@page "/editQuestion/{Id:int}"


<BackButton RedirectionPage="/questions"></BackButton>
<PageTitle>@Localizer["PageTitle"]</PageTitle>
<div class="container text-center">
    <div class="border border-dark p-4 d-inline-block">
        <h3>@Localizer["Title"]</h3>

        <EditForm Model="@question" OnValidSubmit="@HandleValidSubmit">
            <DataAnnotationsValidator />
            <ValidationSummary />
            <div class="row mb-3">
                <div class="col-4 text-end">
                    <label for="content" class="col-form-label">@Localizer["Content"] :</label>
                </div>
                <div class="col-8">
                    <InputText id="content" @bind-Value="question.Content" class="form-control" />
                </div>
            </div>
            <div class="row mb-3">
                <div class="col-4 text-end">
                    <label for="idChapter" class="col-form-label">@Localizer["Chapter"] :</label>
                </div>
                <div class="col-8">
                    <InputSelect id="idChapter" @bind-Value="question.IdChapter" class="form-select">
                        @if (chapters != null)
                        {
                            foreach (var chapter in chapters)
                            {
                                <option value="@chapter.Id">@chapter.Name</option>
                            }
                        }
                    </InputSelect>
                </div>
            </div>

            @foreach (var index in Enumerable.Range(0, answers.Count))
            {
                var answer = answers[index];
                var checkbox = checkboxs[index];

                <div class="row mb-3">
                    <div class="col-4 text-end">
                        <label for="@($"answer{answer.Id}")" class="col-form-label">@Localizer["Answers"]@(index + 1) :</label>
                    </div>
                    <div class="col-5">
                        <InputText id="@($"answer{answer.Id}")" @bind-Value="answer.Content" class="form-control" />
                    </div>
                    <div class="col-3">
                        <label for="@($"checkbox{checkbox.Id}")" class="form-check-label">
                            <input type="radio" name="radio" id="@($"checkbox{checkbox.Id}")" checked="@checkbox.IsCorrect" @onchange="() => SetCorrectAnswer(checkbox.Id)" class="form-check-input" />  @Localizer["Correct"]
                        </label>
                    </div>
                </div>
            }
            <button type="submit" class="btn btn-success">@Localizer["Submit"]</button>
        </EditForm>
    </div>
</div>
