@page "/newsletler"
@attribute [Microsoft.AspNetCore.Authorization.Authorize]

@inject IDialogService DialogService
@inject ISnackbar Snackbar
@inject IUserUtility UserUtility
@inject IRestWrapper RestWrapper

<MudStack class="w-full p-8 h-screen bg-[--mud-palette-background-grey]">
    <MudGrid>
        <MudItem xs="12">
            <MudStack Row="true" class="mb-5">
                <MudText Typo="Typo.h4">اعضا خبرنامه</MudText>
                <MudChip Color="Color.Info" Variant="Variant.Outlined">124 عدد</MudChip>
                <MudSpacer />
            </MudStack>
            <MudPaper>
                <MudDataGrid FixedFooter="true" FixedHeader="true" Striped="true"
                             T="NewsletterMemberSDto" Items="@ViewModel.Members" CurrentPage="@ViewModel.CurrentPage"
                             RowsPerPage="20" Filterable="false" Loading="@ViewModel.IsProcessing"
                             SortMode="@SortMode.None" Groupable="false">
                    <Columns>
                        <PropertyColumn Title="شماره تماس" Property="arg => arg.PhoneNumber" />
                        <PropertyColumn Title="ایمیل" Property="arg => arg.Email" />
                    </Columns>
                    <PagerContent>
                        <MudStack Row="true" class="w-full">

                            <MudPagination Rectangular="true" Variant="Variant.Filled" Count="@ViewModel.PageCount"
                                           SelectedChanged="@ViewModel.ChangePageAsync" class="my-4 mx-auto" />
                        </MudStack>

                    </PagerContent>
                </MudDataGrid>
            </MudPaper>
        </MudItem>
    </MudGrid>
</MudStack>

@code
{
    public NewsletterManagementPageViewModel ViewModel { get; set; }
    protected override async Task OnInitializedAsync()
    {
        ViewModel = new NewsletterManagementPageViewModel(Snackbar, UserUtility, RestWrapper, DialogService);
        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();
    }
}
