@model OrderModel

<div class="card-body">
    <div class="row">
        <div class="col-md-6 card-group">
            <div class="card mb-3">
                <div class="card-header clearfix">
                    @T("Admin.Orders.Fields.BillingAddress")
                </div>
                <div class="card-body">
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.FullName")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.FirstName @Model.BillingAddress.LastName
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Email")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.Email
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Phone")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.PhoneNumber
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Fax")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.FaxNumber
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Company")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.Company
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Address1")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.Address1
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Address2")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.Address2
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.City")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.City
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.County")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.County
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.StateProvince")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.StateProvinceName
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.ZipPostalCode")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.ZipPostalCode
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-md-4">
                            <div class="label-wrapper">
                                <label class="col-form-label">
                                    @T("Admin.Orders.Address.Country")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-8">
                            <div class="form-text-row">
                                @Model.BillingAddress.CountryName
                            </div>
                        </div>
                    </div>

                    @if (!string.IsNullOrEmpty(Model.BillingAddress.FormattedCustomAddressAttributes))
                    {
                        <div class="form-group row">
                            <div class="col-md-4">
                                <div class="label-wrapper">
                                    <label class="col-form-label">@T("Admin.Orders.Address.CustomAttributes")</label>
                                </div>
                            </div>
                            <div class="col-md-8">
                                <div class="form-text-row">
                                    @Html.Raw(Model.BillingAddress.FormattedCustomAddressAttributes)
                                </div>
                            </div>
                        </div>
                    }

                </div>

                @if (!Model.IsLoggedInAsVendor)
                {
                    <div class="card-footer">
                        <div class="form-group row justify-content-end">
                            <div class="col-auto">
                                <a asp-action="AddressEdit" asp-route-addressId="@Model.BillingAddress.Id" asp-route-orderId="@Model.Id" class="btn btn-primary">@T("Admin.Common.Edit")</a>
                            </div>
                        </div>
                    </div>
                }
            </div>
        </div>

        <div class="col-md-6 card-group">
            @if (Model.IsShippable)
            {
                if (!Model.PickupInStore && Model.ShippingAddress != null)
                {
                    <div class="card mb-3">
                        <div class="card-header clearfix">
                            @T("Admin.Orders.Fields.ShippingAddress")
                        </div>
                        <div class="card-body">
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.FullName")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.FirstName @Model.ShippingAddress.LastName
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Email")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.Email
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Phone")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.PhoneNumber
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Fax")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.FaxNumber
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Company")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.Company
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Address1")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.Address1
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Address2")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.Address2
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.City")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.City
                                    </div>
                                </div>
                            </div>

                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.County")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.County
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.StateProvince")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.StateProvinceName
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.ZipPostalCode")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.ZipPostalCode
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-4">
                                    <div class="label-wrapper">
                                        <label class="col-form-label">
                                            @T("Admin.Orders.Address.Country")
                                        </label>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    <div class="form-text-row">
                                        @Model.ShippingAddress.CountryName
                                    </div>
                                </div>
                            </div>

                            @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = AdminWidgetZones.OrderShippingAddressDetailsBottom, additionalData = Model })

                            @if (!string.IsNullOrEmpty(Model.ShippingAddress.FormattedCustomAddressAttributes))
                            {
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <div class="label-wrapper">
                                            <label class="col-form-label">@T("Admin.Orders.Address.CustomAttributes")</label>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="form-text-row">
                                            @Html.Raw(Model.ShippingAddress.FormattedCustomAddressAttributes)
                                        </div>
                                    </div>
                                </div>
                            }

                        </div>

                        <div class="card-footer">
                            <div class="form-group row">
                                <div class="col-auto mr-auto">
                                    <div class="form-text-row mb-2">
                                        <img alt="google maps" src="@Url.Content("~/css/admin/images/gmaps.ico")" />
                                        <a href="@Html.Raw(Model.ShippingAddressGoogleMapsUrl)" style="margin-bottom: 10px;" target="_blank">@T("Admin.Orders.Fields.ShippingAddress.ViewOnGoogleMaps")</a>
                                    </div>
                                </div>
                                @if (!Model.IsLoggedInAsVendor)
                                {
                                    <div class="col-auto">
                                        <a asp-action="AddressEdit" asp-route-addressId="@Model.ShippingAddress.Id" asp-route-orderId="@Model.Id" class="btn btn-primary">@T("Admin.Common.Edit")</a>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                }

                if (Model.PickupInStore && Model.PickupAddress != null)
                {

                    <div class="card mb-3">
                        <div class="card-header clearfix">
                            @T("Admin.Orders.Fields.PickupAddress")
                        </div>
                        <div class="card-body">
                            @if (!string.IsNullOrEmpty(Model.PickupAddress.Address1))
                            {
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <div class="label-wrapper">
                                            <label class="col-form-label">
                                                @T("Admin.Orders.Address.Address1")
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="form-text-row">
                                            @Model.PickupAddress.Address1
                                        </div>
                                    </div>
                                </div>
                            }

                            @if (!string.IsNullOrEmpty(Model.PickupAddress.City))
                            {
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <div class="label-wrapper">
                                            <label class="col-form-label">
                                                @T("Admin.Orders.Address.City")
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="form-text-row">
                                            @Model.PickupAddress.City
                                        </div>
                                    </div>
                                </div>
                            }

                            @if (!string.IsNullOrEmpty(Model.PickupAddress.County))
                            {
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <div class="label-wrapper">
                                            <label class="col-form-label">
                                                @T("Admin.Orders.Address.County")
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="form-text-row">
                                            @Model.PickupAddress.County
                                        </div>
                                    </div>
                                </div>
                            }

                            @if (!string.IsNullOrEmpty(Model.PickupAddress.CountryName))
                            {
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <div class="label-wrapper">
                                            <label class="col-form-label">
                                                @T("Admin.Orders.Address.Country")
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="form-text-row">
                                            @Model.PickupAddress.CountryName
                                        </div>
                                    </div>
                                </div>
                            }

                            @if (!string.IsNullOrEmpty(Model.PickupAddress.ZipPostalCode))
                            {
                                <div class="form-group row">
                                    <div class="col-md-4">
                                        <div class="label-wrapper">
                                            <label class="col-form-label">
                                                @T("Admin.Orders.Address.ZipPostalCode")
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="form-text-row">
                                            @Model.PickupAddress.ZipPostalCode
                                        </div>
                                    </div>
                                </div>
                            }

                        </div>

                        <div class="card-footer">
                            <div class="form-group row">
                                <div class="col-auto mr-auto">
                                    <div class="form-text-row mb-2">
                                        <img alt="google maps" src="@Url.Content("~/css/admin/images/gmaps.ico")" />
                                        <a href="@Html.Raw(Model.PickupAddressGoogleMapsUrl)" style="margin-bottom: 10px;" target="_blank">@T("Admin.Orders.Fields.PickupAddress.ViewOnGoogleMaps")</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                }
            }
            else
            {
                <div class="form-group row mx-auto">
                    <div class="col-auto">
                        @T("Admin.Orders.ShippingInfo.NotRequired")
                    </div>
                </div>
            }
        </div>

    </div>

    @if (Model.IsShippable)
    {
        <div class="card card-default">
            <div class="card-body">
                <div class="form-group row">
                    <div class="col-lg-3">
                        <nop-label asp-for="ShippingMethod" />
                    </div>
                    <div class="col-lg-9">
                        @if (!Model.IsLoggedInAsVendor)
                        {
                            <script>
                                $(function () {
                                    toggleEditShippingMethod(false);
                                });

                                function toggleEditShippingMethod(editmode) {
                                    if (editmode) {
                                        $('#lblShippingMethod').hideElement();
                                        $('#divShippingMethod').showElement();
                                        $('#btnEditShippingMethod').hideElement();
                                        $('#btnSaveShippingMethod').showElement();
                                        $('#btnCancelShippingMethod').showElement();
                                    } else {
                                        $('#lblShippingMethod').showElement();
                                        $('#divShippingMethod').hideElement();
                                        $('#btnEditShippingMethod').showElement();
                                        $('#btnSaveShippingMethod').hideElement();
                                        $('#btnCancelShippingMethod').hideElement();
                                    }
                                }
                            </script>
                            <div class="input-group input-group-short">
                                <div id="lblShippingMethod" class="input-group-text">
                                    @Model.ShippingMethod
                                </div>
                                <div id="divShippingMethod">
                                    <nop-editor asp-for="ShippingMethod" />
                                </div>
                                <span class="input-group-append">
                                    <button type="submit" onclick="toggleEditShippingMethod(true);return false;" id="btnEditShippingMethod" class="btn btn-primary">
                                        @T("Admin.Common.Edit")
                                    </button>

                                    <button type="submit" id="btnSaveShippingMethod" name="save-shipping-method" class="btn btn-primary">
                                        @T("Admin.Common.Save")
                                    </button>
                                    <nop-action-confirmation asp-button-id="btnSaveShippingMethod" />

                                    <button type="submit" onclick="toggleEditShippingMethod(false);return false;" id="btnCancelShippingMethod" class="btn btn-secondary">
                                        @T("Admin.Common.Cancel")
                                    </button>
                                </span>
                            </div>
                        }
                        else
                        {
                            <div id="lblShippingMethod">
                                <div class="form-text-row">@Model.ShippingMethod</div>
                            </div>
                        }
                    </div>
                </div>

                @if (!Model.IsLoggedInAsVendor)
                {
                    <div class="form-group row">
                        <div class="col-lg-3">
                            <nop-label asp-for="ShippingStatus" />
                        </div>
                        <div class="col-lg-9">
                            <div class="form-text-row">@Model.ShippingStatus</div>
                        </div>
                    </div>
                }
            </div>
        </div>

        <div class="card card-default">
            <div class="card-header">
                @T("Admin.Orders.Shipments")
            </div>
            <div class="card-body">
                @await Html.PartialAsync("Table", new DataTablesModel
                {
                    Name = "shipments-grid",
                    UrlRead = new DataUrl("ShipmentsByOrder", "Order", new RouteValueDictionary { [nameof(OrderShipmentSearchModel.OrderId)] = Model.Id }),
                    PrimaryKeyColumn = nameof(ShipmentModel.Id),
                    Length = Model.OrderShipmentSearchModel.PageSize,
                    LengthMenu = Model.OrderShipmentSearchModel.AvailablePageSizes,
                    ColumnCollection = new List<ColumnProperty>
                    {
                        new ColumnProperty(null)
                        {
                            Render = new RenderChildCaret(),
                            Width = "5",
                            Searchable = false,
                            ClassName =  NopColumnClassDefaults.ChildControl
                        },
                        new ColumnProperty(nameof(ShipmentModel.Id))
                        {
                            Title = T("Admin.Orders.Shipments.ID").Text,
                            Width = "50"
                        },
                        new ColumnProperty(nameof(ShipmentModel.CustomOrderNumber))
                        {
                            Title = T("Admin.Orders.Shipments.CustomOrderNumber").Text,
                            Width = "100"
                        },
                        new ColumnProperty(nameof(ShipmentModel.TrackingNumber))
                        {
                            Title = T("Admin.Orders.Shipments.TrackingNumber").Text,
                            Width = "100"
                        },
                        new ColumnProperty(nameof(ShipmentModel.TotalWeight))
                        {
                            Title = T("Admin.Orders.Shipments.TotalWeight").Text,
                            Width = "100"
                        },
                        (Model.PickupInStore ? 
                            new ColumnProperty(nameof(ShipmentModel.ReadyForPickupDate))
                            {
                                Title = T("Admin.Orders.Shipments.ReadyForPickupDate").Text,
                                Width = "100"
                            } : 
                            new ColumnProperty(nameof(ShipmentModel.ShippedDate))
                            {
                                Title = T("Admin.Orders.Shipments.ShippedDate").Text,
                                Width = "100"
                            }),
                        new ColumnProperty(nameof(ShipmentModel.DeliveryDate))
                        {
                            Title = T("Admin.Orders.Shipments.DeliveryDate").Text,
                            Width = "100"
                        },
                        new ColumnProperty(nameof(ShipmentModel.Id))
                        {
                            Title = T("Admin.Common.View").Text,
                            Width = "50",
                            Render = new RenderButtonView(new DataUrl("~/Admin/Order/ShipmentDetails/"))
                        }
                    },
                    ChildTable = new DataTablesModel
                    {
                        Name = "shipment-items-grid",
                        UrlRead = new DataUrl("ShipmentsItemsByShipmentId", "Order", null),
                        IsChildTable = true,
                        Length = Model.OrderShipmentSearchModel.PageSize,
                        LengthMenu = Model.OrderShipmentSearchModel.AvailablePageSizes,
                        Filters = new List<FilterParameter>
                        {
                            new FilterParameter(nameof(ShipmentItemSearchModel.ShipmentId), nameof(ShipmentModel.Id), true)
                        },
                        ColumnCollection = new List<ColumnProperty>
                        {
                            new ColumnProperty(nameof(ShipmentItemModel.ProductName))
                            {
                                Title = T("Admin.Orders.Shipments.Products.ProductName").Text,
                                Width = "400"
                            },
                            new ColumnProperty(nameof(ShipmentItemModel.ShippedFromWarehouse))
                            {
                                Title = T("Admin.Orders.Shipments.Products.Warehouse").Text,
                                Width = "150"
                            },
                            new ColumnProperty(nameof(ShipmentItemModel.QuantityInThisShipment))
                            {
                                Title = T("Admin.Orders.Shipments.Products.QtyShipped").Text,
                                Width = "150"
                            },
                            new ColumnProperty(nameof(ShipmentItemModel.ItemWeight))
                            {
                                Title = T("Admin.Orders.Shipments.Products.ItemWeight").Text,
                                Width = "150"
                            },
                            new ColumnProperty(nameof(ShipmentItemModel.ItemDimensions))
                            {
                                Title = T("Admin.Orders.Shipments.Products.ItemDimensions").Text,
                                Width = "150"
                            }
                        }
                    }
                })
            </div>
            @if (Model.CanAddNewShipments)
            {
                <div class="card-footer">
                    <button type="submit" id="btnAddNewShipment" name="btnAddNewShipment" onclick="javascript:setLocation('@(Url.Action("AddShipment", "Order", new { id = Model.Id }))'); return false;" class="btn btn-primary">
                        @T("Admin.Orders.Shipments.AddNew")
                    </button>
                </div>
            }
        </div>
    }
</div>
