<vn>
<div id="title">
	<h1>{{_(params.$.id ? 'Order' : 'ShoppingBasket')}}</h1>
</div>
<div id="actions">
	<htk-bar-button
		icon="settings"
		tip="_ConfigureOrder"
		on-click="this.onConfigureClick()"/>
	<htk-bar-button
		icon="shopping_bag"
		tip="_Catalog"
		on-click="this.onCatalogClick()"/>
	<htk-bar-button
		icon="shopping_cart_checkout"
		tip="_Checkout"
		on-click="this.onConfirmClick()"/>
</div>
<vn-group>
	<vn-lot-query id="params" on-change="this.onHashChange()">
		<vn-spec name="id" type="Number"/>
	</vn-lot-query>
	<vn-lot id="lot"/>
	<db-form v-model="order" on-ready="onOrderReady">
		<db-model property="model" lot="lot">
			SELECT o.id, o.sent,
					ag.description agency, v.code method,
					ad.nickname, ad.postalCode, ad.city, ad.street
				FROM myOrder o
					JOIN vn.agencyMode ag ON ag.id = o.agencyModeFk
					LEFT JOIN myAddress ad ON ad.id = o.addressFk
					JOIN vn.deliveryMethod v ON v.id = o.deliveryMethodFk
				WHERE o.id = #id;
		</db-model>
	</db-form>
</vn-group>
<div id="form" class="hedera-basket">
	<div class="box vn-w-sm vn-pa-lg">
		<div class="head vn-pb-lg">
			<h5>#{{order.id}}</h5>
			<div class="delivery">
				<h6><t>ShippingInformation</t></h6>
					<p>{{order.nickname}}</p>
				<p>
					<t>Delivery at</t> {{Vn.Value.format(order.sent, _('%D'))}}
				</p>
				<p>
					<span id="method"><t>Agency</t></span> {{order.agency}}
				</p>
			</div>
			<div id="address" class="address vn-mt-md">
				<h6><t>DeliveryAddress</t></h6>
				<p>{{order.street}}</p>
				<p>{{order.postalCode}}, {{order.city}}</p>
			</div>
			<p class="total">
				<t>Total</t> 
				<htk-text format="%.2d€">
					<db-calc-sum property="param" func="subtotal" model="items"/>
				</htk-text>
			</p>
		</div>
		<div class="lines vn-pt-lg">
			<htk-repeater form-id="iter">
				<db-model id="items" property="model" lot="lot" updatable="true">
					SELECT bi.id, bi.amount, bi.price, i.longName item,
							i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7,
							i.image, im.updated
						FROM myOrderRow bi
							JOIN vn.item i ON i.id = bi.itemFk
							LEFT JOIN image im
								ON im.collectionFk = 'catalog'
								AND im.name = i.image
						WHERE orderFk = #id
				</db-model>
				<custom>
					<div class="line">
						<htk-button
							class="delete"
							tip="_Remove"
							icon="delete"
							on-click="this.onDeleteClick($iter)"/>
						<htk-image
							value="{{iter.image}}"
							stamp-column="updated"
							class="photo"
							directory="catalog"
							subdir="200x200"
							full-dir="1600x900"/>
						<div class="info">
							<h2>{{iter.item}}</h2>
							<p class="tags">
								{{iter.value5}} {{iter.value6}} {{iter.value7}}
							</p>
							<span class="subtotal">
								{{Vn.Value.format(iter.price * iter.amount, '%.2d€')}}
							</span>
							<p class="amount">
								{{iter.amount}} x {{Vn.Value.format(iter.price, '%.2d€')}}
							</p>
						</div>
					</div>
				</custom>
			</htk-repeater>
		</div>
	</div>
</div>
</vn>
