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

@{
	bool summaryIsPaymentStep = GetLoop("StepButtons").Count == 0;
	int summaryCurrentStep = !summaryIsPaymentStep ? 1 : 4;
	int summaryCurrentUserId = Dynamicweb.Core.Converter.ToInt32(GetGlobalValue("Global:Extranet.UserID"));

	bool userHasDefaultAddress = false;
	bool userAddressSelected = false;

	string userSelectedAddressID = GetString("UserManagement:User.UserAddress.SelectedAddressID");

	foreach (LoopItem userAddress in GetLoop("UserManagement:User.UserAddresses"))
	{
		if (userAddress.GetBoolean("UserManagement:User.UserAddress.Default"))
		{
			userHasDefaultAddress = true;
		}
		if (userAddress.GetBoolean("UserManagement:User.UserAddress.SelectedForDeliveryFields"))
		{
			userAddressSelected = true;
		}
		if (!string.IsNullOrEmpty(userAddress.GetString("UserManagement:User.UserAddress.SelectedAddressID")))
		{
			userSelectedAddressID = userAddress.GetString("UserManagement:User.UserAddress.SelectedAddressID");
		}
	}

	foreach (LoopItem step in GetLoop("StepButtons"))
	{
		if (step.GetBoolean("Step.Current"))
		{
			summaryCurrentStep = step.GetInteger("Step.Number");
		}
	}
}

@if (!string.IsNullOrEmpty(GetString("UserManagement:User.Address")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.ShippingMethodID")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.PaymentMethodID")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Name")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Company")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Address")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Address2")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Zip")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.City")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Email")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Phone")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Name")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Company")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Address")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Address2")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Zip")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.City")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Email")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.Customer.Phone")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.ShippingMethod")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.ShippingDate")) ||
	!string.IsNullOrEmpty(GetString("Ecom:Order.PaymentMethod")))
{

	@* User *@
	if (summaryCurrentUserId != 0)
	{
		<div class="list-group mb-5" style="--bs-list-group-bg: rgba(var(--bs-body-color-rgb), 0.05)">

			@Include("StepSummaryOrderCustomer.cshtml")

			@if (summaryCurrentStep != 1)
			{
				if(!String.Equals(summaryCurrentUserId.ToString(), userSelectedAddressID)) //Selected address
				{
					<text>
					@Include("StepSummaryOrderDelivery.cshtml")
					</text>
				}
			}
			@if (summaryCurrentStep > 2)
			{
				<text>
				@Include("StepSummaryDeliveryMethod.cshtml")
				@Include("StepSummaryDeliveryDate.cshtml")
				</text>
			}
		</div>
	}
	@* Anonymous *@
	else
	{
		if (summaryCurrentStep != 1)
		{
			<div class="list-group" style="--bs-list-group-bg: rgba(var(--bs-body-color-rgb), 0.05)">

				@Include("StepSummaryOrderCustomer.cshtml")
				
				@if (summaryCurrentStep > 2)
				{
					<text>
					@Include("StepSummaryDeliveryMethod.cshtml")
					@Include("StepSummaryDeliveryDate.cshtml")
					</text>
				}
				@if (summaryCurrentStep > 3)
				{
					<text>
					@Include("Helpers/StepSummaryPaymentMethod.cshtml")
					@Include("Helpers/StepSummaryOrderReference.cshtml")
					</text>
				}
			</div>
		}
	}
}
