@model AddProductToOrderModel

@using Nop.Core.Domain.Catalog

@{
    //page title
    ViewBag.PageTitle = string.Format(T("Admin.Orders.Products.AddNew.Title2").Text, Model.Name, Model.OrderId);
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("Orders");
}

@*we add enctype = "multipart/form-data" because "File upload" attribute control type requires it*@

<form asp-controller="Order" asp-action="AddProductToOrderDetails" asp-route-orderId="@Model.OrderId"
      asp-route-productId="@Model.ProductId" enctype="multipart/form-data" method="post" id="product-details-form">
    
    <div asp-validation-summary="All"></div>

    <div class="content-header clearfix">
        <h1 class="float-left">
            @string.Format(T("Admin.Orders.Products.AddNew.Title2").Text, Model.Name, Model.OrderId)
            <small>
                <i class="fas fa-arrow-circle-left"></i>
                <a asp-action="AddProductToOrder" asp-route-orderId="@Model.OrderId">@T("Admin.Orders.Products.AddNew.BackToList")</a>
            </small>
        </h1>
        <div class="float-right">
            &nbsp;
        </div>
    </div>

   <section class="content">
        <div class="container-fluid">
           @if (Model.Warnings.Count > 0)
            {
                <div class="callout callout-danger">
                    <ul>
                        @foreach (var warning in Model.Warnings)
                        {
                            <li>@warning</li>
                        }
                    </ul>
                </div>
            }

            <div class="form-horizontal">
                <div class="cards-group">
                    @if (Model.ProductType == ProductType.SimpleProduct)
                    {
                        <div class="card card-default">
                            <div class="card-body">
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="UnitPriceInclTax" />
                                    </div>
                                    <div class="col-md-9">
                                        <nop-editor asp-for="UnitPriceInclTax" />
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="UnitPriceExclTax" />
                                    </div>
                                    <div class="col-md-9">
                                        <nop-editor asp-for="UnitPriceExclTax" />
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="Quantity" />
                                    </div>
                                    <div class="col-md-9">
                                        <nop-editor asp-for="Quantity" />
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="SubTotalInclTax" />
                                    </div>
                                    <div class="col-md-9">
                                        <nop-editor asp-for="SubTotalInclTax" />
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <div class="col-md-3">
                                        <nop-label asp-for="SubTotalExclTax" />
                                    </div>
                                    <div class="col-md-9">
                                        <nop-editor asp-for="SubTotalExclTax" />
                                    </div>
                                </div>
                            </div>
                        </div>

                        var dataDict = new ViewDataDictionary(ViewData) { new KeyValuePair<string, object>("productId", Model.ProductId) };
                        @await Html.PartialAsync("_ProductAddAttributes", Model.ProductAttributes, dataDict)

                        var dataDictGiftCard = new ViewDataDictionary(ViewData);
                        dataDictGiftCard.TemplateInfo.HtmlFieldPrefix = $"giftcard_{@Model.ProductId}";
                        @await Html.PartialAsync("_ProductAddGiftCardInfo", Model.GiftCard, dataDictGiftCard)

                        @await Html.PartialAsync("_ProductAddRentalInfo", Model)

                        <div class="card card-default">
                            <div class="card-body">
                                @if (!Model.AutoUpdateOrderTotals)
                                { 
                                    <div class="form-group row">
                                        <div class="col-md-9 offset-md-3">
                                            <p>
                                                <strong>@T("Admin.Orders.Products.AddNew.UpdateTotals")</strong>
                                            </p>
                                        </div>
                                    </div>
                                }
                                <div class="form-group row">
                                    <div class="col-md-9 offset-md-3">
                                        <button type="submit" class="btn btn-primary">
                                            @T("Admin.Orders.Products.AddNew")
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    }
                    else if (Model.ProductType == ProductType.GroupedProduct)
                    {
                        <div class="card card-default">
                            <div class="card-body">
                                Grouped products are not currently supported for adding to an existing order
                            </div>
                        </div>
                    }
                    else
                    {
                        <div class="card card-default">
                            <div class="card-body">
                                This product type (unknown) is not currently supported for adding to an existing order
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
   </section>
</form>