@page
@model Quizzer.Pages.QuestionsModel
@Html.AntiForgeryToken()
@{
    ViewData["Title"] = "Quizzer";
    Layout = "_Layout-teacher";
}
<div class="container-fluid">
    <div class="row">
        <div class="col-xl-12" style="background-color: lightgreen">
            <h1><center>Q Management</center></h1>
        </div>
    </div>
    <div class="row">
        <div class="col-xl-12" style="background-color: lemonchiffon">
            <form class="form-horizontal" method="post">
                <input type="hidden" name="action" value="changeCategory" />
                Subject: @Html.Raw(Model.CatMenu)<br /><br />
            </form>
            <form class="form-horizontal" method="post">
                <input type="hidden" name="action" value="changeQText" />
                <label for="qText">Question Text:</label>
                <input id="qText" type="text" class="form-control" placeholder="Enter the question" name="changeTo" value="@Model.questionCookie.QuestionText" style="width:100%" onchange="javascript:this.form.submit()">
            </form>
            <table class="table table-striped" style="width:100%">
                <tr>
                    <th>Correct</th>
                    <th>Text</th>
                </tr>
                @if (Model.questionCookie.AList != null)
                {
                    @for (var indx = 0; indx < Model.questionCookie.AList.Count(); indx++)
                    {
                        <tr>
                            <td>
                                <form class="form-horizontal" method="post">
                                    <input type="hidden" name="action" value="changeAOk" />
                                    <input type="hidden" name="tochange" value="@indx" />
                                    @if (@Model.questionCookie.AList[@indx].Aok)
                                    {
                                        <input type="hidden" name="changeTo" value="off" />
                                        <button type="submit" class="btn btn-outline-success btn-sm" checked onchange="javascript:this.form.submit()"><i class="bi bi-check2-circle"></i></button>
                                        //<input type="checkbox" class="form-check-input" name="changeTo" checked onchange="javascript:this.form.submit()">
                                    }
                                    else
                                    {
                                        <input type="hidden" name="changeTo" value="on" />
                                        <button type="submit" class="btn btn-outline-danger btn-sm" checked onchange="javascript:this.form.submit()"><i class="bi bi-x-circle"></i></button>
                                        //<input type="checkbox" class="form-check-input" name="changeTo" onchange="javascript:this.form.submit()">
                                    }
                                </form>
                            </td>
                            <td>
                                <form class="form-horizontal" method="post">
                                    <input type="hidden" name="action" value="changeAText" />
                                    <input type="hidden" name="tochange" value="@indx" />
                                    <input id="qText" type="text" class="form-control" placeholder="Alternative text" name="changeTo" value="@Model.questionCookie.AList[@indx].Atxt" style="width:100%" onchange="javascript:this.form.submit()">
                                </form>
                            </td>
                        </tr>
                    }
                }
            </table>
            <form class="form-horizontal" method="post">
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        @if (Model.isSubmittable)
                        {
                            <button type="submit" class="btn btn-success" name="action" value="create">Submit</button>
                        }
                        else
                        {
                            <input type="hidden" name="action" value="update" />
                            <button type="submit" class="btn btn-success" name="action" value="create" disabled>Submit</button>
                        }
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-12" style="background-color: lemonchiffon">
            <h3>Scan Question</h3>
            <form asp-page="" method="post">
                <input type="hidden" name="action" value="scan" />
                <label for="q_txt">Question text</label>
                <div class="form-group green-border-focus">
                    <textarea class="form-control" name="tochange" rows="5" id="q_txt" onchange="javascript:this.form.submit()"></textarea>
                </div>
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-12" style="background-color: lemonchiffon">
            <h3>Edit Question</h3>
            <form asp-page="" method="post">
                <input type="hidden" name="action" value="edit" />
                <label for="q_txt">Question text</label>
                <input type="text" name="txt" id="q_txt" size="100%" onchange="javascript:this.form.submit()" />
            </form>
        </div>
    </div>
    @if (Model.questionCookie.Category != null && Model.questionsInCat != null)
    {
        <div class="row">
            <div class="col-12" style="background-color: paleturquoise">
                <table class="table" style="width:100%">
                    <tr>
                        <td>
                            <h5>Questions in selected category : @Model.questionsInCat.Count()</h5>
                        </td>
                        <td>
                            <table class="table" style="width:100%">
                                <thead>
                                <th>AIKEN format</th>
                                <th></th>
                                </thead>
                                <tr>
                                    <td>
                                        Download
                                    </td>
                                    <td>
                                        <form asp-page="" method="post">
                                            <input type="hidden" name="action" value="download" />
                                            <button type="submit" class="btn btn-outline-danger btn-sm" checked onchange="javascript:this.form.submit()"><i class="bi bi-download"></i></button>
                                        </form>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        UpLoad
                                    </td>
                                    <td>
                                        <form method="post" enctype="multipart/form-data">
                                            <input type="hidden" name="action" value="upload" />
                                            <button type="submit" class="btn btn-outline-danger btn-sm" checked onchange="javascript:this.form.submit()"><i class="bi bi-upload"></i></button>
                                            <input type="file" asp-for="Upload" />
                                        </form>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <table class="table table-striped" style="width:100%">
                    <tr>
                        <th>Question</th>
                        <th>Delete</th>
                    </tr>
                    @foreach (var item in Model.mcQuestionsInCat)
                    {
                        <tr>
                            <td>
                                @item.QuestionText
                                @foreach (var altItem in item.AList)
                                {
                                    @if (altItem.Aok)
                                    {
                                        <li style="background-color:lightgreen">@altItem.Atxt</li>
                                    }
                                    else
                                    {
                                        <li>@altItem.Atxt</li>
                                    }
                                }
                            </td>
                            <td>
                                <form asp-page="" method="post">
                                    <input type="hidden" name="action" value="delete" />
                                    <input type="hidden" name="tochange" value="@item.QuestionID" />
                                    <button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
                                </form>
                            </td>
                        </tr>
                    }
                </table>
            </div>
        </div>
    }
    <div class="row">
    </div>
</div>
