@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using System.Linq
@using Dynamicweb.Ecommerce.International
@{
	var ShippingServices = GetLoop("ShippingServices");
}
@if (ShippingServices.Any())
{

	foreach (LoopItem service in ShippingServices)
	{
		string priceFormatted = !string.IsNullOrEmpty(service.GetString("Serviceprice.PriceFormatted")) ? service.GetString("Serviceprice.PriceFormatted") : Translate("Not specified");
		string radioName = string.Format("{0}{1}", GetString("FieldPrefix"), "ShipmondoCarrierProductCode");
		string radioId = string.Format("{0}{1}", radioName, service.GetString("ServiceProductCode"));
		string radioValue = service.GetString("ServiceProductCode");
		if (ShippingServices.Count > 1)
		{
			<label class="list-group-item list-group-item-action" @(service.GetBoolean("IsSelectedCarrier") ? "aria-current=\"true\"" : string.Empty) for="@radioId" role="button">
				<dl class="d-flex gap-2 justify-content-between mb-0">
					<dt class="form-check fw-normal">
						<input @(service.GetBoolean("IsSelectedCarrier") ? "checked" : string.Empty) class="form-check-input" type="radio" required name="@radioName" id="@radioId" value="@radioValue" >
						<div class="d-flex flex-column">
							<span class="form-check-label">@(service.GetString("ServiceCarrierName"))@(" - " + service.GetString("ServiceDescription"))</span>
							@if (!string.IsNullOrEmpty(service.GetString("DeliveryTime")))
							{
								<span class="opacity-75 fs-8">@Translate("Delivery within ")@service.GetString("DeliveryTime")</span>
							}
						</div>
					</dt>
					<dd class="mb-0 text-end"></dd>
				</dl>
			</label>
		}
		if (service.GetBoolean("IsSelectedCarrier"))
		{
			var dropPoints = GetLoop("DropPoints");
			if (dropPoints.Any())
			{
				foreach (LoopItem dropPoint in dropPoints)
				{
					if (!Dynamicweb.Context.Current.Items.Contains("DroppointsRendered"))
					{
						Dynamicweb.Context.Current.Items.Add("DroppointsRendered", true);
					}
					string pointRadioName = string.Format("{0}{1}", GetString("FieldPrefix"), "ShipmondoServicePointId");
					string pointRadioId = string.Format("{0}{1}", pointRadioName, dropPoint.GetString("Id"));
					string pointRadioValue = dropPoint.GetString("Id");

					List<string> dropPointInfo = new List<string>();
					dropPointInfo.Add(dropPoint.GetString("Address"));
					dropPointInfo.Add(dropPoint.GetString("Zipcode"));
					dropPointInfo.Add(dropPoint.GetString("City"));
					dropPointInfo.Add(dropPoint.GetString("Country"));

					string dropPointInfoString = (string.Join(",", dropPointInfo.Select(x => x).ToArray())).Replace(",", ", ");

					<label class="ps-5 list-group-item list-group-flush list-group-item-action" @(dropPoint.GetBoolean("IsSelectedServicePoint") ? "aria-current=\"true\"" : string.Empty) for="@pointRadioId" role="button">
						<div class="form-check">
							<input @(dropPoint.GetBoolean("IsSelectedServicePoint") || dropPoint.GetInteger("DropPoints.LoopCounter") == 1 ? "checked" : string.Empty) class="form-check-input" type="radio" @(dropPoint.GetBoolean("ServicePointRequired") ? "required" : string.Empty) name="@pointRadioName" id="@pointRadioId" value="@pointRadioValue">
							<div class="d-flex flex-column">
								<span class="form-check-label">@dropPoint.GetString("Name")</span>
								<span class="opacity-75 fs-8">
									@dropPointInfoString
								</span>
							</div>
						</div>
					</label>
				}
			}
		}
	}
}
