@using DocuMed.Domain.Entities.MedicalHistoryTemplate

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

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

    <MudSelect @bind-Value="@_pdhQuestionType" T="MedicalHistoryQuestionType" ToStringFunc="(e=>e.ToDisplay())" Label="نوع سوال" Variant="Variant.Outlined">

        <MudSelectItem Value="@MedicalHistoryQuestionType.Hourly" />
        <MudSelectItem Value="@MedicalHistoryQuestionType.Interrogatively" />
        <MudSelectItem Value="@MedicalHistoryQuestionType.YesOrNo" />
    </MudSelect>
    <MudTextField @bind-Value="@_pdhQuestionTitle" 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 PshQuestions)
    {
        <MedicalHistoryQuestionTemplateItemTemplate Question="item" QuestionRemoved="RemovePshQuestion" />
    }

    <MudSelect @bind-Value="@_pshQuestionType"
               ToStringFunc="(e=>e.ToDisplay())"
               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
{
    [Parameter]
    public List<MedicalHistoryQuestionSDto> PdhQuestions { get; set; } = new();
    [Parameter]
    public List<MedicalHistoryQuestionSDto> PshQuestions { get; set; } = new();


    private string _pdhQuestionTitle = string.Empty;
    private MedicalHistoryQuestionType _pdhQuestionType;
    private string _pshQuestionTitle = string.Empty;
    private MedicalHistoryQuestionType _pshQuestionType;

    private void RemovePiQuestion(MedicalHistoryQuestionSDto question)
    {
        PdhQuestions.Remove(question);
    }
    private void AddPiQuestion()
    {
        PdhQuestions.Add(new MedicalHistoryQuestionSDto
            {
                QuestionType = _pdhQuestionType,
                Part = MedicalHistoryPart.PastDiseasesHistory,
                Question = _pdhQuestionTitle
            });
        _pdhQuestionTitle = string.Empty;
    }

    private void RemovePshQuestion(MedicalHistoryQuestionSDto question)
    {
        PshQuestions.Remove(question);
    }
    private void AddPshQuestion()
    {
        PshQuestions.Add(new MedicalHistoryQuestionSDto
            {
                Part = MedicalHistoryPart.PastSurgeryHistory,
                QuestionType = _pshQuestionType,
                Question = _pshQuestionTitle
            });
        _pshQuestionTitle = string.Empty;
    }

}