@using DocuMed.Domain.Entities.MedicalHistoryTemplate
<MudStack class="pb-20 font-iranyekan">
    <BasePartDivider Index="5" Title="تاریخچه بیماری های خانوادگی ( FH )" />

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

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

    <MudButton @onclick="AddFamilyHistory" 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="6" class="mt-9" Title="داروهای مصرفی ( DH )" />
    
    <div class="grid mx-1 gap-2 grid-cols-2 md:grid-cols-4">
        @foreach (var item in DrugHistories)
        {
            <MudCard @onclick="()=>RemoveDrugHistory(item)" class="text-center">
                <MudCardContent>
                    <p class="font-extrabold text-gray-600 text-md">@item.Question</p>
                </MudCardContent>
            </MudCard>
        }
    </div>

    <div class="flex flex-row">
        <MudTextField @bind-Value="@_drugHistoryName" class="grow" T="string" Label="نام دارو مورد نظر" Variant="Variant.Outlined" />

        <MudButton Variant="Variant.Outlined" @onclick="AddDrugHistory" Color="Color.Info" IconSize="Size.Large" DisableElevation="false" class="mx-2 mt-1.5 mb-0.5 pt-2 text-4xl rounded-md">
            +
        </MudButton>
    </div>

    <BasePartDivider Index="7" class="mt-9" Title="مواد مصرفی ( HH )" />

    <div class="grid mx-1 gap-2 grid-cols-2 md:grid-cols-4">
        @foreach (var item in AhMedicines)
        {
            <MudCard @onclick="()=>RemoveHhMedicine(item)" class="text-center">
                <MudCardContent>
                    <p class="font-extrabold text-gray-600 text-md">@item.Question</p>
                </MudCardContent>
            </MudCard>
        }
    </div>

    <div class="flex flex-row">
        <MudTextField @bind-Value="@_hhName" class="grow" T="string" Label="نام دارو مورد نظر" Variant="Variant.Outlined" />

        <MudButton Variant="Variant.Outlined" @onclick="AddHhMedicine" Color="Color.Info" IconSize="Size.Large" DisableElevation="false" class="mx-2 mt-1.5 mb-0.5 pt-2 text-4xl rounded-md">
            +
        </MudButton>
    </div>



</MudStack>
@code {
    private string _familyHistoryQuestionTitle = string.Empty;
    private MedicalHistoryQuestionType _familyHistoryQuestionType;
    [Parameter]
    public List<MedicalHistoryQuestionSDto> FamilyHistories { get; set; } = new();
    private void RemoveFamilyHistory(MedicalHistoryQuestionSDto question)
    {
        FamilyHistories.Remove(question);
    }
    private void AddFamilyHistory()
    {
        FamilyHistories.Add(new MedicalHistoryQuestionSDto
        {
            Question = _familyHistoryQuestionTitle,
            QuestionType = _familyHistoryQuestionType,
            Part = MedicalHistoryPart.FamilyHistory
        });
        _familyHistoryQuestionTitle = String.Empty;
    }


    private string _drugHistoryName = string.Empty;
    [Parameter]
    public List<MedicalHistoryQuestionSDto> DrugHistories { get; set; } = new();
    private void RemoveDrugHistory(MedicalHistoryQuestionSDto medicine)
    {
        DrugHistories.Remove(medicine);
    }
    private void AddDrugHistory()
    {
        DrugHistories.Add(new MedicalHistoryQuestionSDto
        {
            Question = _drugHistoryName,
            QuestionType = MedicalHistoryQuestionType.Selective,
            Part = MedicalHistoryPart.DrugHistory
        });
        _drugHistoryName = string.Empty;
    }


    private string _hhName = string.Empty;
    [Parameter]
    public List<MedicalHistoryQuestionSDto> AhMedicines { get; set; } = new();
    private void RemoveHhMedicine(MedicalHistoryQuestionSDto medicine)
    {
        AhMedicines.Remove(medicine);
    }
    private void AddHhMedicine()
    {
        AhMedicines.Add(new MedicalHistoryQuestionSDto
        {
            Part = MedicalHistoryPart.AddictionHistory,
            Question = _hhName,
            QuestionType = MedicalHistoryQuestionType.Selective
        });
        _hhName = string.Empty;
    }
}