@page
@model Quizzer.Pages.CoverageModel
@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>Quiz Coverage</center></h1>
        </div>
    </div>
    <div class="row">
        <div class="col-xl-12">
            <form class="form-horizontal" method="post">
                <input type="hidden" name="action" value="selectClass" />
                <select id="selectedClass" name="selectedClass" onchange="javascript:this.form.submit()">
                    <option>Select Class</option>
                    @foreach (var item in @Model.theClasses)
                    {
                        <option value="@item">@item</option>
                    }
                </select>
            </form>
        </div>
    </div>
    @if (Model.currentClass != "" && Model.registrations.Count > 0)
    {
        <div class="row">
            <div class="col-xl-12">
                <h3>@Model.registrations[0].TheClass</h3>
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">Name</th>
                            @for (var counter = 0; counter < Model.dates.Count(); counter++)
                            {
                                <th scope="col">@(counter + 1)</th>
                            }
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var student in Model.persons)
                        {
                            <tr>
                                <td>@student.Name</td>
                                @foreach (var theDate in Model.dates)
                                {
                                    var res = Model.registrations.Where(x => x.Name == student.Name && x.Date == theDate);
                                    @if (res.Count() == 0)
                                    {
                                        <td>-</td>
                                    }
                                    else
                                    {
                                        <td>+</td>
                                    }
                                }
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="col-xl-12">
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">#</th>
                            <th scope="col">Date</th>
                            <th scope="col">Attendees</th>
                        </tr>
                    </thead>
                    <tbody>
                        @for (var index = 0; index < Model.dates.Count(); index++)
                        {
                            <tr>
                                <td>@(index + 1)</td>
                                <td>@Model.dates[index]</td>
                                <td>@Model.registrations.Where(x => x.Date == Model.dates[index]).Count()</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    }
    @if (Model.currentClass != "" && Model.registrations.Count == 0)
    {
        <div class="row">
            <div class="col-xl-12">
                <h5>No registrations</h5>
            </div>
        </div>
    }
</div>