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

@{
	var hideEditAddress = Pageview.CurrentParagraph?.Item["HideEditBillingAddress"] != null ? Convert.ToBoolean(Pageview.CurrentParagraph.Item["HideEditBillingAddress"].ToString()) : false;
	var selectedAddressString = string.Empty;
	int fieldCount = 0; //Helps us render addresses that contains more than just the auto set country
	List<string> address = new List<string>();
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Company")))
	{
		address.Add(GetString("Ecom:Order.Delivery.Company"));
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Name")))
	{
		address.Add(GetString("Ecom:Order.Delivery.Name"));
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Address")))
	{
		address.Add(GetString("Ecom:Order.Delivery.Address"));
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Address2")))
	{
		address.Add(GetString("Ecom:Order.Delivery.Address2"));
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Zip")))
	{
		address.Add(GetString("Ecom:Order.Delivery.Zip"));
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.City")))
	{
		address.Add(GetString("Ecom:Order.Delivery.City"));
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Region")))
	{
		string regionName = GetString("Ecom:Order.Delivery.Region");
		foreach (LoopItem region in GetLoop("DeliveryRegions"))
		{
			if (region.GetString("Ecom:DeliveryRegion.IsDeliveryRegion") == "true")
			{
				regionName = region.GetString("Ecom:DeliveryRegion.Name");
			}
		}

		address.Add(regionName);
		fieldCount++;
	}
	if (!string.IsNullOrEmpty(GetString("Ecom:Order.Delivery.Country")))
	{
		address.Add(GetString("Ecom:Order.Delivery.Country"));
		fieldCount++;
	}
	selectedAddressString = (string.Join(",", address.Select(x => x.ToString()).ToArray())).Trim(',').Replace(",", ", ");
}

@if (!string.IsNullOrEmpty(selectedAddressString) && fieldCount > 1)
{
	<div class="list-group-item py-2 fs-7">
		<dl class="grid gap-1 gap-sm-3 mb-0">
			<dt class="g-col-8 g-col-sm-4 fw-normal">@Translate("Selected address")</dt>
			<dd class="g-col-12 g-col-sm-7 order-2 order-sm-1 mb-0">@selectedAddressString</dd>

			@if (!hideEditAddress)
			{
				<dd class="g-col-4 g-col-sm-1 order-1 order-sm-2 mb-0 text-end">
					<button class="btn btn-sm btn-link fs-8 p-0" data-dw-button="link" type="submit" name="CartV2.GotoStep0" id="EditDeliveryAddressButton">
						<span class="text-uppercase">@Translate("Edit")</span>
					</button>
				</dd>
			}
		</dl>
	</div>
}
