@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using Dynamicweb

@{
	bool anonymousUser = Pageview.User == null;
	string iconPath = "/Files/Images/Icons/";
	int currentUserId = Dynamicweb.Core.Converter.ToInt32(GetGlobalValue("Global:Extranet.UserID"));
	var shopPageId = GetPageIdByNavigationTag("Shop");
	var cart = Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(Pageview.CurrentParagraph)?.Item ?? null;
	var checkoutAnonymousLink = cart?.GetLink("CheckoutAnonymousPageLink") is object ? cart.GetLink("CheckoutAnonymousPageLink").Url : string.Empty;
	var checkoutSignedInLink = cart?.GetLink("CheckoutSignedInPageLink") is object ? cart.GetLink("CheckoutSignedInPageLink").Url : string.Empty;
	string checkoutLink = currentUserId == 0 ? checkoutAnonymousLink : checkoutSignedInLink;
	var quoteCheckoutLink = cart?.GetLink("QuoteCheckoutPageLink") is object ? cart.GetLink("QuoteCheckoutPageLink").Url : string.Empty;
	bool isQuote = Dynamicweb.Ecommerce.Services.Orders.GetById(GetString("Ecom:Order.ID")).IsQuote;
	var cartServicePageId = GetPageIdByNavigationTag("CartService");	
}
<div class="grid gap-0" id="Cart">
	<header class="g-col-12">
		<div class="pb-3 pb-lg-0 pt-3 pt-lg-5">
			<h1 class="h3 mb-2">@Translate("Shopping Cart")</h1>
			<p class="mb-0"><span>@Translate("Items in your shopping cart"):</span> <span>@GetString("Ecom:Order.OrderLines.TotalProductQuantity")</span></p>
		</div>
	</header>

	<div class="g-col-12 g-col-lg-8 pe-lg-5 pb-md-5">
		@Include("Helpers/Errors.cshtml")

		<form name="ordersubmit" id="ordersubmit" method="post" autocomplete="off">
			<input type="hidden" name="cartcmd" value="updateorderlines" />
			<input type="hidden" name="redirect" value="false" />
			<input type="hidden" name="LayoutTemplate" value="Swift-v2_MiniCart.cshtml" />

			<header class="py-2 pt-lg-5 border-bottom d-none d-lg-block">
				<div class="grid" style="line-height: 1;">
					<div class="g-col-2">@Translate("Product")</div>
					<div class="g-col-9 grid">
						<div class="g-col-10 g-col-md-6 g-start-8"></div>
						<div class="g-col-2 g-col-md-3 g-start-8">@Translate("Quantity")</div>
					</div>
					<div class="g-col-1 text-end">@Translate("Total")</div>
				</div>
			</header>
				<script>
					window.dataLayer = window.dataLayer || [];
					window.dataLayer.push({
						event: "view_cart",
						ecommerce: {
							currency: "@GetString("Ecom:Order.Currency.Code")",
							value: @GetDouble("Ecom:Order.Price.PriceWithVAT.Value").ToString("0.00", System.Globalization.CultureInfo.InvariantCulture),
							items: [
								@foreach (LoopItem orderline in GetLoop("OrderLines"))
								{
									<text>
									{
										item_id: "@orderline.GetString("Ecom:Order:OrderLine.ProductID")",
										item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(orderline.GetString("Ecom:Order:OrderLine.ProductName"))",
										currency: "@orderline.GetString("Ecom:Order:OrderLine.UnitPrice.CurrencyCode")",
										price: @orderline.GetDouble("Ecom:Order:OrderLine.UnitPriceWithProductDiscount.Price.Value").ToString("0.00", System.Globalization.CultureInfo.InvariantCulture),
										discount: @Math.Abs(orderline.GetDouble("Ecom:Order:OrderLine.UnitDiscount.Price.Value")).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture),
										quantity: @orderline.GetDouble("Ecom:Order:OrderLine.Quantity").ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)
									},</text>
								}
							]
						}
					});
				</script>

			@Include("Helpers/OrderLineItem.cshtml")

			@if(Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Desktop)
			{
				<text>@Include("Helpers/CartNavigation.cshtml")</text>
			}

		</form>
	</div>

	<aside class="g-col-12 g-col-lg-4 position-relative">
		<div class="p-3 p-lg-5 pb-lg-4 sticky-top z-1" data-dw-colorscheme="@Pageview.CurrentParagraph?.ColorSchemeId">
			<header>
				<h4 class="fs-6 fw-normal mb-2">@Translate("Order summary")</h4>
			</header>

			@Include("Helpers/OrderSummary.cshtml")

			@if(Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet)
			{
				<text>@Include("Helpers/CartNavigation.cshtml")</text>
			}
		</div>
	</aside>

	<script>
		document.addEventListener('updated.swift.cart', (event) => {
			swift.PageUpdater.Update(document.querySelector("#ordersubmit"), true);
		});
	</script>
</div>
