<MudStack class="pb-20 font-iranyekan">
    <BasePartDivider Index="8" Title="ظاهر کلی بیمار ( GA )" />
    <div class="grid mx-1 gap-2 grid-cols-1 md:grid-cols-2">
        @foreach (var item in GeneralAppearance)
        {
            <MudCard @onclick="()=>RemoveGeneralAppearance(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="@_generalAppearance" class="grow" T="string" Label="عنوان بررسی مورد نظر" Variant="Variant.Outlined" />

        <MudButton Variant="Variant.Outlined" @onclick="AddGeneralAppearance" 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 class="mt-9" Index="9" Title="مرور سیستماتیک ( ROS )" />
    @foreach (var item in ReviewOfSystems)
    {
        <MudPaper class="px-3 py-2 mx-1">

            <div class="flex flex-row">
                <div>
                    <p>@item.Question</p>
                    <div class="flex flex-row">
                        <MudPaper Elevation="0" Class="mx-1 mt-1 bg-gray-200 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                            @item.BodySystem.ToDisplay()
                        </MudPaper>
                        @if(@item.IsSign)
                        {
                            <MudPaper Elevation="0" Class="mx-1 mt-1 bg-gray-200 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                                Sign
                            </MudPaper>
                        }
                        @if (@item.IsSymptom)
                        {
                            <MudPaper Elevation="0" Class="mx-1 mt-1 bg-gray-200 w-fit text-center rounded-full py-0.5 px-3 text-gray-800 text-xs">
                                Symptom
                            </MudPaper>
                        }
                    </div>
                </div>
                <MudIconButton @onclick="()=>RemoveReviewOfSystems(item)" class="mr-auto" Color="Color.Error" Icon="@Icons.Material.Filled.Close" />
            </div>
        </MudPaper>
    }

    <MudTextField @bind-Value="@_reviewOfSystemTitle" class="grow" T="string" Label="علامت مورد نظر" Variant="Variant.Outlined" />

    <MudSelect @bind-Value="@_reviewOfSystemName" T="BodySystem" ToStringFunc="(e=>e.ToDisplay())" Label="سیستم مورد نظر" Variant="Variant.Outlined">
        
        <MudSelectItem Value="@BodySystem.Chest" />
        <MudSelectItem Value="@BodySystem.Ear" />
        <MudSelectItem Value="@BodySystem.Extremities" />
        <MudSelectItem Value="@BodySystem.Eyes" />
        <MudSelectItem Value="@BodySystem.GenitalOrganFemale" />
        <MudSelectItem Value="@BodySystem.GenitalOrganMale" />
        <MudSelectItem Value="@BodySystem.Heart" />
        <MudSelectItem Value="@BodySystem.Lung" />
        <MudSelectItem Value="@BodySystem.LymphaticGlands" />
        <MudSelectItem Value="@BodySystem.Mouth" />
        <MudSelectItem Value="@BodySystem.Neck" />
        <MudSelectItem Value="@BodySystem.Nose" />
        <MudSelectItem Value="@BodySystem.Extremities" />
        <MudSelectItem Value="@BodySystem.NervousSystem" />
        <MudSelectItem Value="@BodySystem.Rectum" />
        <MudSelectItem Value="@BodySystem.Skin" />
        <MudSelectItem Value="@BodySystem.Skull" />
        <MudSelectItem Value="@BodySystem.Throat" />
        <MudSelectItem Value="@BodySystem.Vessels" />
        <MudSelectItem Value="@BodySystem.Abdomen" />
        <MudSelectItem Value="@BodySystem.BoneJointsMuscles" />
    </MudSelect>

    <div class="flex flex-row">

        <MudCheckBox @bind-Checked="@_reviewOfSystemIsSign" Color="Color.Primary" UnCheckedColor="Color.Default" Size="Size.Large" T="bool"
                     class="my-auto" Label="Sign"></MudCheckBox>

        <MudCheckBox @bind-Checked="@_reviewOfSystemIsSymptom" Color="Color.Primary" UnCheckedColor="Color.Default" Size="Size.Large" T="bool"
                     class="my-auto" Label="Symptom"></MudCheckBox>

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


</MudStack>
@code {

    private string _generalAppearance = string.Empty;
    [Parameter]
    public List<MedicalHistoryQuestionSDto> GeneralAppearance { get; set; } = new();

    private void RemoveGeneralAppearance(MedicalHistoryQuestionSDto generalAppearance)
    {
        GeneralAppearance.Remove(generalAppearance);
    }
    private void AddGeneralAppearance()
    {
        GeneralAppearance.Add(new MedicalHistoryQuestionSDto
        {
            Question = _generalAppearance,
            QuestionType = MedicalHistoryQuestionType.Selective,
            Part = MedicalHistoryPart.GeneralAppearance
        });
        _generalAppearance = string.Empty;
    }


    private string _reviewOfSystemTitle = string.Empty;
    private BodySystem _reviewOfSystemName;
    private bool _reviewOfSystemIsSign;
    private bool _reviewOfSystemIsSymptom;

    [Parameter]
    public List<MedicalHistoryQuestionSDto> ReviewOfSystems { get; set; } = new();
    private void RemoveReviewOfSystems(MedicalHistoryQuestionSDto review)
    {
        ReviewOfSystems.Remove(review);
    }
    private void AddReviewOfSystems()
    {
        ReviewOfSystems.Add(new MedicalHistoryQuestionSDto
            {
                Question = _reviewOfSystemTitle,
                IsSign = _reviewOfSystemIsSign,
                IsSymptom = _reviewOfSystemIsSymptom,
                BodySystem = _reviewOfSystemName,
                QuestionType = MedicalHistoryQuestionType.RosSelective,
                Part = MedicalHistoryPart.ReviewOfSystem
            });
        _reviewOfSystemTitle = string.Empty;
    }
}