<div class="flex flex-row mt-2">
    <p class="ml-3 font-bold text-justify my-auto grow">@Question</p>
    <div class="flex flex-row">
        @if (_isYesSelected)
        {
            
            <MudIconButton @onclick="async () => await Yes()"
                           DisableElevation="true"
                           Class="bg-[--color-medicalhistory] rounded-full mx-3"
                           Icon="@Icons.Material.Filled.Check"
                           Variant="Variant.Filled"/>
        }
        else
        {
            
            <MudIconButton @onclick="async () => await Yes()"
                           DisableElevation="true"
                           Class="bg-white rounded-full mx-3"
                           Icon="@Icons.Material.Filled.Check"
                           Variant="Variant.Filled"/>
        }
        @if (_isNoSelected)
        {

            <MudIconButton @onclick="async () => await No()"
                           DisableElevation="true"
                           class="bg-[--color-medicalhistory] rounded-full"
                           Icon="@Icons.Material.Filled.Close"
                           Variant="Variant.Filled"/>
        }
        else
        {
            <MudIconButton @onclick="async () => await No()"
                           DisableElevation="true"
                           class="bg-white rounded-full"
                           Icon="@Icons.Material.Filled.Close"
                           Variant="Variant.Filled"/>
        }
    </div>
</div>


@code 
{
    
    public override async Task SetParametersAsync(ParameterView parameters)
    {
        await base.SetParametersAsync(parameters);

        if (!OldAnswer.IsNullOrEmpty())
        {
            if(Answer == OldAnswer)
                return;
            if (OldAnswer == "بله")
            {
                Answer = "بله";
                _isNoSelected = false;
                _isYesSelected = true;
            }
            else if (OldAnswer == "خیر")
            {
                Answer = "خیر";
                _isNoSelected = true;
                _isYesSelected = false;
            }
            await AnswerChanged.InvokeAsync(Answer);
        }
    }

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

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

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

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

    private bool _isYesSelected = false;
    private bool _isNoSelected = false;

    private async Task Yes()
    {
        Answer = "بله";
        _isNoSelected = false;
        _isYesSelected = true;
        await AnswerChanged.InvokeAsync(Answer);
    }

    private async Task No()
    {
        Answer = "خیر";
        _isNoSelected = true;
        _isYesSelected = false;
        await AnswerChanged.InvokeAsync(Answer);
    }
}
