<vn>
<vn-group>
	<vn-lot id="lot" on-change="onAddressChange"/>
	<db-form id="defaults" on-ready="onValuesReady">
		<db-model property="model">
			SELECT delivery_method, agency_id, address_id
				FROM basket_defaults
		</db-model>
	</db-form>
	<db-form id="order-form" on-ready="onValuesReady">
		<db-model property="model">
			SELECT d.code delivery_method, o.date_send, o.agency_id, o.address_id
				FROM basket o
					JOIN vn.deliveryMethod d ON d.id = o.delivery_method_id
		</db-model>
	</db-form>
	<db-form id="address-form" model="addresses">
		<db-model property="model" id="addresses">
			SELECT a.id, a.consignee, p.name province, a.zip_code, a.city, a.name, a.active, c.Pais country
				FROM address_view a
					LEFT JOIN vn2008.province p ON a.province_id = p.province_id
					JOIN vn2008.Paises c ON c.Id = p.Paises_Id
				WHERE active != FALSE
		</db-model>
	</db-form>
	<db-model
		id="agencies"
		lot="lot"
		auto-load="false"
		on-status-changed="onAgenciesReady">
		CALL vn.agencyListForMethod(#date, #address, #method)
	</db-model>
</vn-group>
<h1 id="title">
	_ConfigureOrder
</h1>
<div id="actions">
	<htk-bar-button
		icon="close"
		tip="_Cancel"
		on-click="onCancelClick"/>
</div>
<div id="main" class="checkout">
	<div class="card form">
		<htk-assistant
			id="assistant"
			step-count="5"
			step-func="stepFunc">
			<htk-step name="method">
				<h2>_DeliveryOrPickupQuestion</h2>
				<div class="answers radio">
					<htk-radio-group
						id="rg-method"
						lot="lot"
						name="method"
						on-changed="onFieldChange"/>
					<div>
						<htk-radio radio-group="rg-method" id="r-agency" value="AGENCY"/>
						<label for="r-agency">_ReceiveThroughtAgency</label>
					</div>
					<div>
						<htk-radio radio-group="rg-method" id="r-delivery" value="DELIVERY"/>
						<label for="r-delivery">_ReceiveThroughtRoute</label>
					</div>
					<div>
						<htk-radio radio-group="rg-method" id="r-pickup" value="PICKUP"/>
						<label for="r-pickup">_PickupInStore</label>
					</div>
				</div>
			</htk-step>
			<htk-step name="date">
				<h2 id="date-question"/>
				<div class="answers">
					<htk-calendar
						id="calendar"
						class="thin-calendar"
						lot="lot"
						name="date"
						restrict-func="calendarRestrict"
						on-pick="onFieldChange"/>
				</div>
			</htk-step>
			<htk-step name="address">
				<h2>_AddressQuestion</h2>
				<div class="answers target">
					<htk-repeater
						id="repeater"
						form-id="iter"
						on-change="onAddressChange"
						renderer="addressRenderer"
						model="addresses">
						<custom>
							<div class="address" id="address">
								<p class="consignee">
									{{consignee}}
								</p>
								<p>
									{{name}}
								</p>
							</div>
						</custom>
					</htk-repeater>
				</div>
			</htk-step>
			<htk-step name="delivery">
				<h2 id="wh-question"/>
				<div class="answers target">
					<htk-combo
						id="agency"
						lot="lot"
						name="agency"
						not-null="true"
						placeholder="_Select agency"
						show-field="description"
						on-changed="onFieldChange"
						model="agencies"/>
				</div>
			</htk-step>
			<htk-step name="confirm" class="confirm">
				<h2>_ConfirmToAccessCatalog</h2>
				<div class="answers target">
					<p>
						_Arrival <htk-text format="%D" lot="lot" name="date"/>
					</p>
					<p>
						{{addressForm.name}}
					</p>
					<p id="agency-text">
						<span>_Agency</span> {{agency.description}}
					</p>
					<p id="delivery-text">
						_ReceiveThroughtRoute
					</p>
					<p id="pickup-text">
						<span>_Warehouse</span> {{agency.description}}
					</p>
					<button id="confirm-button" class="thin" on-click="onConfirmClick">
						_Confirm
					</button>
					<div class="clear"/>
				</div>
			</htk-step>
		</htk-assistant>
		<htk-assistant-bar assistant="assistant"/>
	</div>
</div>
</vn>
