@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
@{
    const string cardId = "order-average-report-card";
    const string hideCardAttributeName = "Reports.HideOrderAverageReportCard";
    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="far fa-money-bill-alt"></i>
            @T("Admin.SalesReport.Average")
        </h3>
        <div class="card-tools float-right">
            <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" style="padding-bottom: 22px;">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "average-order-report-grid",
            UrlRead = new DataUrl("OrderAverageReportList", "Order", null),
            Length = int.MaxValue,
            Paging = false,
            Info = false,
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(OrderAverageReportModel.OrderStatus))
                {
                    Title = T("Admin.SalesReport.Average.OrderStatus").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumTodayOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumTodayOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumThisWeekOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumThisWeekOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumThisMonthOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumThisMonthOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumThisYearOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumThisYearOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumAllTimeOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumAllTimeOrders").Text
                }
            }
        })
    </div>
</div>