@using Nop.Core
@using Nop.Services.Customers
@model CheckoutBillingAddressModel
@inject IWebHelper webHelper
@inject IWorkContext workContext
@inject ICustomerService _customerService
@{
    Layout = "_ColumnsOne";

    var storeLocation = webHelper.GetStoreLocation();

    //title
    NopHtml.AddTitleParts(T("PageTitle.Checkout").Text);
    //page class
    NopHtml.AppendPageCssClassParts("html-checkout-page");
    NopHtml.AppendPageCssClassParts("html-billing-address-page");
}
<script src="~/js/public.billingaddress.js" asp-location="Footer"></script>
@await Component.InvokeAsync(typeof(CheckoutProgressViewComponent), new { step = CheckoutProgressStep.Address })
<div class="page checkout-page">
    <div class="page-title panel-heading">
        <h1>@T("Checkout.BillingAddress")</h1>
    </div>
    <div class="page-body checkout-data">
        <form id="billing-form" asp-route="CheckoutBillingAddress" method="post">
            <div class="billing-addresses">
                <div id="toggle-billing-address">
                    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.CheckoutBillingAddressTop, additionalData = Model })
                    @if (Model.ShipToSameAddressAllowed)
                    {
                    <div class="section ship-to-same-address">
                        <div class="selector">
                            <input asp-for="ShipToSameAddress" />
                            <label asp-for="ShipToSameAddress">@T("Checkout.ShipToSameAddress")</label>
                        </div>
                    </div>
                    }
                    @if (Model.ExistingAddresses.Count > 0)
                    {
                    <div class="section select-billing-address">
                        <div class="title small-heading">
                            <strong>@T("Checkout.SelectBillingAddress")</strong>
                        </div>
                        @if (Model.InvalidExistingAddresses.Count > 0)
                            {
                        <label class="min-amount-warning">
                            @string.Format(T("Checkout.Addresses.Invalid").Text, Model.InvalidExistingAddresses.Count)
                        </label>
                            }
                        <div class="address-grid row">
                            @foreach (var item in Model.ExistingAddresses)
                            {
                                <div class="address-item col-xs-12 col-sm-4 col-md-4">
                                    <div class="select-button">
                                        <button type="button" class="btn btn-primary select-billing-address-button" onclick="selectBillingAddress@(item.Id)()">@T("Checkout.BillToThisAddress")</button>
                                        <script asp-location="Footer">
                                                function selectBillingAddress@(item.Id)() {
                                                    if ($('#@Html.IdFor(model => model.ShipToSameAddress)')
                                                        .is(':checked')) {
                                                        setLocation(
                                                            '@Html.Raw(Url.RouteUrl("CheckoutSelectBillingAddress", new {addressId = item.Id, shipToSameAddress = "true"}))');
                                                    } else {
                                                        setLocation(
                                                            '@Url.RouteUrl("CheckoutSelectBillingAddress", new {addressId = item.Id})');
                                                    }
                                                }
                                        </script>
                                    </div>
                                    <div class="address-list-page">
                                        <button id="edit-button-@(item.Id)" type="button" class="button-2 btn btn-default edit-address-button" onclick="CheckoutBilling.editAddress('@(storeLocation)checkout/GetAddressById/', @(item.Id), '@T("Checkout.EditAddress")'); return false;">@T("Common.Edit")</button>
                                        <button id="delete-button-@(item.Id)" type="button" class="button-2 btn btn-default delete-address-button" onclick="CheckoutBilling.deleteEditAddress('@(storeLocation)checkout/DeleteEditBillingAddress/', @(item.Id)); return false;">@T("Common.Delete")</button>
                                    </div>
                                    <ul class="address-box">
                                        <li class="name">
                                            <strong>@item.FirstName @item.LastName</strong>
                                        </li>
                                        <li class="email">
                                            <label>@T("Address.Fields.Email"):</label>
                                            <span>@item.Email</span>
                                        </li>
                                        @if (item.PhoneEnabled)
                                                {
                                        <li class="phone">
                                            <label>@T("Address.Fields.PhoneNumber"):</label>
                                            <span>@item.PhoneNumber</span>
                                        </li>
                                                }
                                        @if (item.FaxEnabled)
                                                {
                                        <li class="fax">
                                            <label>@T("Address.Fields.FaxNumber"):</label>
                                            <span>@item.FaxNumber</span>
                                        </li>
                                                }
                                        @if (item.CompanyEnabled && !string.IsNullOrEmpty(item.Company))
                                                {
                                        <li class="company">
                                            @item.Company
                                        </li>
                                                }
                                        @if (item.StreetAddressEnabled)
                                                {
                                        <li class="address1">
                                            @item.Address1
                                        </li>
                                                }
                                        @if (item.StreetAddress2Enabled && !string.IsNullOrEmpty(item.Address2))
                                                {
                                        <li class="address2">
                                            @item.Address2
                                        </li>
                                                }
                                        @if (item.CityEnabled && !string.IsNullOrEmpty(item.City) ||
                                                    item.CountyEnabled && !string.IsNullOrEmpty(item.County) ||
                                                    item.StateProvinceEnabled && !string.IsNullOrEmpty(item.StateProvinceName) ||
                                                    item.ZipPostalCodeEnabled && !string.IsNullOrEmpty(item.ZipPostalCode))
                                                {
                                        <li class="city-state-zip">
                                            @if (item.CityEnabled && !string.IsNullOrEmpty(item.City))
                                                        {
                                            @item.City
                                                            if (item.CountyEnabled && !string.IsNullOrEmpty(item.County) ||
                                                             item.StateProvinceEnabled && !string.IsNullOrEmpty(item.StateProvinceName) ||
                                                             item.ZipPostalCodeEnabled && !string.IsNullOrEmpty(item.ZipPostalCode))
                                                            {
                                            <text>,</text>
                                                            }
                                                        }
                                            @if (item.CountyEnabled && !string.IsNullOrEmpty(item.County))
                                                        {
                                            @item.County
                                                            if (item.StateProvinceEnabled && !string.IsNullOrEmpty(item.StateProvinceName) ||
                                                          item.ZipPostalCodeEnabled && !string.IsNullOrEmpty(item.ZipPostalCode))
                                                            {
                                            <text>,</text>
                                                            }
                                                        }
                                            @if (item.StateProvinceEnabled && !string.IsNullOrEmpty(item.StateProvinceName))
                                                        {
                                            @item.StateProvinceName
                                                            if (item.ZipPostalCodeEnabled && !string.IsNullOrEmpty(item.ZipPostalCode))
                                                            {
                                            <text>,</text>
                                                            }
                                                        }
                                            @if (item.ZipPostalCodeEnabled && !string.IsNullOrEmpty(item.ZipPostalCode))
                                                        {
                                            @item.ZipPostalCode
                                                        }
                                        </li>
                                                }
                                        @if (item.CountryEnabled && !string.IsNullOrEmpty(item.CountryName))
                                                {
                                        <li class="country">
                                            @item.CountryName
                                        </li>
                                                }
                                        @if (!string.IsNullOrEmpty(item.FormattedCustomAddressAttributes))
                                                {
                                        <li class="custom-attributes-view">
                                            @Html.Raw(item.FormattedCustomAddressAttributes)
                                        </li>
                                                }
                                    </ul>
                                </div>
                            }
                        </div>
                    </div>
                    }
                </div>
                @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.CheckoutBillingAddressMiddle, additionalData = Model })
                <div class="section new-billing-address" id="billingaddress-new-form">
                    <div class="title small-heading">
                        @if (Model.ExistingAddresses.Count > 0)
                        {
                        <strong class="title-text">@T("Checkout.OrEnterNewAddress")</strong>
                        }
                        else
                        {
                        <strong>@T("Checkout.EnterBillingAddress")</strong>
                        }
                    </div>
                    @if (Model.EuVatEnabled)
                    {
                        <div class="inputs form-group row">
                            <label asp-for="VatNumber" asp-postfix=":" class="control-label col-sm-2 col-md-2"></label>
                            @if (Model.EuVatEnabledForGuests)
                            {
                                <div class="col-sm-6 col-md-6">
                                    <input asp-for="VatNumber" class="vat-numbers" />
                                </div>
                                <div class="col-sm-4 col-md-4">
                                    <span asp-validation-for="VatNumber"></span>
                                </div>
                            }
                            else
                            {
                                <span class="vat-number-warning">
                                    @T("Checkout.VatNumber.Disabled", Url.RouteUrl("CustomerInfo"))
                                </span>
                            }
                        </div>
                    }
                    <div class="enter-address">
                        <div asp-validation-summary="ModelOnly" class="message-error"></div>
                        <div class="enter-address-body form-horizontal">
                            @{
                                var dataDictAddress = new ViewDataDictionary(ViewData);
                                dataDictAddress.TemplateInfo.HtmlFieldPrefix = "BillingNewAddress";
                                @await Html.PartialAsync("_CreateOrUpdateAddress", Model.BillingNewAddress, dataDictAddress)
                            }
                        </div>
                    </div>
                    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.CheckoutBillingAddressBottom, additionalData = Model })
                </div>
                <div class="form-group row next-btn-wrapper">
                    <div class="col-md-12 billings-address-btns">
                        <button id="billingaddress-save-button" type="button" class="button-1 btn btn-default" style="display: none" onclick="CheckoutBilling.saveEditAddress('@(storeLocation)checkout/SaveEditBillingAddress/'); return false;">@T("Common.Save")</button>
                        <button id="billingaddress-cancel-button" type="button" class="button-1 btn btn-default" style="display: none" onclick="setLocation('@Url.RouteUrl("CheckoutBillingAddress")')">@T("Common.Cancel")</button>
                        <button type="submit" name="nextstep" class="btn btn-primary new-address-next-step-button">@T("Checkout.NextButton")</button>
                    </div>
                </div>
            </div>
        </form>
        <script asp-location="Footer">
            CheckoutBilling.init('#billing-form');
            $('#edit-billing-address-button').show();
            $('#delete-billing-address-button').show();
        </script>
        <div class="section order-summary-body">
            <div class="title small-heading">
                <strong>@T("Checkout.OrderSummary")</strong>
            </div>
            @await Component.InvokeAsync(typeof(OrderSummaryViewComponent))
        </div>
    </div>
</div>
