@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inherits DbContextPage

<RadzenDataList WrapItems="true" AllowPaging="false" Data="@orders" TItem="Order">
    <Template Context="order">
        <RadzenCard Style="width:300px;">
            <RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
                <RadzenImage Path="@order.Employee?.Photo" Style="width: 80px; height: 80px; border-radius: 50%" AlternateText="@(order.Employee?.FirstName + " " + order.Employee?.LastName)" />
                <RadzenStack Gap="0">
                    <RadzenText TextStyle="TextStyle.Overline" class="rz-display-flex rz-mt-2 rz-my-0">Employee</RadzenText>
                    <RadzenText TextStyle="TextStyle.Body1"><b>@(order?.Employee?.FirstName + " " + order?.Employee?.LastName)</b></RadzenText>
                    <RadzenText TextStyle="TextStyle.Overline" class="rz-display-flex rz-mt-4 rz-mb-0">City</RadzenText>
                    <RadzenText TextStyle="TextStyle.Body1"><b>@(order.ShipCity), @(order.ShipCountry)</b></RadzenText>
                </RadzenStack>
            </RadzenStack>
            <hr style="border: none; background-color: rgba(0,0,0,.2); height: 1px; margin: 1rem 0;" />
            <RadzenRow>
                <RadzenColumn Size="8" class="rz-text-truncate">
                    <b>@(order.ShipName)</b>
                </RadzenColumn>
                <RadzenColumn Size="4" class="rz-text-align-end">
                    <RadzenBadge BadgeStyle="BadgeStyle.Secondary" Text=@($"{String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", order.Freight)}") />
                </RadzenColumn>
            </RadzenRow>
        </RadzenCard>
    </Template>
</RadzenDataList>

<RadzenPager ShowPagingSummary="true" PagingSummaryFormat="@pagingSummaryFormat" HorizontalAlign="HorizontalAlign.Right" Count="count" PageSize="@pageSize" PageNumbersCount="5" PageChanged="@PageChanged" />

@code {
    string pagingSummaryFormat = "Displaying page {0} of {1} (total {2} records)";
    int pageSize = 6;
    int count;
    IEnumerable<Order> orders;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        count = dbContext.Orders.Count();
        orders = GetOrders(0, pageSize);
    }

    void PageChanged(PagerEventArgs args)
    {
        orders = GetOrders(args.Skip, args.Top);
    }

    IEnumerable<Order> GetOrders(int skip, int take)
    {
        return dbContext.Orders.Include("Customer").Include("Employee").Skip(skip).Take(take).ToList();
    }
}