@model ProductAttributeSearchModel

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


<div class="content-header clearfix">
    <h1 class="float-left">
        @T("Admin.Catalog.Attributes.ProductAttributes")
    </h1>
    <div class="float-right">
        <a asp-action="Create" class="btn btn-primary">
            <i class="fas fa-plus-square"></i>
            @T("Admin.Common.AddNew")
        </a>
        @await Component.InvokeAsync(typeof(AdminWidgetViewComponent), new { widgetZone = AdminWidgetZones.ProductAttributeListButtons, additionalData = Model })
        <button type="button" id="delete-selected" class="btn btn-danger">
            <i class="far fa-trash-alt"></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="cards-group">
        <div class="card card-default">
            <div class="card-body">
                <p>
                    @T("Admin.Catalog.Attributes.ProductAttributes.Description")
                    <nop-doc-reference asp-string-resource="@T("Admin.Documentation.Reference.ProductAttributes", Docs.ProductAttributes + Utm.OnAdmin)" asp-add-wrapper="false"/>
                </p>
                @await Html.PartialAsync("Table", new DataTablesModel
                {
                    Name = "products-grid",
                    UrlRead = new DataUrl("List", "ProductAttribute", null),
                    Length = Model.PageSize,
                    LengthMenu = Model.AvailablePageSizes,
                    ColumnCollection = new List<ColumnProperty>
                    {
                         new ColumnProperty(nameof(ProductAttributeModel.Id))
                        {
                            IsMasterCheckBox = true,
                            Render = new RenderCheckBox("checkbox_productattributes"),
                            ClassName =  NopColumnClassDefaults.CenterAll,
                            Width = "50"
                        },
                        new ColumnProperty(nameof(ProductAttributeModel.Name))
                        {
                            Title = T("Admin.Catalog.Attributes.ProductAttributes.Fields.Name").Text
                        },
                        new ColumnProperty(nameof(ProductAttributeModel.Id))
                        {
                            Title = T("Admin.Common.Edit").Text,
                            Width = "100",
                            ClassName =  NopColumnClassDefaults.Button,
                            Render = new RenderButtonEdit(new DataUrl("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", "ProductAttribute"))",
                                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('#products-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>