
<MudStack class="pb-20 font-iranyekan">
    <BasePartDivider Index="3" Title="تاریخچه بیماری های قبلی ( PMH )" />
    
    @foreach (var question in PdhQuestions)
    {
        <BaseMedicalQuestionTemplate Question="@question" AnswerChanged="PdhAnswerChanged" />
    }

    
    <MudTextField Margin="Margin.Dense" T="string"
                  Value="@PdhDetail" ValueChanged="async piDetail => { PdhDetail = piDetail; await PdhDetailChanged.InvokeAsync(piDetail); }"
                  Label="توضیحاتـــ تکمیلی" Lines="5" Variant="Variant.Outlined"/>

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

    @foreach (var question in PshQuestions)
    {
        <BaseMedicalQuestionTemplate Question="@question" AnswerChanged="PshAnswerChanged" />
    }

    <MudTextField Margin="Margin.Dense"
                  Value="@PshDetail" ValueChanged="async piDetail => { PshDetail = piDetail; await PshDetailChanged.InvokeAsync(piDetail); }"
                  T="string" Label="توضیحاتـــ تکمیلی" Lines="5" Variant="Variant.Outlined"/>

</MudStack>

@code 
{
    [Parameter]
    public List<MedicalHistoryAnswerSDto> PdhAnswers { get; set; } = new();

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

    [Parameter]
    public string PdhDetail { get; set; } = string.Empty;

    [Parameter]
    public EventCallback<string> PdhDetailChanged { get; set; }

    private void PdhAnswerChanged(MedicalHistoryAnswerSDto dto)
    {
        var findAnswer = PdhAnswers.FirstOrDefault(pi => pi.Question == dto.Question && pi.Part == dto.Part);
        if (findAnswer != null)
            findAnswer.Answer = dto.Answer;
        else
            PdhAnswers.Add(dto);
    }

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

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

    [Parameter]
    public string PshDetail { get; set; } = string.Empty;

    [Parameter]
    public EventCallback<string> PshDetailChanged { get; set; }

    private void PshAnswerChanged(MedicalHistoryAnswerSDto dto)
    {
        var findAnswer = PdhAnswers.FirstOrDefault(pi => pi.Question == dto.Question && pi.Part == dto.Part);
        if (findAnswer != null)
            findAnswer.Answer = dto.Answer;
        else
            PdhAnswers.Add(dto);
    }
}