@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
@{
    const string cardId = "order-incomplete-report-card";
    const string hideCardAttributeName = "Reports.HideOrderIncompleteReportCard";
    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-hourglass-start"></i>
            @T("Admin.Dashboard.IncompleteOrders")
        </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">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "incomplete-order-report-grid",
            UrlRead = new DataUrl("OrderIncompleteReportList", "Order", null),
            Length = int.MaxValue,
            Paging = false,
            Info = false,
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(OrderIncompleteReportModel.Item))
                {
                    Title = T("Admin.SalesReport.Incomplete.Item").Text
                },
                new ColumnProperty(nameof(OrderIncompleteReportModel.Total))
                {
                    Title = T("Admin.SalesReport.Incomplete.Total").Text,
                    Width = "50"
                },
                new ColumnProperty(nameof(OrderIncompleteReportModel.Count))
                {
                    Title = T("Admin.SalesReport.Incomplete.Count").Text,
                    Width = "120",
                    ClassName =  NopColumnClassDefaults.Button,
                    Render = new RenderCustom("renderColumnOrderIncompleteReportCount")
                }
            }
        })
        <script>
            function renderColumnOrderIncompleteReportCount(data, type, row, meta) {
                return '<a class="btn btn-default" href="' + row.ViewLink +'"><i class="far fa-eye"></i>' + row.Count + ' - @T("Admin.SalesReport.Incomplete.View").Text</a>';
            }
        </script>
    </div>
</div>