@if (_isSelected)
{
    <MudCard @onclick="SelectChanged" class="text-center bg-[--color-medicalhistory]">
        <MudCardContent>
            <div class="flex flex-row">
                <p class="flex-grow font-extrabold text-gray-600 text-md">@Question</p>
                <MudPaper Elevation="0" Class="mx-1 mt-1 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                    @BodySystem.ToDisplay()
                </MudPaper>
                @if (IsSign)
                {
                    <MudPaper Elevation="0" Class="mx-1 mt-1 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                        Sign
                    </MudPaper>
                }
                @if (IsSymptom)
                {
                    <MudPaper Elevation="0" Class="mx-1 mt-1 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                        Symptom
                    </MudPaper>
                }
            </div>
        </MudCardContent>
    </MudCard>
}
else
{
    <MudCard @onclick="SelectChanged" class="text-center">
        <MudCardContent>
            <div class="flex flex-row">
                <p class="flex-grow font-extrabold text-gray-600 text-md">@Question</p>
                <MudPaper Elevation="0" Class="mx-1 mt-1 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                    @BodySystem.ToDisplay()
                </MudPaper>
                @if (IsSign)
                {
                    <MudPaper Elevation="0" Class="mx-1 mt-1 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                        Sign
                    </MudPaper>
                }
                @if (IsSymptom)
                {
                    <MudPaper Elevation="0" Class="mx-1 mt-1 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                        Symptom
                    </MudPaper>
                }
            </div>
        </MudCardContent>
    </MudCard>
}

@code
{

    public override async Task SetParametersAsync(ParameterView parameters)
    {
        await base.SetParametersAsync(parameters);
        if (!OldAnswer.IsNullOrEmpty())
        {
            if(Answer == OldAnswer)
                return;
            _isSelected = OldAnswer != Question;
            await SelectChanged();
        }
    }

    [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;

    [Parameter]
    public BodySystem BodySystem { get; set; }

    [Parameter]
    public bool IsSign { get; set; }

    [Parameter]
    public bool IsSymptom { get; set; }

    private bool _isSelected = false;

    private async Task SelectChanged()
    {
        _isSelected = !_isSelected;

        Answer = _isSelected ? Question : string.Empty;

        await AnswerChanged.InvokeAsync(Answer);
    }
}