﻿@model IndexViewModel

@addTagHelper *, Starkit

<input type="hidden" id="modelState" value="@Model.BookingTablesFilterViewModel.SelectedItem">
<input type="hidden" id="modelName" value="@Model.BookingTablesFilterViewModel.SelectedName">
<input type="hidden" id="modelSort" value="@Model.SortViewModel.Current">
<input type="hidden" id="modelPage" value="@Model.PageViewModel.PageNumber">

<div style="overflow-x:auto; font-size: 14px">
    <table class="table table-bordered">
        <thead>
        <tr>
            <th></th>
            <th style="vertical-align: middle; text-align: center" scope="col">Номер стола</th>
            <th style="vertical-align: middle; text-align: center" scope="col">
                Дата и время
                <a style="cursor: pointer" id="@Model.SortViewModel.DateSort" class="dateSort" onclick="dateSort('')">
                    <img src="https://img.icons8.com/material-sharp/24/000000/sort.png"/>
                </a>
            </th>
            <th style="vertical-align: middle; text-align: center" scope="col">
                Кол-во гостей
                <a style="cursor: pointer" id="@Model.SortViewModel.PaxSort" class="paxSort" onclick="paxSort('')">
                    <img src="https://img.icons8.com/material-sharp/24/000000/sort.png"/>
                </a>
            </th>
            <th style="vertical-align: middle; text-align: center" scope="col">Статус</th>
            <th style="vertical-align: middle; text-align: center" scope="col">Действие</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var booking in Model.Bookings)
        {
            <tr id="booking-@booking.Id">
                <td id="checkbox-td" style="vertical-align: middle; text-align: center">
                    <input type="checkbox" value="true" id="@booking.Id">
                </td>
                <td style="vertical-align: middle; text-align: center">
                    @foreach (var t in booking.BookingTables)
                    {
                        @t.TableId<br>
                    }
                </td>
                <td class="link-dish-name" style="vertical-align: middle; text-align: center" onclick="detailsBooking('@booking.Id')"> @booking.Date @booking.BookFrom - @booking.BookTo</td>
                <td style="vertical-align: middle; text-align: center">@booking.Pax</td>
                <td style="vertical-align: middle ; text-align: center" onchange="changeState('@booking.Id')">
                    
                    <select name="state" id="state-@booking.Id">
                        @foreach (var s in Enum.GetValues(typeof(BookingStatus)))
                        {
                            if (s.ToString() == booking.State.ToString())
                            {
                                <option class="stateValue" selected value="@s">@GetEnumDescription.GetBookingStateDescription(s.ToString())</option>
                            }
                            else
                            {
                                <option class="stateValue" value="@s">@GetEnumDescription.GetBookingStateDescription(s.ToString())</option>
                            }
                        }
                    </select>
                </td>
                <td style="vertical-align: middle; text-align: center">
                    <a style="margin-bottom: 10px" asp-action="Edit" asp-controller="Booking" asp-route-id="@booking.Id">
                        <img src="https://img.icons8.com/ios-glyphs/24/000000/edit.png"/>
                    </a>
                </td>
            </tr>
        }
        </tbody>
    </table>
</div>
<div id="modal-window"></div>

<div>
<ul class="pagination">
    <li class="page-item">
        <a class="page-link" href="#@(Model.PageViewModel.PageNumber - 1)" aria-label="Previous"
           onclick="previousPage('@(Model.PageViewModel.PageNumber - 1)',
                                    '@(Model.BookingTablesFilterViewModel.SelectedName)',
                                    '@(Model.BookingTablesFilterViewModel.SelectedItem)',
                                    '@(Model.SortViewModel.Current)')"><span aria-hidden="true">&laquo;</span></a>
    </li>
    @for (int itmp = 1; itmp < Model.PageViewModel.TotalPages + 1; itmp++)
    {
        @if (Model.PageViewModel.PageNumber == itmp)
        {
            <li class="page-item active">
                <a class="page-link" href="#@itmp" id="page@itmp"
                   onclick="clickedPage(
                       '@itmp',
                       '@(Model.BookingTablesFilterViewModel.SelectedName)',
                       '@(Model.BookingTablesFilterViewModel.SelectedItem)',
                       '@(Model.SortViewModel.Current)')">@itmp.ToString()</a>
            </li>
        }
        else
        {
            <li class="page-item">
                <a class="page-link" href="#@itmp" id="page@itmp"
                   onclick="clickedPage(
                   '@itmp',
                   '@(Model.BookingTablesFilterViewModel.SelectedName)',
                   '@(Model.BookingTablesFilterViewModel.SelectedItem)',
                   '@(Model.SortViewModel.Current)')">@itmp.ToString()</a>
            </li>
        }
    }
    <li class="page-item">
        <a class="page-link" href="#@(Model.PageViewModel.PageNumber + 1)" aria-label="Next"
           onclick="nextPage('@(Model.PageViewModel.PageNumber + 1)',
                           '@(Model.BookingTablesFilterViewModel.SelectedName)',
                           '@(Model.BookingTablesFilterViewModel.SelectedItem)',
                           '@(Model.SortViewModel.Current)')"><span aria-hidden="true">&raquo;</span></a>
    </li>
</ul>
</div>

