ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Views/Checkout/OpcShippingAddress.cshtml
@model CheckoutShippingAddressModel
@using System.Text;
<div class="col-12 checkout-data px-0">
    @if (Model.AllowPickUpInStore && !Model.PickUpInStoreOnly && Model.PickupPoints.Any())
    {
        <div class="section pickup-in-store">
            <p class="selector">
                <label class="custom-control custom-checkbox">
                    <input asp-for="PickUpInStore" class="custom-control-input" onclick="Shipping.togglePickUpInStore(this)"/>
                    <span class="custom-control-label"></span>
                    <span class="custom-control-description" for="@Html.IdFor(model => model.PickUpInStore)">
                        @T("Checkout.PickupPoints").Text
                    </span>
                </label>
            </p>
            <p class="description">
                <i>@T("Checkout.PickupPoints.Description")</i>
            </p>
            <script>
                $(document).ready(function () {
                    Shipping.togglePickUpInStore($('#@Html.IdFor(model => model.PickUpInStore)'));
                });
            </script>
        </div>
    }

    @if (Model.AllowPickUpInStore)
    {
        <div class="pickup-points" id="pickup-points-form">
            @if (Model.PickupPoints.Any())
            {
                if (Model.PickUpInStoreOnly)
                {
                    <input asp-for="PickUpInStore" type="hidden" />
                }
                <div class="section select-pickup-points">
                    @if (Model.PickupPoints.Count == 1)
                    {
                        var point = Model.PickupPoints.First();
                        @Html.Hidden("pickup-point-id", point.Id)
                        <div class="section single-pickup-point">
                            <ul>
                                <li class="single-pickup-point name">@point.Name</li>
                                <li class="single-pickup-point address">@(string.Format("{0} {1} {2}", point.Address.City, point.Address.ZipPostalCode, point.Address.Address1))</li>
                                @if (!string.IsNullOrEmpty(point.PickupFee))
                                {
                                    <li class="single-pickup-point fee">@point.PickupFee</li>
                                }
                            </ul>
                        </div>
                    }
                    else
                    {
                        <label for="pickup-points-select">@T("Checkout.PickupPoints.SelectPickupPoint")</label>
                        <select name="pickup-point-id" id="pickup-points-select" class="custom-select address-select" title="">
                            @foreach (var point in Model.PickupPoints)
                            {
                                var addressLine = new StringBuilder();
                                addressLine.Append(point.Name);
                                if (!string.IsNullOrEmpty(point.Address.City))
                                {
                                    addressLine.AppendFormat(", {0}", point.Address.City);
                                }
                                if (!string.IsNullOrEmpty(point.Address.ZipPostalCode))
                                {
                                    addressLine.AppendFormat(", {0}", point.Address.ZipPostalCode);
                                }
                                if (!string.IsNullOrEmpty(point.Address.Address1))
                                {
                                    addressLine.AppendFormat(", {0}", point.Address.Address1);
                                }
                                if (!string.IsNullOrEmpty(point.PickupFee))
                                {
                                    addressLine.AppendFormat(", {0}", point.PickupFee);
                                }
                                <option value="@point.Id">@(addressLine)</option>
                            }
                        </select>
                    }
                </div>
            }
            <div class="section message-error">
                <ul>
                    @foreach (var warning in Model.Warnings)
                    {
                        <li>@warning</li>
                    }
                </ul>
            </div>
        </div>
    }


    @if (!Model.PickUpInStoreOnly)
    {
        <div class="shipping-addresses" id="shipping-addresses-form">
            @await Component.InvokeAsync("Widget", new { widgetZone = "op_checkout_shipping_address_top" })
            @if (Model.ExistingAddresses.Any())
            {
                <div class="section select-shipping-address">
                    <label for="shipping-address-select">@T("Checkout.SelectShippingAddressOrEnterNewOne")</label>
                    <div>
                        <select name="shipping_address_id" id="shipping-address-select" class="custom-select address-select"
                                title="" onchange="Shipping.newAddress(!this.value)">
                            @foreach (var address in Model.ExistingAddresses)
                            {
                                var addressLine = "";
                                addressLine += address.FirstName;
                                addressLine += " " + address.LastName;
                                if (address.StreetAddressEnabled && !String.IsNullOrEmpty(address.Address1))
                                {
                                    addressLine += ", " + address.Address1;
                                }
                                if (address.CityEnabled && !String.IsNullOrEmpty(address.City))
                                {
                                    addressLine += ", " + address.City;
                                }
                                if (address.StateProvinceEnabled && !String.IsNullOrEmpty(address.StateProvinceName))
                                {
                                    addressLine += ", " + address.StateProvinceName;
                                }
                                if (address.ZipPostalCodeEnabled && !String.IsNullOrEmpty(address.ZipPostalCode))
                                {
                                    addressLine += " " + address.ZipPostalCode;
                                }
                                if (address.CountryEnabled && !String.IsNullOrWhiteSpace(address.CountryName))
                                {
                                    addressLine += ", " + address.CountryName;
                                }
                                //how should we render "FormattedCustomAddressAttributes" here?
                                <option value="@(address.Id)">@(addressLine)</option>
                            }
                            <option value="" selected="@Model.NewAddressPreselected">@T("Checkout.NewAddress")</option>
                        </select>
                    </div>
                </div>
            }
            @await Component.InvokeAsync("Widget", new { widgetZone = "op_checkout_shipping_address_middle" })
            <div class="section new-shipping-address" id="shipping-new-address-form">
                <div class="enter-address">
                    <div asp-validation-summary="ModelOnly" class="message-error"></div>
                    @{
                        var dataDictAddress = new ViewDataDictionary(ViewData);
                        dataDictAddress.TemplateInfo.HtmlFieldPrefix = "ShippingNewAddress";
                        <partial name="_CreateOrUpdateAddress" model="Model.NewAddress" view-data="dataDictAddress" />
                    }
                </div>
            </div>
            @await Component.InvokeAsync("Widget", new { widgetZone = "op_checkout_shipping_address_bottom" })
        </div>
    }
</div>