
<MudStack class="pb-20 font-iranyekan">
    <BasePartDivider Index="3" Title="تاریخچه بیماری قبلی ( PI )" />

    @foreach (var item in PIQuestions)
    {
        <MedicalHistoryQuestionTemplateItemTemplate Question="item" QuestionRemoved="RemovePIQuestion" />
    }

    <MudSelect @bind-Value="@_piQuestionType" T="MedicalHistoryQuestionType" Label="نوع سوال" Variant="Variant.Outlined">

        <MudSelectItem Value="@MedicalHistoryQuestionType.Hourly" />
        <MudSelectItem Value="@MedicalHistoryQuestionType.Interrogatively" />
        <MudSelectItem Value="@MedicalHistoryQuestionType.YesOrNo" />
    </MudSelect>
    <MudTextField @bind-Value="@_piQuestionTitle" Margin="Margin.None" T="string" Label="عنوان سوال" Lines="1"
                  Variant="Variant.Outlined" />

    <MudButton @onclick="AddPIQuestion" Variant="Variant.Filled" IconSize="Size.Large" DisableElevation="true"
               class="font-extrabold text-lg rounded-md py-4 bg-[--color-medicalhistory] text-gray-800">
        + افزودن
    </MudButton>

    <BasePartDivider Index="4" class="mt-9" Title="تاریخچه جراحی های قبلی ( PSH )" />

    @foreach (var item in PIQuestions)
    {
        <MedicalHistoryQuestionTemplateItemTemplate Question="item" QuestionRemoved="RemovePSHQuestion" />
    }

    <MudSelect @bind-Value="@_pshQuestionType" 
               T="MedicalHistoryQuestionType" 
               Label="نوع سوال" 
               Variant="Variant.Outlined">

        <MudSelectItem Value="@MedicalHistoryQuestionType.Hourly" />
        <MudSelectItem Value="@MedicalHistoryQuestionType.Interrogatively" />
        <MudSelectItem Value="@MedicalHistoryQuestionType.YesOrNo" />
    </MudSelect>
    <MudTextField @bind-Value="@_pshQuestionTitle" 
                  Margin="Margin.None" 
                  T="string" 
                  Label="عنوان سوال" Lines="1"
                  Variant="Variant.Outlined" />

    <MudButton @onclick="AddPSHQuestion" Variant="Variant.Filled" IconSize="Size.Large" DisableElevation="true"
               class="font-extrabold text-lg rounded-md py-4 bg-[--color-medicalhistory] text-gray-800">
        + افزودن
    </MudButton>


</MudStack>

@code
{
    private string _piQuestionTitle = string.Empty;
    private MedicalHistoryQuestionType _piQuestionType;
    private string _pshQuestionTitle = string.Empty;
    private MedicalHistoryQuestionType _pshQuestionType;
    public List<MedicalHistoryQuestion> PIQuestions { get; set; } = new();
    public List<MedicalHistoryQuestion> PSHQuestions { get; set; } = new();

    private void RemovePIQuestion(MedicalHistoryQuestion question)
    {
        PIQuestions.Remove(question);
    }
    private void AddPIQuestion()
    {
        PIQuestions.Add(new MedicalHistoryQuestion
            {
                Title = _piQuestionTitle,
                Type = _piQuestionType
            });
    }

    private void RemovePSHQuestion(MedicalHistoryQuestion question)
    {
        PSHQuestions.Remove(question);
    }
    private void AddPSHQuestion()
    {
        PSHQuestions.Add(new MedicalHistoryQuestion
            {
                Title = _pshQuestionTitle,
                Type = _pshQuestionType
            });
    }

}