@model ResourcesManager.Models.ReservationViewModel

@{
    ViewBag.Title = "Week";
}
<h2>Week</h2>
@Html.Partial("ViewChange", Model.Actual)
<a href="" class="toggle">Show all hours</a>
<h3 class="text-center">
    @Html.ActionLink("< Előző hét", "Week", "Reservations", new { date = Model.Actual.AddDays(-7) }, new { @class = "btn btn-primary btn-sm pull-left" })
    @Model.Actual.Year.ToString() - @Model.Actual.ToString("MMMM")
    @Html.ActionLink("Következő hét >", "Week", "Reservations", new { date = Model.Actual.AddDays(7) }, new { @class = "btn btn-primary btn-sm pull-right" })
</h3>
<table class="reservation-week-table">
    <thead>
        <tr>
            <th></th>
            @for (DateTime i = Model.Start; i < Model.End; i = i.AddDays(1))
            {
                <th class="@(i.Date == DateTime.Today ? "green-bg" : string.Empty)"><a href="@Url.Action("Day", "Reservations", new { day = i.Date })">@i.Date.ToString("M.dd")<br />@i.Date.DayOfWeek</a></th>
            }
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <ul class="list-group">
                    @for (int i = 0; i < 24; i++)
                    {
                        <li class="list-group-item @(i < 7 || i > 20 ? "hidden" : string.Empty)">
                            <p class="week-hour-title">
                                @i:00
                            </p>
                        </li>
                    }
                </ul>
            </td>
            @for (DateTime i = Model.Start; i < Model.End; i = i.AddDays(1))
            {
                <td class="@(i.Date == DateTime.Today ? "green-bg" : string.Empty)">
                    <ul class="list-group">
                        @for (DateTime j = i; j < i.AddDays(1); j = j.AddHours(1))
                        {
                            <li class="list-group-item @(j.Hour < 7 || j.Hour > 20 ? "hidden" : string.Empty)">
                                @foreach (var item in Model.Reservations)
                                {
                                    if (item.Begining.Day == j.Day && item.Begining.Hour == j.Hour)
                                    {
                                        <a href="@Url.Action("Details", new { id = item.Id })" class="resource-link">
                                            <span><small class="time">@item.Begining.ToString("HH")-@item.End.ToString("HH")ó</small> @item.Resource.Name</span>
                                        </a>
                                        <br />
                                    }
                                }
                                <p class="week-hour-title">
                                    @Html.ActionLink("Foglalás", "Create", "Reservations", new { time = j }, new { @class = "create-reservation-link" })
                                </p>
                            </li>
                        }
                    </ul>
                </td>
            }
        </tr>
    </tbody>
</table>
@section Scripts{
    <script src="~/Scripts/reservation.js"></script>
}