@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@{
	if (GetLoop("Shippingmethods").Any())
	{
		bool methodSelected = false;
		<div class="mt-4" id="SelectDeliveryGroup">
			<h3 class="fs-6 fw-normal mb-3">@Translate("Select delivery")</h3>
			<div class="list-group" id="ShippingMethodsGroup">
				@foreach (LoopItem method in GetLoop("Shippingmethods"))
				{
					if (method.GetBoolean("Ecom:Cart.Shippingmethod.IsSelected"))
					{
						methodSelected = true;
					}

					bool isActive = method.GetBoolean("Ecom:Cart.Shippingmethod.IsSelected");

					<label class="list-group-item list-group-item-action" @(isActive ? "aria-current=\"true\"" : string.Empty) role="button" style="@(isActive ? "background-color: rgba(var(--bs-body-color-rgb), 0.05)" : null)">
						<dl class="d-flex justify-content-between gap-2 mb-0">
							<dt class="form-check fw-normal">
								@{
									string imagePath = Dynamicweb.Context.Current.Server.MapPath(method.GetString("Ecom:Cart.Shippingmethod.Icon.Clean"));

									if (File.Exists(imagePath))
									{
										<input class="form-check-input" type="radio" name="EcomCartShippingmethodID" id="EcomCartShippingmethodID_@method.GetString("Ecom:Cart.Shippingmethod.ID")" value="@method.GetString("Ecom:Cart.Shippingmethod.ID")" @if (!string.IsNullOrWhiteSpace(method.GetString("Ecom:Cart.Shippingmethod.IsSelected"))) { <text> checked="checked" </text> } onchange="submitForm()">
										<div class="d-flex flex-column gap-2">
											<span class="m-0 d-block" style="height: 1.5rem; background: url('@method.GetString("Ecom:Cart.Shippingmethod.Icon.Clean")') no-repeat left center; background-size: contain;"></span>
											<span class="form-check-label">@method.GetString("Ecom:Cart.Shippingmethod.Name")</span>
										</div>
									}
									else
									{
										<input class="form-check-input" type="radio" name="EcomCartShippingmethodID" id="EcomCartShippingmethodID_@method.GetString("Ecom:Cart.Shippingmethod.ID")" value="@method.GetString("Ecom:Cart.Shippingmethod.ID")" @if (!string.IsNullOrWhiteSpace(method.GetString("Ecom:Cart.Shippingmethod.IsSelected"))) { <text> checked="checked" </text> } onchange="submitForm()">
										<div class="d-flex flex-column">
											<span class="form-check-label">@method.GetString("Ecom:Cart.Shippingmethod.Name")</span>
											<span class="opacity-75 fs-8">@method.GetString("Ecom:Cart.Shippingmethod.Description")</span>
										</div>
									}
								}
							</dt>

							<dd class="mb-0 text-end">
								@if (!method.GetBoolean("Ecom:Cart.ShippingMethod.Price.IsZero"))
								{
									<span class="text-price">@method.GetString("Ecom:Cart.ShippingMethod.Price")</span>
								}
								else
								{
									<span class="text-price">@Translate("Free")</span>
								}
							</dd>
						</dl>
					</label>

					if (!string.IsNullOrEmpty(method.GetString("Ecom:ShippingProvider.Content")))
					{
						@method.GetString("Ecom:ShippingProvider.Content")
					}
				}
				@{
					if (!methodSelected)
					{
						//Enable the possibility to use validation if no default shipping method is selected
						<input class="form-check-input d-none" type="radio" name="EcomCartShippingmethodID" value="" checked="checked" />
					}
				}
			</div>
		</div>
	}
}
