@model BestsellerBriefSearchModel
@using Nop.Services.Orders;

@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
@{
    const string cardId = "bestsellers-report-quantity-card";
    const string hideCardAttributeName = "Reports.HideBestsellersBriefReportByQuantityCard";
    var hideCard = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideCardAttributeName);
}

<div class="card card-primary card-outline @if(hideCard){<text>collapsed-card</text>}" id="@cardId">
    <div class="card-header with-border">
        <h3 class="card-title">
            <i class="fas fa-star"></i>
            @T("Admin.Reports.Sales.BestSellers.ByQuantity")
        </h3>
        <div class="card-tools float-right">
            <button type="button" class="btn btn-tool" data-card-widget="collapse">
                @if (hideCard)
                {
                    <text><i class="fas fa-plus"></i></text>
                }
                else
                {
                    <text><i class="fas fa-minus"></i></text>
                }
            </button>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $('#@cardId').on('click', 'button[data-card-widget="collapse"]', function () {
                var collapsed = !$('#@cardId').hasClass('collapsed-card');
                saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hideCardAttributeName', collapsed);
            });
        });
    </script>
    <div class="card-body">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "bestsellers-byquantity-grid",
            UrlRead = new DataUrl("BestsellersBriefReportByQuantityList", "Order", new RouteValueDictionary { [nameof(Model.OrderBy)] = OrderByEnum.OrderByQuantity }),
            Length = Model.PageSize,
            Dom = "<'row'<'col-md-12't>>" +
                  "<'row margin-t-5'" +
                    "<'col-lg-10 col-xs-12'<'float-lg-left'p>>" +
                    "<'col-lg-2 col-xs-12'<'float-lg-right text-center'i>>" +
                  ">",
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(BestsellerModel.ProductName))
                {
                    Title = T("Admin.Reports.Sales.Bestsellers.Fields.Name").Text
                },
                new ColumnProperty(nameof(BestsellerModel.TotalQuantity))
                {
                    Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalQuantity").Text
                },
                new ColumnProperty(nameof(BestsellerModel.TotalAmount))
                {
                    Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalAmount").Text
                },
                new ColumnProperty(nameof(BestsellerModel.ProductId))
                {
                    Title = T("Admin.Common.View").Text,
                    Width = "80",
                    ClassName = NopColumnClassDefaults.Button,
                    Render = new RenderButtonView(new DataUrl("~/Admin/Product/Edit/"))
                }
            }
        })
    </div>
</div>