@model ManufacturerSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.Catalog.Manufacturers").Text;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("Manufacturers");
}

@{
    const string hideSearchBlockAttributeName = "ManufacturersPage.HideSearchBlock";
    var hideSearchBlock = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideSearchBlockAttributeName);
}

<div class="content-header clearfix">
    <h1 class="float-left">
        @T("Admin.Catalog.Manufacturers")
    </h1>
    <div class="float-right">
        <a asp-action="Create" class="btn btn-primary">
            <i class="fas fa-square-plus"></i>
            @T("Admin.Common.AddNew")
        </a>
        <div class="btn-group">
            <button type="button" class="btn btn-success">
                <i class="fas fa-download"></i>
                @T("Admin.Common.Export")
            </button>
            <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                <span class="caret"></span>
                <span class="sr-only">&nbsp;</span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li class="dropdown-item">
                    <a asp-action="ExportXml">
                        <i class="far fa-file-code"></i>
                        @T("Admin.Common.ExportToXml")
                    </a>
                </li>
                <li class="dropdown-item">
                    <a asp-action="ExportXlsx">
                        <i class="far fa-file-excel"></i>
                        @T("Admin.Common.ExportToExcel")
                    </a>
                </li>
            </ul>
        </div>
        <button type="button" name="importexcel" class="btn bg-olive" data-toggle="modal" data-target="#importexcel-window">
            <i class="fas fa-upload"></i>
            @T("Admin.Common.Import")
        </button>
        @await Component.InvokeAsync(typeof(AdminWidgetViewComponent), new { widgetZone = AdminWidgetZones.ManufacturerListButtons, additionalData = Model })
        <button type="button" id="delete-selected" class="btn btn-danger">
            <i class="far fa-trash-can"></i>
            @T("Admin.Common.Delete.Selected")
        </button>
        <nop-action-confirmation asp-button-id="delete-selected" />
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="form-horizontal">
            <div class="cards-group">
                <div class="card card-default card-search">
                    <div class="card-body">
                        <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                            <div class="search-text">@T("Admin.Common.Search")</div>
                            <div class="icon-search"><i class="fas fa-magnifying-glass" aria-hidden="true"></i></div>
                            <div class="icon-collapse"><i class="far fa-angle-@(!hideSearchBlock ? "up" : "down")" aria-hidden="true"></i></div>
                        </div>

                        <div class="search-body @(hideSearchBlock ? "closed" : "")">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group row">
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchManufacturerName" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-editor asp-for="SearchManufacturerName" />
                                        </div>
                                    </div>
                                    <div class="form-group row" @(Model.HideStoresList ? Html.Raw("style=\"display:none\"") : null)>
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchStoreId" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="SearchStoreId" asp-items="Model.AvailableStores" />
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-4">
                                            <nop-label asp-for="SearchPublishedId" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="SearchPublishedId" asp-items="Model.AvailablePublishedOptions" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="text-center col-12">
                                    <button type="button" id="search-manufacturers" class="btn btn-primary btn-search">
                                        <i class="fas fa-magnifying-glass"></i>
                                        @T("Admin.Common.Search")
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card card-default">
                <div class="card-body">
                    <nop-doc-reference asp-string-resource="@T("Admin.Documentation.Reference.Manufacturers", Docs.Manufacturers + Utm.OnAdmin)" />

                    @await Html.PartialAsync("Table", new DataTablesModel
                    {
                        Name = "manufacturers-grid",
                        UrlRead = new DataUrl("List", "Manufacturer", null),
                        SearchButtonId = "search-manufacturers",
                        Length = Model.PageSize,
                        LengthMenu = Model.AvailablePageSizes,
                        Filters = new List<FilterParameter>
                        {
                            new FilterParameter(nameof(Model.SearchManufacturerName)),
                            new FilterParameter(nameof(Model.SearchStoreId)),
                            new FilterParameter(nameof(Model.SearchPublishedId))
                        },
                        ColumnCollection = new List<ColumnProperty>
                        {
                            new ColumnProperty(nameof(ManufacturerModel.Id))
                            {
                                IsMasterCheckBox = true,
                                Render = new RenderCheckBox("checkbox_manufacturers"),
                                ClassName =  NopColumnClassDefaults.CenterAll,
                                Width = "50"
                            },
                            new ColumnProperty(nameof(ManufacturerModel.Name))
                            {
                                Title = T("Admin.Catalog.Manufacturers.Fields.Name").Text
                            },
                            new ColumnProperty(nameof(ManufacturerModel.Published))
                            {
                                Title = T("Admin.Catalog.Manufacturers.Fields.Published").Text,
                                Width = "100",
                                ClassName =  NopColumnClassDefaults.CenterAll,
                                Render = new RenderBoolean()
                            },
                            new ColumnProperty(nameof(ManufacturerModel.DisplayOrder))
                            {
                                Title = T("Admin.Catalog.Manufacturers.Fields.DisplayOrder").Text,
                                Width = "150",
                                ClassName = NopColumnClassDefaults.CenterAll
                            },
                            new ColumnProperty(nameof(ManufacturerModel.Id))
                            {
                                Title = T("Admin.Common.Edit").Text,
                                Width = "100",
                                ClassName =  NopColumnClassDefaults.Button,
                                Render = new RenderButtonEdit(new DataUrl("~/Admin/Manufacturer/Edit"))
                            }
                        }
                    })


                    <script>
                        $(function() {
                            $('#delete-selected-action-confirmation-submit-button').bind('click', function () {
                                var postData = {
                                    selectedIds: selectedIds
                                };
                                addAntiForgeryToken(postData);
                                $.ajax({
                                    cache: false,
                                    type: "POST",
                                    url: "@(Url.Action("DeleteSelected", "Manufacturer"))",
                                    data: postData,
                                    error: function (jqXHR, textStatus, errorThrown) {
                                        showAlert('deleteSelectedFailed', errorThrown);
                                    },
                                    complete: function (jqXHR, textStatus) {
                                        if (jqXHR.status === 204)
                                        {
                                            showAlert('nothingSelectedAlert', '@T("Admin.Common.Alert.NothingSelected")');
                                            return;
                                        }
                                        updateTable('#manufacturers-grid');
                                    }
                                });
                                $('#delete-selected-action-confirmation').modal('toggle');
                                return false;
                            });
                        });
                    </script>
                    <nop-alert asp-alert-id="deleteSelectedFailed" />
                    <nop-alert asp-alert-id="nothingSelectedAlert" />
                </div>
            </div>
        </div>
    </div>   
</section>
@*import manufacturers form*@
<div id="importexcel-window" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="importexcel-window-title">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="importexcel-window-title">@T("Admin.Common.ImportFromExcel")</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>                                
            </div>
            <form asp-controller="Manufacturer" asp-action="ImportFromXlsx" method="post" enctype="multipart/form-data">
                <div class="form-horizontal">
                    <div class="modal-body">
                        <ul class="common-list">
                            <li>
                                <em>@T("Admin.Catalog.Manufacturers.List.ImportFromExcelTip")</em>
                            </li>
                            <li>
                                <em>@T("Admin.Common.ImportFromExcel.ManyRecordsWarning")</em>
                            </li>
                        </ul>
                        <div class="form-group row">
                            <div class="col-md-2">
                                <div class="label-wrapper">
                                    <label class="col-form-label">
                                        @T("Admin.Common.ExcelFile")
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-10">
                                <input type="file" id="importexcelfile" name="importexcelfile" class="form-control" />
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">
                            @T("Admin.Common.ImportFromExcel")
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>