@model ShipmentModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.Orders.Shipments.ViewDetails").Text;

    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("Shipments");
}


<form asp-controller="Order" asp-action="ShipmentDetails" method="post">
    <script>
        $(document).ready(function() {
            toggleShippedDate(false);
            toggleReadyForPickupDate(false);
            toggleDeliveryDate(false);
        });

        function toggleShippedDate(editmode) {
            if (editmode) {
                $('#lblShippedDate').hideElement();
                $('#divShippedDate').showElement();
                $('#btnEditShippedDate').hideElement();
                $('#btnSaveShippedDate').showElement();
                $('#btnCancelShippedDate').showElement();
            } else {
                $('#lblShippedDate').showElement();
                $('#divShippedDate').hideElement();
                $('#btnEditShippedDate').showElement();
                $('#btnSaveShippedDate').hideElement();
                $('#btnCancelShippedDate').hideElement();
            }
        }

        function toggleReadyForPickupDate(editmode) {
            if (editmode) {
                $('#lblReadyForPickupDate').hideElement();
                $('#divReadyForPickupDate').showElement();
                $('#btnEditReadyForPickupDate').hideElement();
                $('#btnSaveReadyForPickupDate').showElement();
                $('#btnCancelReadyForPickupDate').showElement();
            } else {
                $('#lblReadyForPickupDate').showElement();
                $('#divReadyForPickupDate').hideElement();
                $('#btnEditReadyForPickupDate').showElement();
                $('#btnSaveReadyForPickupDate').hideElement();
                $('#btnCancelReadyForPickupDate').hideElement();
            }
        }

        function toggleDeliveryDate(editmode) {
            if (editmode) {
                $('#lblDeliveryDate').hideElement();
                $('#divDeliveryDate').showElement();
                $('#btnEditDeliveryDate').hideElement();
                $('#btnSaveDeliveryDate').showElement();
                $('#btnCancelDeliveryDate').showElement();
            } else {
                $('#lblDeliveryDate').showElement();
                $('#divDeliveryDate').hideElement();
                $('#btnEditDeliveryDate').showElement();
                $('#btnSaveDeliveryDate').hideElement();
                $('#btnCancelDeliveryDate').hideElement();
            }
        }
    </script>

    <div class="content-header clearfix">
        <h1 class="float-left">
            @T("Admin.Orders.Shipments.ViewDetails") - @Model.Id
            <small>
                <i class="fas fa-arrow-circle-left"></i>
                <a asp-action="Edit" asp-route-id="@Model.OrderId">@T("Admin.Orders.Shipments.BackToOrder")</a>
            </small>
        </h1>
        <div class="float-right">
            <a asp-action="PdfPackagingSlip" asp-route-shipmentId="@Model.Id" class="btn btn-info">
                <i class="far fa-file-pdf"></i>
                @T("Admin.Orders.Shipments.PrintPackagingSlip")
            </a>
            <span id="shipment-delete" class="btn btn-danger">
                <i class="far fa-trash-alt"></i>
                @T("Admin.Common.Delete")
            </span>
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.OrderShipmentDetailsButtons, additionalData = Model })
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <div asp-validation-summary="All"></div>
            <div class="form-horizontal">
                <div class="cards-group">
                    <div class="card card-default">
                        <div class="card-body">
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="CustomOrderNumber" />
                                </div>
                                <div class="col-md-9">
                                    <a asp-controller="Order" asp-action="Edit" asp-route-id="@Model.OrderId">@Model.CustomOrderNumber - @T("Admin.Common.View")</a>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="TrackingNumber" />
                                </div>
                                <div class="col-md-9">
                                    <div class="input-group input-group-short float-left">
                                        <nop-editor asp-for="TrackingNumber" />
                                        <span class="input-group-append">
                                            <button type="submit" name="settrackingnumber" class="btn btn-info">
                                                @T("Admin.Orders.Shipments.TrackingNumber.Button")
                                            </button>
                                        </span>
                                    </div>
                                    @if (!string.IsNullOrEmpty(Model.TrackingNumberUrl))
                                    {
                                        <a href="@Model.TrackingNumberUrl" target="_blank" class="margin-l-10">@T("Admin.Orders.Shipments.TrackingNumber.ViewOnline")</a>
                                    }
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="AdminComment" />
                                </div>
                                <div class="col-md-9">
                                    <div class="input-group">
                                        <nop-editor asp-for="AdminComment" />
                                        <span class="input-group-append">
                                            <button type="submit" name="setadmincomment" class="btn btn-info">
                                                @T("Admin.Orders.Shipments.AdminComment.Button")
                                            </button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="TotalWeight" />
                                </div>
                                <div class="col-md-9">
                                    <div class="form-text-row">@Model.TotalWeight</div>
                                </div>
                            </div>
                            @if (Model.PickupInStore)
                            {
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="ReadyForPickupDate" />
                                    </div>
                                    <div class="col-md-9">
                                        <div class="input-group input-group-short">
                                            <div id="lblReadyForPickupDate" class="input-group-text">
                                                @Model.ReadyForPickupDate
                                            </div>
                                            @if (Model.ReadyForPickupDateUtc.HasValue)
                                            {
                                                <div id="divReadyForPickupDate" style="display: inline-block;" class="col-md-9">
                                                    <nop-editor asp-for="ReadyForPickupDateUtc" />
                                                    @T("Admin.Orders.Shipments.ReadyForPickupDate.EnterUtc")&nbsp;&nbsp;
                                                </div>
                                            }
                                            <div class="input-group-append col-md-3">
                                                @if (Model.CanMarkAsReadyForPickup)
                                                {
                                                    <button type="submit" name="setasreadyforpickup" id="setasreadyforpickup" class="btn btn-info btn-flat">
                                                        @T("Admin.Orders.Shipments.ReadyForPickupDate.Button")
                                                    </button>
                                                }
                                                @if (Model.ReadyForPickupDateUtc.HasValue)
                                                {
                                                    <button type="submit" onclick="toggleReadyForPickupDate(true);return false;" id="btnEditReadyForPickupDate" class="btn btn-primary">
                                                        @T("Admin.Common.Edit")
                                                    </button>

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

                                                    <button type="submit" onclick="toggleReadyForPickupDate(false);return false;" id="btnCancelReadyForPickupDate" class="btn btn-success">
                                                        @T("Admin.Common.Cancel")
                                                    </button>
                                                }
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="ShippedDate" />
                                    </div>
                                    <div class="col-md-9">
                                        <div class="input-group input-group-short">
                                            <div id="lblShippedDate" class="input-group-text">
                                                @Model.ShippedDate
                                            </div>
                                            @if (Model.ShippedDateUtc.HasValue)
                                            {
                                                <div id="divShippedDate" style="display: inline-block;" class="col-md-9">
                                                    <nop-editor asp-for="ShippedDateUtc" />
                                                    @T("Admin.Orders.Shipments.ShippedDate.EnterUtc")&nbsp;&nbsp;
                                                </div>
                                            }
                                            <div class="input-group-append col-md-3">
                                                @if (Model.CanShip)
                                                {
                                                    <button type="submit" name="setasshipped" id="setasshipped" class="btn btn-info btn-flat">
                                                        @T("Admin.Orders.Shipments.ShippedDate.Button")
                                                    </button>
                                                }
                                                @if (Model.ShippedDateUtc.HasValue)
                                                {
                                                    <button type="submit" onclick="toggleShippedDate(true);return false;" id="btnEditShippedDate" class="btn btn-primary">
                                                        @T("Admin.Common.Edit")
                                                    </button>

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

                                                    <button type="submit" onclick="toggleShippedDate(false);return false;" id="btnCancelShippedDate" class="btn btn-success">
                                                        @T("Admin.Common.Cancel")
                                                    </button>
                                                }
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            }
                            <div class="form-group row">
                                <div class="col-md-3">
                                    <nop-label asp-for="DeliveryDate" />
                                </div>

                                <div class="col-md-9">
                                    <div class="input-group input-group-short">
                                        <div id="lblDeliveryDate" class="input-group-text">
                                            @Model.DeliveryDate
                                        </div>
                                        @if (Model.DeliveryDateUtc.HasValue)
                                        {
                                            <div id="divDeliveryDate" style="display: inline-block;" class="col-md-9">
                                                <nop-editor asp-for="DeliveryDateUtc" />
                                                @T("Admin.Orders.Shipments.DeliveryDate.EnterUtc")&nbsp;&nbsp;
                                            </div>
                                        }
                                        <div class="input-group-append col-md-3">
                                            @if (Model.CanDeliver)
                                            {
                                                <button type="submit" name="setasdelivered" id="setasdelivered" class="btn btn-info btn-flat">
                                                    @T("Admin.Orders.Shipments.DeliveryDate.Button")
                                                </button>
                                            }
                                            @if (Model.DeliveryDateUtc.HasValue)
                                            {

                                                <button type="submit" onclick="toggleDeliveryDate(true);return false;" id="btnEditDeliveryDate" class="btn btn-primary">
                                                    @T("Admin.Common.Edit")
                                                </button>

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

                                                <button type="submit" onclick="toggleDeliveryDate(false);return false;" id="btnCancelDeliveryDate" class="btn btn-success">
                                                    @T("Admin.Common.Cancel")
                                                </button>
                                            }
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card card-default">
                        <div class="card-header">
                            @T("Admin.Orders.Shipments.Products")
                        </div>
                        <div class="card-body">
                            <table class="table table-hover table-bordered">
                                <thead>
                                    <tr>
                                        <th>
                                            @T("Admin.Orders.Shipments.Products.ProductName")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.Products.SKU")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.Products.Warehouse")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.Products.ItemWeight")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.Products.ItemDimensions")
                                        </th>
                                        @if (Model.PickupInStore)
                                        {
                                            <th>
                                                @T("Admin.Orders.Shipments.Products.QtyReadyForPickup")
                                            </th>
                                        }
                                        else
                                        {
                                            <th>
                                                @T("Admin.Orders.Shipments.Products.QtyShipped")
                                            </th>
                                        }
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in Model.Items)
                                    {
                                    <tr>
                                        <td style="width: 40%;" class="text-left">
                                            <div>
                                                <em><a asp-controller="Product" asp-action="Edit" asp-route-id="@item.ProductId">@item.ProductName</a></em>
                                                @if (!string.IsNullOrEmpty(item.AttributeInfo))
                                                    {
                                                    <p>
                                                        @Html.Raw(item.AttributeInfo)
                                                    </p>
                                                    }
                                                @if (!string.IsNullOrEmpty(item.RentalInfo))
                                                    {
                                                    <p>
                                                        @Html.Raw(item.RentalInfo)
                                                    </p>
                                                    }
                                            </div>
                                        </td>
                                        <td style="width: 15%;" class="text-center">
                                            <div>
                                                @item.Sku
                                            </div>
                                        </td>
                                        <td style="width: 15%;" class="text-center">
                                            <div>
                                                @item.ShippedFromWarehouse
                                            </div>
                                        </td>
                                        <td style="width: 10%;" class="text-center">
                                            @item.ItemWeight
                                        </td>
                                        <td style="width: 10%;" class="text-center">
                                            @item.ItemDimensions
                                        </td>
                                        <td style="width: 10%;" class="text-center">
                                            @item.QuantityInThisShipment
                                        </td>
                                    </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>

                    @if (Model.ShipmentStatusEvents.Count > 0)
                    {
                    <div class="card card-default">
                        <div class="card-header">
                            @T("Admin.Orders.Shipments.ShipmentStatusEvents")
                        </div>
                        <div class="card-body">
                            <table class="table table-hover table-bordered text-center">
                                <thead>
                                    <tr>
                                        <th>
                                            @T("Admin.Orders.Shipments.ShipmentStatusEvents.Event")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.ShipmentStatusEvents.Location")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.ShipmentStatusEvents.Country")
                                        </th>
                                        <th>
                                            @T("Admin.Orders.Shipments.ShipmentStatusEvents.Date")
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var item in Model.ShipmentStatusEvents)
                                        {
                                        <tr>
                                            <td style="width:40%;">
                                                <div>
                                                    @item.EventName
                                                </div>
                                            </td>
                                            <td style="width:20%;">
                                                <div>
                                                    @item.Location
                                                </div>
                                            </td>
                                            <td style="width:20%;">
                                                <div>
                                                    @item.Country
                                                </div>
                                            </td>
                                            <td style="width:20%;">
                                                <div>
                                                    @if (item.Date.HasValue)
                                                        {
                                                        @item.Date.Value.ToString("D")
                                                        }
                                                </div>
                                            </td>
                                        </tr>
                                        }
                                </tbody>
                            </table>
                        </div>
                    </div>
                    }
                </div>
            </div>
        </div>
    </section>
</form>
<nop-delete-confirmation asp-model-id="@Model.Id" asp-button-id="shipment-delete" asp-action="DeleteShipment"/>