@using PantheonRA.BackOffice.Enums
@model PantheonRA.BackOffice.Models.ProductsListViewModel
@{
    ViewBag.Title = Loc.Products;
    var userCanAccessProductImport = PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.PRODUCT_IMPORT);
    var userCanAccessProductCud = PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.PRODUCT_CUD);
}

<div class="wrapper wrapper-content">
    <div class="tabs-container">
        @Html.Partial("~/Views/Products/_CodeListTabNavigation.cshtml")
        <div class="tab-content">
            <div class="row buttons-tabbed">
                @if (userCanAccessProductCud)
                {
                    <a href="@Url.Action("Create", "Products")" class="btn btn-primary btn-primary btn-outline" title="@Loc.CreateNewProduct">
                        <i class="fa fa-plus"></i><span class="bold visible-lg-inline m-l-xs">@Loc.NewProduct</span>
                    </a>
                }

                @if (userCanAccessProductImport)
                {
                    <div class="btn-group dropdown">
                        <button type="button"
                                id="importButton"
                                class="btn btn-primary btn-outline printDropdown"
                                onClick="importProductsClick()"
                                title="@Loc.ImportProducts">
                            <i class="fas fa-cloud-upload-alt"></i><span class="visible-lg-inline visible-md-inline m-l-xs">@Loc.ImportProducts</span>
                        </button>
                        <button type="button" class="btn btn-primary btn-outline dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="@Url.Action("DownloadProductsImportTemplate", "Products")" class="btn btn-primary btn-outline" title="@Loc.DownloadImportTemplate">
                                    <span>@Loc.DownloadImportTemplate</span>
                                </a>
                            </li>
                            <li>
                                <a id="importProductsButton" onClick="importProductsClick()" class="btn btn-primary btn-outline" title="@Loc.ImportProducts">
                                    <span>@Loc.ImportProducts</span>
                                </a>
                            </li>
                        </ul>
                    </div>
                }
            </div>

            @Html.HiddenFor(model => model.DefaultDecimalPlacesPrice)
            @Html.HiddenFor(model => model.DefaultDecimalPlacesQuantity)
            @Html.HiddenFor(model => model.DefaultDecimalPlacesValue)
            <div class="row document-head">
                <div class="col-md-2 col-xs-4">
                    @Html.Partial("~/Views/Products/_ProductsTabNavigation.cshtml", ProductCodelistType.Idents)
                </div>
                <div class="col-md-2 col-xs-4">
                    <div class="form-group">
                        <label class="control-label">@Loc.SearchFilter</label>
                        @Html.TextBoxFor(model => model.Keywords, new { @id = "Keywords", @class = "form-control search-input", @placeholder = Loc.Search, autocomplete = "off" })
                    </div>
                </div>
                <div class="col-md-2 col-xs-4">
                    <div class="form-group">
                        <label class="control-label">@Loc.Status</label>
                        @Html.DropDownListFor(model => model.Status, Model.ActiveStatuses, new { @class = "form-control custom-select" })
                    </div>
                </div>
                <div class="col-md-2 col-xs-4">
                    <div class="form-group">
                        <label class="control-label">@Loc.AccountingTypes</label>
                        @Html.DropDownListFor(model => model.Type, Model.Types, Loc.AccountingTypes, new { @class = "form-control custom-select" })
                    </div>
                </div>
                <div class="col-md-2 col-xs-4">
                    <div class="form-group">
                        <label class="control-label">@Loc.MainMeasurementUnit</label>
                        @Html.DropDownListFor(model => model.MeasurementUnit, Model.MeasurementUnits, Loc.MainMeasurementUnit, new { @class = "form-control custom-select" })
                    </div>
                </div>
                <div class="col-md-2 col-xs-4">
                    <div class="form-group">
                        <label class="control-label">@Loc.Supplier</label>
                        @Html.TextBoxFor(model => model.SupplierId, HtmlAttributesHelper.CreateInputAttributes("form-control typeahead_3 typeahead_large", "SupplierId",
                        false, Loc.Supplier, true, new { dataUrl = Url.Action("SearchSuppliers", "ReceivedBills") }))
                    </div>
                </div>
            </div>

            <div class="project-list">
                <div class="document-list">
                    <table id="grid-data" data-grid-id="products" data-url="@Url.Action("SetItemsList", "SetItem")" class="list-table">
                        <thead>
                            <tr>
                                <th width="3%" class="text-center">@Loc.ActiveShort</th>
                                <th width="10%" data-name="Ident" data-url="@Url.Action("Edit", "Products")?id=">@Loc.Code / @Loc.Ident</th>
                                <th width="17%" data-name="Name" data-url="@Url.Action("Edit", "Products")?id=">@Loc.Name</th>
                                <th width="7%" data-name="RetailPrice" class="dt-right">@Loc.RetailPrice</th>
                                <th width="7%" data-name="SellingPrice" class="dt-right">@Loc.SellingPrice</th>
                                <th width="12%" data-name="Classif">@Loc.PrimaryClassification</th>
                                <th width="13%" data-name="Classif2">@Loc.SecondaryClassification</th>
                                <th width="10%" data-name="Type">@Loc.AccountingType</th>
                                <th width="6%" data-name="Barcode">@Loc.SuppliersCode</th>
                                <th width="15%" data-name="Supplier">@Loc.Supplier</th>
                            </tr>
                        </thead>
                    </table>
                </div>
                <div class="row document-footer document-footer-sm">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <span class="pull-left"><span>@Loc.NumberOfIdents:</span> <b class="grid-data-total-items"></b></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="userCanAccessProductImport" value="@userCanAccessProductImport.ToString()" />
<input type="hidden" id="userCanAccessProductCud" value="@userCanAccessProductCud.ToString()" />
<input type="hidden" id="searchPlaceholder" value="@Loc.ProductListSearch" />
<input type="hidden" value="@Url.Action("ImportProducts", "Products")" id="importProductsUrl" />
<input type="hidden" value="@Url.Action("ImportProductContractPrices", "Products")" id="importProductsContractPricesUrl" />

@section pageScripts{
    @Scripts.Render("~/bundles/product")
    <script>
        $(document).ready(function () {
            initializeProductsProductList();
        });
    </script>
}