@using DocuMed.Domain.Entities.MedicalHistoryTemplate
<MudStack class="pb-20 font-iranyekan">
    <BasePartDivider Index="2" Title="تاریخچه بیماری فعلی ( PI )" />

    <MudAlert Severity="Severity.Info">شما میتوانید سوال های هر بخش ها را به صورت کامل تنظیم نمایید</MudAlert>

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

    <MudSelect @bind-Value="@_questionType" 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="@_questionTitle" Margin="Margin.None" T="string" Label="عنوان سوال" Lines="1"
                  Variant="Variant.Outlined" />

    @* <MudAutocomplete T="string" Label="وابستگی به سوال قبلی" Variant="Variant.Outlined" /> *@

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

</MudStack>


@code
{
    private MedicalHistoryQuestionType _questionType;
    private string _questionTitle = string.Empty;
    private MedicalHistoryPart _questionPart = MedicalHistoryPart.PresentIllness;

    [Parameter]
    public List<MedicalHistoryQuestionSDto> PiQuestions { get; set; } = new();

    private void RemoveQuestion(MedicalHistoryQuestionSDto question)
    {
        PiQuestions.Remove(question);
    }
    private void AddQuestion()
    {
        PiQuestions.Add(new MedicalHistoryQuestionSDto
        {
            Part = _questionPart,
            Question = _questionTitle,
            QuestionType = _questionType
        });
        _questionTitle = string.Empty;
    }
}