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

@inherits DbContextPage

<RadzenStack Gap="1rem">
    <RadzenCard Variant="Variant.Outlined">
        <RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0.5rem;" Wrap="FlexWrap.Wrap">
            <RadzenLabel Text="Pager Position:" Component="DropDown1" />
            <RadzenDropDown @bind-Value="@pagerPosition" TextProperty="Text" Name="DropDown1" ValueProperty="Value" 
                            Data="@(Enum.GetValues(typeof(PagerPosition)).Cast<PagerPosition>().Select(t => new { Text = $"{t}", Value = t }))" />
        </RadzenStack>
    </RadzenCard>

    <RadzenDataGrid Data="@orderDetails" PagerPosition="@pagerPosition" AllowPaging="true" AllowSorting="true">
        <Columns>
            <RadzenDataGridColumn Property="OrderID" Title="OrderID" />
            <RadzenDataGridColumn Property="ProductID" Title="ProductID" />
            <RadzenDataGridColumn Property="UnitPrice" Title="Unit Price">
                <Template Context="detail">
                    @String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", detail.UnitPrice)
                </Template>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn Property="@nameof(OrderDetail.Quantity)" Title="Quantity" />
            <RadzenDataGridColumn Property="@nameof(OrderDetail.Discount)" Title="Discount">
                <Template Context="detail">
                    @String.Format("{0}%", detail.Discount * 100)
                </Template>
            </RadzenDataGridColumn>
        </Columns>
    </RadzenDataGrid>
</RadzenStack>

@code {
    PagerPosition pagerPosition = PagerPosition.Bottom;

    IEnumerable<OrderDetail> orderDetails;

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

        orderDetails = dbContext.OrderDetails;
    }
}