@model ShipmentModel
@{
    //page title
    ViewBag.Title = string.Format(Loc["Admin.Orders.Shipments.AddNew.Title"], Model.OrderId);

}
<form asp-area="@Constants.AreaAdmin" asp-controller="Shipment" asp-action="AddShipment" method="post"
      asp-route-orderId="@Context.Request.Query["orderId"]">

    <div asp-validation-summary="All"></div>

    <div class="col-md-12">
        <div class="x_panel light form-fit">
            <div class="x_title">
                <div class="caption">
                    <i class="fa fa-truck"></i>
                    @string.Format(Loc["Admin.Orders.Shipments.AddNew.Title"], Model.OrderNumber)
                    <small>
                        <i class="fa fa-arrow-circle-left"></i>
                        @Html.ActionLink(Loc["Admin.Orders.Shipments.BackToOrder"], "Edit", "Order", new { Id = Model.OrderId })
                    </small>
                </div>
                <div class="actions">
                    <div class="btn-group btn-group-devided">
                        <button class="btn btn-success" type="submit" id="shipment-save" name="save"><i class="fa fa-check"></i> @Loc["Admin.Common.Save"] </button>
                        <button class="btn btn-success" type="submit" id="shipment-save-continue" name="save-continue"><i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"] </button>
                        <vc:admin-widget widget-zone="order_shipment_add_buttons" additional-data="null" />
                    </div>
                </div>
            </div>
            <div class="x_content form">
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="form-group">
                            <admin-label asp-for="TrackingNumber" />
                            <div class="col-md-9 col-sm-9">
                                <admin-input asp-for="TrackingNumber" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="AdminComment" />
                            <div class="col-md-9 col-sm-9">
                                <admin-input asp-for="AdminComment" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>



    <h4><strong>@Loc["Admin.Orders.Shipments.Products"]</strong></h4>

    <div class="table-responsive visible-xs-block visible-sm-block visible-md-block visible-lg-block">
        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.ProductName"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.SKU"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.Warehouse"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.ItemWeight"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.ItemDimensions"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.QtyOrdered"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.QtyShipped"]
                    </th>
                    <th>
                        @Loc["Admin.Orders.Shipments.Products.QtyToShip"]
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Items)
                {
                    <tr>
                        <td>
                            <div style="padding-left:10px;padding-right:10px;">
                                <em><a href="@Url.Action("Edit", "Product", new {id = item.ProductId, area = Constants.AreaAdmin})">@item.ProductName</a></em>
                                @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                {
                                    <p>
                                        @Html.Raw(item.AttributeInfo)
                                    </p>
                                }
                                @if (item.ShipSeparately)
                                {
                                    <p>
                                        <strong>@Loc["Admin.Orders.Shipments.Products.ShipSeparately.Warning"]</strong>
                                        @Loc["Admin.Orders.Shipments.Products.ShipSeparately"]
                                    </p>
                                }
                            </div>
                        </td>
                        <td>
                            <div style="padding-left:10px;padding-right:10px;">
                                @item.Sku
                            </div>
                        </td>
                        <td>
                            <div>
                                @if (item.AllowToChooseWarehouse)
                                {
                                    if (item.AvailableWarehouses.Count > 0)
                                    {
                                        <select name="warehouse_@(item.OrderItemId)" id="warehouse_@(item.OrderItemId)">
                                            @foreach (var warehouse in item.AvailableWarehouses)
                                            {
                                                var selected = warehouse.WarehouseId == item.WarehouseId ? true : false;
                                                <option value="@(warehouse.WarehouseId)" data-stock-qty="@(warehouse.StockQuantity)"
                                                        data-reserved-qty="@(warehouse.ReservedQuantity)"
                                                        selected="@selected">
                                                    @Loc["Admin.Orders.Shipments.Products.Warehouse.ChooseQty", warehouse.WarehouseName, warehouse.StockQuantity, warehouse.ReservedQuantity]
                                                </option>
                                            }
                                        </select>
                                    }
                                    else
                                    {
                                        <div>@Loc["Admin.Orders.Shipments.Products.Warehouse.NotAvailabe"]</div>
                                    }
                                }
                                else
                                {
                                    //display warehouses
                                    for (int i = 0; i < item.AvailableWarehouses.Count; i++)
                                    {
                                        var warehouse = item.AvailableWarehouses[i];
                                        @warehouse.WarehouseName
                                        if (i != item.AvailableWarehouses.Count - 1)
                                        {
                                            <br />
                                        }
                                    }
                                }
                            </div>
                        </td>
                        <td>
                            @item.ItemWeight
                        </td>
                        <td>
                            @item.ItemDimensions
                        </td>
                        <td>
                            @item.QuantityOrdered
                        </td>
                        <td>
                            @item.QuantityInAllShipments
                        </td>
                        <td>
                            <input name="qtyToAdd@(item.OrderItemId)" type="number" value="@item.QuantityToAdd"
                                   id="qtyToAdd@(item.OrderItemId)" class="form-control" style="width:100px;" max="@item.QuantityToAdd" />
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>


</form>
