@page "/seller/statistics"
@using Website.Components.DataTable

<Title Value="@($"Statistics Seller - Unturned Store")"></Title>

<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item">Seller</li>
        <li class="breadcrumb-item active" aria-current="page">Statistics</li>
    </ol>
</nav>

@if (Orders != null)
{
    <div class="mb-3 row">
        <div class="col-md-4 mb-2">
            <div class="card shadow text-center">
                <div class="card-body">
                    <h5 class="card-title">$@Orders.Where(x => x.CreateDate > DateTime.UtcNow.AddDays(-1)).Sum(x => x.TotalPrice)</h5>
                    <p class="card-text text-muted">Today's Revenue</p>
                </div>
            </div>
        </div>
        <div class="col-md-4 mb-2">
            <div class="card shadow text-center">
                <div class="card-body">
                    <h5 class="card-title">$@Orders.Where(x => x.CreateDate > DateTime.UtcNow.AddDays(-31)).Sum(x => x.TotalPrice)</h5>
                    <p class="card-text text-muted">Last 30 Days Revenue</p>
                </div>
            </div>
        </div>
        <div class="col-md-4 mb-2">
            <div class="card shadow text-center">
                <div class="card-body">
                    <h5 class="card-title">$@Orders.Sum(x => x.TotalPrice)</h5>
                    <p class="card-text text-muted">All Time Revenue</p>
                </div>
            </div>
        </div>
    </div>
    <div class="mb-3">
        <DataTable TItem="MOrderItem" Data="OrderItems">
            <DataTableTitle TItem="MOrderItem">
                <div class="d-flex align-items-center">
                    <div class="fs-5">
                        Orders (@context.Items.Count())
                    </div>
                </div>        
            </DataTableTitle>
            <DataTableColumn TItem="MOrderItem" Name="ID" Field="x => x.Id" IsSearchable="true" SearchType="ESearchType.Exact" />
            <DataTableColumn TItem="MOrderItem" Name="Product" Field="x => x.ProductName" IsSearchable="true" SearchType="ESearchType.Contains" Context="item">
                <div class="d-flex align-items-center">
                    <div>
                        <img src="/api/images/@item.Product.ImageId" width="30" height="30" />
                    </div>
                    <div class="ms-2">
                        <a href="/products/@item.ProductId" class="text-decoration-none">
                            @item.ProductName
                        </a>
                    </div>
                </div>
            </DataTableColumn>
            <DataTableColumn TItem="MOrderItem" Name="User" Field="x => x.Order.Buyer.Name" IsSearchable="true" SearchType="ESearchType.Contains" Context="item">
                <div class="d-flex align-items-center">
                    <div>
                        <img class="rounded-circle" src="/api/images/@item.Order.Buyer.AvatarImageId" width="30" height="30" />
                    </div>
                    <div class="ms-2">
                        <a href="/users/@item.Order.Buyer.Id" class="text-decoration-none">
                            @item.Order.Buyer.Name
                        </a>
                    </div>
                </div>
            </DataTableColumn>
            <DataTableColumn TItem="MOrderItem" Name="Payer" Field="x => x.Order.PaymentSender" Context="item" IsSearchable="true" SearchType="ESearchType.Exact">
                @item.Order.PaymentSender
            </DataTableColumn>
            <DataTableColumn TItem="MOrderItem" Name="Payment Method" Field="x => x.Order.PaymentMethod" Context="user" IsSearchable="true" />
            <DataTableColumn TItem="MOrderItem" Name="Amount" Field="x => x.Price" Context="user" IsSearchable="false" />
            <DataTableColumn TItem="MOrderItem" Name="Currency" Field="x => string.Empty" Context="user" IsSearchable="false">
                USD
            </DataTableColumn>
            <DataTableColumn TItem="MOrderItem" Name="Date" Field="x => x.Order.CreateDate" IsSearchable="false" />
        </DataTable>
    </div>
} else
{
    <Progressbar />
}

