@page "/ProfilePage"
@inject IRestWrapper RestWrapper
@inject ISnackbar Snackbar
@inject IUserUtility UserUtility
@inject NavigationManager NavigationManager


<BasePageUi Title="پروفایل شما" Description="اطلاعات پروفایل شما باید دقیق و کامل باشد">
    <MudStack class="p-5 pb-10">
        <MudTextField @bind-Value="@ViewModel.User.FirstName" T="string" Label="نـــــــام" Variant="Variant.Outlined" />
        <MudTextField @bind-Value="@ViewModel.User.LastName" T="string" Label="نام خانوادگی" Variant="Variant.Outlined" />
        <MudTextField @bind-Value="@ViewModel.User.PhoneNumber" T="string" Label="شماره تماس" Variant="Variant.Outlined" />
        <MudTextField @bind-Value="@ViewModel.User.StudentId" T="string" Label="شماره دانشجویی" Variant="Variant.Outlined" />

        <MudAutocomplete @bind-Value="@ViewModel.SelectedCity"
                         SearchFunc="@ViewModel.SearchCity"
                         T="CitySDto"
                         ToStringFunc="dto => dto.Name"
                         Label="شهر شما"
                         Variant="Variant.Outlined">
            <ProgressIndicatorInPopoverTemplate>
                <MudList Clickable="false">
                    <MudListItem>
                        <div class="flex flex-row w-full mx-auto">
                            <MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true" />
                            <p class="font-bold my-1 mx-auto text-md">منتظر بمانید</p>
                        </div>
                    </MudListItem>
                </MudList>
            </ProgressIndicatorInPopoverTemplate>
            <ItemTemplate Context="e">
                <p>@e.Name</p>
            </ItemTemplate>
        </MudAutocomplete>

        <MudAutocomplete @bind-Value="@ViewModel.SelectedUni"
                         ToStringFunc="dto => dto.Name"
                         SearchFunc="@ViewModel.SearchUniversity"
                         T="UniversitySDto" Label="دانشگاه" Variant="Variant.Outlined">
            <ProgressIndicatorInPopoverTemplate>
                <MudList Clickable="false">
                    <MudListItem>
                        <div class="flex flex-row w-full mx-auto">
                            <MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true" />
                            <p class="font-bold my-1 mx-auto text-md">منتظر بمانید</p>
                        </div>
                    </MudListItem>
                </MudList>
            </ProgressIndicatorInPopoverTemplate>
            <ItemTemplate Context="e">
                <p>@e.Name</p>
            </ItemTemplate>
        </MudAutocomplete>

        <MudAutocomplete T="SectionSDto" Label="بخش فعلی" Variant="Variant.Outlined"
                         ToStringFunc="dto => dto.Name"
                         SearchFunc="@ViewModel.SearchSection"
                         @bind-Value="@ViewModel.SelectedSection">

            <ProgressIndicatorInPopoverTemplate>
                <MudList Clickable="false">
                    <MudListItem>
                        <div class="flex flex-row w-full mx-auto">
                            <MudProgressCircular class="my-auto mr-1 -ml-4" Size="Size.Small" Indeterminate="true" />
                            <p class="font-bold my-1 mx-auto text-md">منتظر بمانید</p>
                        </div>
                    </MudListItem>
                </MudList>
            </ProgressIndicatorInPopoverTemplate>
            <ItemTemplate Context="e">
                <p>@e.Name</p>
            </ItemTemplate>
        </MudAutocomplete>

        <BaseButtonUi IsProcessing="@ViewModel.IsProcessing"
                      Icon="@Icons.Material.TwoTone.Check"
                      @onclick="@ViewModel.SubmitEditAsync"
                      Content="ویرایش پروفایل"
                      Variant="Variant.Filled"
                      Color="Color.Primary" />

        <BaseButtonUi Icon="@Icons.Material.TwoTone.Close"
        @onclick="@ViewModel.LogoutAsync" Content="خروج از حساب کاربری" Variant="Variant.Outlined" Color="Color.Error" />

    </MudStack>
    <div class="bg-gray-300 rounded-md mt-auto py-4 px-6 flex flex-row">
        <p class="my-auto">نسخه برنامه </p>
        <p class="font-extrabold text-lg mr-auto">@ViewModel.Version</p>
    </div>
</BasePageUi>

@code {

    private ProfilePageViewModel ViewModel { get; set; }
    
    protected override async Task OnInitializedAsync()
    {
        ViewModel = new ProfilePageViewModel(UserUtility, RestWrapper, Snackbar, NavigationManager);
        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();

    }

}