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

@{ 
	string lang = Pageview.Area.CultureInfo.TwoLetterISOLanguageName;

	string showPricesWithVat = Pageview?.Area?.EcomPricesWithVat != null ? Dynamicweb.Ecommerce.Common.Context.DisplayPricesWithVat.ToString() : "false";
	bool neverShowVat = string.IsNullOrEmpty(showPricesWithVat);

	string paddingTop = "padding-top: 8px;";
	string paddingBottom = "padding-bottom: 8px;";
	string paddingLeft = "padding-left: 16px;";
	string paddingRight = "padding-right: 16px;";

	string borderTop = "border-top: 1px solid;";
	string borderBottom = "border-bottom: 1px solid;";
	string borderLeft = "border-left: 1px solid;";
	string borderRight = "border-right: 1px solid;";

	string textPrice = "font-variant-numeric: tabular-nums; white-space: nowrap;";

	string verticalAlignTop = "vertical-align: top;";

	string textRight = "text-align: right;";
	string textLeft= "text-align: left;";

	string fontBold = "font-weight: bold;";
	string fontNormal = "font-weight: normal;";

	string tableHeadingStyle1 = "font-weight: normal; text-align: left; border-top: 1px solid; border-right: 1px solid; border-left: 1px solid; padding-top: 8px; padding-right: 16px; padding-left: 16px;";
	string tableHeadingStyle2 = "font-weight: normal; text-align: left; padding-top: 8px; padding-right: 16px; padding-bottom: 8px; padding-left: 16px;";
	string tableCellStyle1 = 	"text-align: left; border-right: 1px solid; border-bottom: 1px solid; border-left: 1px solid; padding-right: 16px; padding-top: 8px; padding-left: 16px;";
	string tableCellStyle2 = 	"text-align: right; padding-top: 8px; padding-right: 16px; padding-bottom: 8px; padding-left: 16px;";
	string tableCellStyle3 = 	"vertical-align: top; padding-top: 8px; padding-right: 16px; padding-bottom: 8px; padding-left: 16px;";
}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--[if IE]>
	<html xmlns="http://www.w3.org/1999/xhtml" class="ie" lang="@lang">
<![endif]-->
<!--[if !IE]><!-->
<html style="margin: 0;padding: 0;" xmlns="http://www.w3.org/1999/xhtml" lang="@lang">
<!--<![endif]-->
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title></title>
	<!--[if !mso]><!-->
	<meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]-->
	<meta name="viewport" content="width=device-width">
	<meta name="x-apple-disable-message-reformatting">
	<meta name="robots" content="noindex,nofollow">
	<meta property="og:title" content="">
</head>
<!--[if mso]>
	<body class="mso">
<![endif]-->
<!--[if !mso]><!-->

<body style="-webkit-text-size-adjust: 100%;">
	<!--<![endif]-->
	<table cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; table-layout: fixed; min-width: 320px; width: 100%; max-width: 560px;">
		<tr>
			<th style="@(textLeft)">
				<h1>@Translate("Thank you for your quote request")</h1>
			</th>
		</tr>
		<tr>
			<td style="@paddingBottom">@Translate("We are processing your quote now, here are the details")</td>
		</tr>
	</table>
	
	<table cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; table-layout: fixed; min-width: 320px; width: 100%; max-width: 560px;">
		@if (!string.IsNullOrEmpty(GetString("Ecom:Order.ID"))) {
			<tr>
				<th style="@tableHeadingStyle1">@Translate("Quote number")</th>
			</tr>
			<tr>
				<td style="@tableCellStyle1">
					@if(!string.IsNullOrEmpty(GetString("Ecom:Order.IntegrationID"))){
						<span>@GetString("Ecom:Order.IntegrationID") (@GetString("Ecom:Order.ID"))</span>
                    } else {
						@GetString("Ecom:Order.ID")
					}
				</td>
			</tr>
		}

		@if (!string.IsNullOrEmpty(GetString("Ecom:Order.Completed"))) {
			<tr>
				<th style="@tableHeadingStyle1">@Translate("Quote date")</th>
			</tr>
			<tr>
				<td style="@tableCellStyle1">@GetString("Ecom:Order.Completed")</td>
			</tr>
		}

		<tr>
			<th style="@tableHeadingStyle1">@Translate("Your information")</th>
		</tr>
		<tr>
			<td style="@tableCellStyle1">
				@{
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Name")))
					{
						<span>@GetString("Ecom:Order.Customer.Name"),</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Address")))
					{
						<span>@GetString("Ecom:Order.Customer.Address"),</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Address2")))
					{
						<span>@GetString("Ecom:Order.Customer.Address2"),</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Zip")))
					{
						<span>@GetString("Ecom:Order.Customer.Zip")</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.City")))
					{
						<span>@GetString("Ecom:Order.Customer.City")</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Region")))
					{
						string regionName = GetString("Ecom:Order.Customer.Region");
						foreach (LoopItem region in GetLoop("CustomerRegions")) {
							if (region.GetString("Ecom:CustomerRegion.IsCustomerRegion") == "true") {
								regionName = region.GetString("Ecom:CustomerRegion.Name");
							}
						}

						<span>@regionName</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Country")))
					{
						<span>@GetString("Ecom:Order.Customer.Country")</span>
					}
					
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Email")))
					{
						<span>@GetString("Ecom:Order.Customer.Email")</span>
					}
					if (!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Phone")))
					{
						<span>@GetString("Ecom:Order.Customer.Phone")</span>
					}
				}
			</td>
		</tr>

		<tr>
			<td style="@tableCellStyle1">
				<div>@Translate("Your quote request")</div>
				<div>@GetString("Ecom:Order.Customer.Comment")</div>
			</td>
		</tr>
	</table>

	<table cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; table-layout: fixed; min-width: 320px; width: 100%; max-width: 560px; margin-top: 32px; @(borderTop)@(borderLeft)@(borderRight)">
		
		@foreach (LoopItem orderline in GetLoop("OrderLines"))
		{
			string name = orderline.GetString("Ecom:Order:OrderLine.ProductName");
			string image = "Admin/Public/GetImage.ashx?image=" + orderline.GetString("Ecom:Product.PrimaryImage") + "&width=100&height=100";
			var uri = Dynamicweb.Context.Current.Request.Url;
			var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
			string imagePath = hostname + "/" + image;
			string removeFromBasketLink = orderline.GetString("Ecom:Order:OrderLine.DeleteLink");
			string priceTotalWithDiscounts = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted") : "";
			string priceBefore = !string.IsNullOrEmpty(orderline.GetString("Ecom:Product.InformativePrice.PriceFormatted")) ? orderline.GetString("Ecom:Product.InformativePrice.PriceFormatted") : "";
			string unitPrice = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.UnitPrice.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.UnitPrice.PriceFormatted") : "";
			string discountPrice = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.UnitPriceWithProductDiscount.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.UnitPriceWithProductDiscount.PriceFormatted") : "";
			string discountTotal = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.TotalDiscount.PriceFormatted")) ? orderline.GetString("Ecom:Order:OrderLine.TotalDiscount.PriceFormatted") : "";
			string variantText = orderline.GetString("Ecom:Order:OrderLine.ProductVariantText");
			var orderlineId = orderline.GetValue("Ecom:Order:OrderLine.Id");
			var quantity = orderline.GetDouble("Ecom:Order:OrderLine.Quantity");
			string primaryGroupId = orderline.GetString("Ecom:Order:OrderLine.PrimaryOrDefaultGroupId");
			string productId = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.ProductID")) ? orderline.GetString("Ecom:Order:OrderLine.ProductID") : "";
			string variantId = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.ProductVariantID")) ? orderline.GetString("Ecom:Order:OrderLine.ProductVariantID") : "";

			string link = "Default.aspx?ID=" + GetPageIdByNavigationTag("Shop");
			link += $"&GroupID={primaryGroupId}";
			link += $"&ProductID={productId}";
			link += !string.IsNullOrEmpty(variantId) ? $"&VariantID={variantId}" : "";

			if (!string.IsNullOrEmpty(variantId))
			{
				link += "&VariantID=" + variantId;
			}

			bool isProduct = orderline.GetBoolean("Ecom:Order:OrderLine.IsProduct");

			if (isProduct)
			{
				<tr>
					<td style="@(tableCellStyle3)@(textLeft)" width="132">
						@* Image *@
						<img src="@imagePath" alt="@name">
					</td>
					<td style="@(tableCellStyle3)@(textLeft)">
						@* Title *@
						<h3 style="@(fontNormal)font-weight:normal;">
							@name
						</h3>
						@* Variants *@
						<p>@variantText</p>
						<p>
							@* Unit price *@
							@if (discountPrice == unitPrice)
							{
								<span style="@(textPrice)">@unitPrice</span> 
							}
							else
							{
								<span style="@(textPrice)">@discountPrice</span>
								<span style="@(textPrice) text-decoration: line-through;">@unitPrice</span>}
						</p>
						@* Quantity *@
						<p>@Translate("Quantity"): @quantity</p>
					</td>
					<td style="@(tableCellStyle3)@(textRight)">
						@* Total *@
						<span style="@(textPrice)">@priceTotalWithDiscounts</span>
						@if (orderline.GetDouble("Ecom:Order:OrderLine.TotalDiscount.Price.Value") != 0)
						{
						<span style="@(textPrice)">@discountTotal</span>}
					</td>
				</tr>
			}
		}
	</table>

	<table cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; table-layout: fixed; min-width: 320px; width: 100%; max-width: 560px;@(borderTop)@(borderBottom)@(borderLeft)@(borderRight)">
		<tr>
			@{ 
				string totalPriceWithoutDiscountsFeesAndTaxes = !string.IsNullOrEmpty(GetString("Ecom:Order.TotalPriceWithoutDiscountsFeesAndTaxes.PriceFormatted")) ? GetString("Ecom:Order.TotalPriceWithoutDiscountsFeesAndTaxes.PriceFormatted") : "";
				string totalPriceWithoutOrderDiscountsAndFees = !string.IsNullOrEmpty(GetString("Ecom:Order.TotalPriceWithoutOrderDiscountsAndFees.PriceFormatted")) ? GetString("Ecom:Order.TotalPriceWithoutOrderDiscountsAndFees.PriceFormatted") : ""; 
			}

			@* Subtotal *@
			<th style="@(textLeft)@(fontBold)@(paddingTop)@(paddingBottom)@(paddingLeft)@(paddingRight)">@Translate("Subtotal")</th>
			<td style="@(textRight)@(paddingTop)@(paddingBottom)@(paddingLeft)@(paddingRight)">
				<div>
					@if (totalPriceWithoutDiscountsFeesAndTaxes != totalPriceWithoutOrderDiscountsAndFees)
					{
						<span style="@(textPrice)text-decoration: line-through;">@totalPriceWithoutDiscountsFeesAndTaxes</span>
					}
					<span style="@(textPrice)@(fontBold);">@totalPriceWithoutOrderDiscountsAndFees</span>
				</div>
				@if (!neverShowVat && showPricesWithVat == "false")
				{
					<div style="font-weight: 300">@Translate("Excl. VAT")</div>
				}
				@if (!neverShowVat && showPricesWithVat == "true")
				{
					<div style="font-weight: 300">@Translate("Incl. VAT")</div>
				}
			</td>
		</tr>
			@* Discounts (only order discounts) *@
			@foreach (LoopItem orderline in GetLoop("OrderLines"))
			{
				bool isDiscount = orderline.GetBoolean("Ecom:Order:OrderLine.IsDiscount");
				bool isProductIdOrNumber = !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.ProductID")) || !string.IsNullOrEmpty(orderline.GetString("Ecom:Order:OrderLine.ProductNumber"));  //Live Cart orderlines may not return ProductId. Manually entered products may not have ProductNumber
				bool isOrderAmountDiscount = orderline.GetInteger("Ecom:Order:OrderLine.Type") == 1 && !isProductIdOrNumber;
				if (isDiscount && isOrderAmountDiscount)
				{	
					<tr>
						<th style="@tableHeadingStyle2">@orderline.GetString("Ecom:Order:OrderLine.ProductName")</th>
						<td style="@(tableCellStyle2)@(textPrice)">@orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted")</td>
					</tr>
				}
			}

			@* Shipping *@
			@if (!string.IsNullOrEmpty(GetString("Ecom:Order.ShippingMethodID")) && GetDouble("Ecom:Order.ShippingFee.Price.Value") != 0.0)
			{
				<tr>
					<th style="@tableHeadingStyle2">@Translate("Delivery")</th>
					<td style="@(tableCellStyle2)@(textPrice)">@GetString("Ecom:Order.ShippingFee.PriceFormatted")</td>
				</tr>
			}

			@* Payment *@
			@if (!string.IsNullOrEmpty(GetString("Ecom:Order.PaymentMethodID")))
			{
				if (GetDouble("Ecom:Order.PaymentFee.Price.Value") != 0)
				{

					<tr>
						<th style="@tableHeadingStyle2">@Translate("Payment")</th>
						<td style="@(tableCellStyle2)@(textPrice)">@GetString("Ecom:Order.PaymentFee.PriceFormatted")</td>
					</tr>
				}
			}

		<tr>
			<th style="@(tableCellStyle3)@(textLeft)@(fontBold)">@Translate("Total")</th>
			<td style="@(tableCellStyle3)@(textRight)@(fontBold)">
				<div>@GetString("Ecom:Order.Price.PriceFormatted")</div>
				@if (!neverShowVat && showPricesWithVat == "false")
				{
					<div style="font-weight: 300">@Translate("Excl. VAT")</div>
				}
				@if (!neverShowVat && showPricesWithVat == "true")
				{
					<div style="font-weight: 300">@Translate("Incl. VAT")</div>
				}
			</td>
		</tr>

		@if (!neverShowVat) {
			<tr>
				<th style="@tableHeadingStyle2">@Translate("VAT")</th>
				<td style="@(tableCellStyle2)@(textPrice)">@GetString("Ecom:Order.Price.VATFormatted")</td>
			</tr>
			if (showPricesWithVat == "false") {
				<tr>
					<th style="@tableHeadingStyle2">@Translate("Total incl. VAT")</th>
					<td style="@(tableCellStyle2)@(textPrice)">@GetString("Ecom:Order.Price.PriceWithVATFormatted")</td>
				</tr>
			}
		}

		@if (GetDouble("Ecom:Order.TotalDiscount.Price.Value") != 0)
		{
			<tr>
				<th style="@tableHeadingStyle2">@Translate("Discount")</th>
				<td style="@(tableCellStyle2)@(textPrice)">@GetString("Ecom:Order.TotalDiscount.PriceFormatted")</td>
			</tr>
		}
	</table>
</body>

</html>
