@page "/MedicalHistoryActionPage"
@page "/MedicalHistoryActionPage/{MedicalHistoryId}"
@inject NavigationManager NavigationManager
@inject IRestWrapper RestWrapper
@inject ISnackbar Snackbar
@inject IUserUtility UserUtility
@inject IDialogService DialogService
@inject IJSRuntime JsRuntime

<BasePageUi Title="افزودن یک شرحال جدید" Description="لطفا اطلاعات بیمار را با دقت کامل وارد کنید">

    <div class="flex flex-col w-full h-full rounded-t-xl p-2">

        <MudCarousel class="flex-grow w-full h-full overflow-x-hidden overflow-y-scroll" @ref="@ViewModel.Carousel" ShowArrows="false"
                     ShowBullets="false" EnableSwipeGesture="false" AutoCycle="false" TData="object">

            <MudCarouselItem>
                <div class="flex flex-col w-full h-full p-4">
                    <MedicalHistoryActionStep1 @bind-ChiefComplaint="@ViewModel.PageDto.ChiefComplaint"
                                               DeleteClicked="@ViewModel.DeleteMedicalHistoryAsync"
                                               IsEditing="@ViewModel.IsEditing"
                    @bind-SelectedTemplate="@ViewModel.SelectedTemplate"
                    @bind-SelectedSection="@ViewModel.SelectedSelection"
                    @bind-PatientAge="@ViewModel.PageDto.Age"
                    @bind-PatientFirstName="@ViewModel.PageDto.FirstName"
                    @bind-PatientLastName="@ViewModel.PageDto.LastName" />
                </div>
            </MudCarouselItem>
            <MudCarouselItem>
                <div class="flex flex-col h-full p-4">
                    <MedicalHistoryActionStep2 PiQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.PresentIllness).ToList()"
                    @bind-PiDetail="@ViewModel.PageDto.PresentIllnessDetail"
                                               PiAnswers="@ViewModel.PiAnswers" />
                </div>
            </MudCarouselItem>
            <MudCarouselItem>
                <div class="flex flex-col h-full p-4">
                    <MedicalHistoryActionStep3 PdhQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.PastDiseasesHistory).ToList()"
                                               PdhAnswers="@ViewModel.PdhAnswers"
                    @bind-PdhDetail="@ViewModel.PageDto.PastDiseasesHistoryDetail"
                                               PshAnswers="@ViewModel.PshAnswers"
                                               PshQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.PastSurgeryHistory).ToList()"
                    @bind-PshDetail="@ViewModel.PageDto.PastSurgeryHistoryDetail" />
                </div>
            </MudCarouselItem>
            <MudCarouselItem>
                <div class="flex flex-col h-full p-4">
                    <MedicalHistoryActionStep4 DhQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.DrugHistory).ToList()"
                                               DhAnswers="@ViewModel.DhAnswers"
                    @bind-DhDetail="@ViewModel.PageDto.DrugHistoryDetail"
                                               FhQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.FamilyHistory).ToList()"
                                               FhAnswers="@ViewModel.FhAnswers"
                    @bind-FhDetail="@ViewModel.PageDto.FamilyHistoryDetail"
                                               HhQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.AddictionHistory).ToList()"
                                               HhAnswers="@ViewModel.HhAnswers"
                    @bind-HhDetail="@ViewModel.PageDto.AddictionHistoryDetail" />
                </div>
            </MudCarouselItem>
            <MudCarouselItem>
                <div class="flex flex-col h-full p-4">
                    <MedicalHistoryActionStep5 GaQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.GeneralAppearance).ToList()"
                                               GaAnswers="@ViewModel.GaAnswers"
                                               RosQuestions="@ViewModel.SelectedTemplateLDto.Questions.Where(q=>q.Part==MedicalHistoryPart.ReviewOfSystem).ToList()"
                                               RosAnswers="@ViewModel.RosAnswers"
                    @bind-DiastolicBloodPressure="@ViewModel.PageDto.DiastolicBloodPressure"
                    @bind-PulseRate="@ViewModel.PageDto.PulseRate"
                    @bind-SPO2="@ViewModel.PageDto.SPO2"
                    @bind-SystolicBloodPressure="@ViewModel.PageDto.SystolicBloodPressure"
                    @bind-Temperature="@ViewModel.PageDto.Temperature"
                    @bind-GaDetail="@ViewModel.PageDto.GeneralAppearanceDetail"
                    @bind-RosDetail="@ViewModel.PageDto.SystemReviewDetail" />
                </div>
            </MudCarouselItem>
            <MudCarouselItem>
                <div class="flex flex-col h-full p-4">
                    <MedicalHistoryActionStep6 SubmittedOnClick="@ViewModel.CompleteCreateMedicalHistory" />
                </div>
            </MudCarouselItem>
        </MudCarousel>

        @if (!@ViewModel.MedicalHistorySubmitted)
        {
            <MudPaper class="basis-auto bottom-0 left-0 fixed w-full bg-[--color-medicalhistory] px-3 pt-4 pb-3 rounded-t-xl flex flex-row">

                @if (@ViewModel.CurrentStep == 4)
                {
                    @if (@ViewModel.IsEditing)
                    {
                        <MudButton @onclick="@ViewModel.CompleteStepClicked" Variant="Variant.Filled"
                                   IconSize="Size.Large" StartIcon="@Icons.Material.Filled.ChevronRight"
                                   class="font-extrabold rounded-full text-white bg-[--color-primary]">ویرایش</MudButton>
                    }
                    else
                    {
                        <MudButton @onclick="@ViewModel.CompleteStepClicked" Variant="Variant.Filled"
                                   IconSize="Size.Large" StartIcon="@Icons.Material.Filled.ChevronRight"
                                   class="font-extrabold rounded-full bg-[--color-primary]">تـــکمیل</MudButton>
                    }
                }
                else
                {
                    <MudButton @onclick="@ViewModel.CompleteStepClicked" Variant="Variant.Outlined" IconSize="Size.Large"
                               StartIcon="@Icons.Material.Filled.ChevronRight" class="font-extrabold rounded-full">
                        مرحله بعد
                    </MudButton>
                }

                <p class="my-auto text-lg font-extrabold text-center grow">@ViewModel.StepCounter</p>
                <MudButton @onclick="@ViewModel.RollBackStepClicked" Disabled="@ViewModel.DisableBackButton" IconSize="Size.Large" EndIcon="@Icons.Material.Filled.ChevronLeft"
                           class="font-extrabold rounded-full">مرحله قبل</MudButton>
            </MudPaper>
        }
    </div>
</BasePageUi>

@code {

    [Parameter]
    public string MedicalHistoryId { get; set; } = string.Empty;
    public MedicalHistoryActionPageViewModel ViewModel { get; set; }
    protected override async Task OnInitializedAsync()
    {
        ViewModel = Guid.TryParse(MedicalHistoryId, out Guid medicalHistoryId) ?
            new MedicalHistoryActionPageViewModel(RestWrapper, NavigationManager, Snackbar, UserUtility, DialogService,JsRuntime, medicalHistoryId)
            : new MedicalHistoryActionPageViewModel(RestWrapper, NavigationManager, Snackbar, UserUtility);

        await ViewModel.InitializeAsync();
        await base.OnInitializedAsync();
    }

}