<!--

    Queue - A Queueing system that can be used to handle labs in higher education
    Copyright (C) 2016-2024  Delft University of Technology

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{container}">
    <!--@thymesVar id="filter" type="nl.tudelft.queue.dto.util.RequestTableFilterDTO"-->

    <!--@thymesVar id="editions" type="java.util.List<nl.tudelft.labracore.api.dto.EditionDetailsDTO>"-->
    <!--@thymesVar id="labs" type="java.util.List<nl.tudelft.queue.dto.view.QueueSessionSummaryDTO>"-->
    <!--@thymesVar id="assignments" type="java.util.List<nl.tudelft.labracore.api.dto.AssignmentSummaryDTO>"-->
    <!--@thymesVar id="rooms" type="java.util.List<nl.tudelft.labracore.api.dto.RoomSummaryDTO>"-->
    <!--@thymesVar id="assistants" type="java.util.List<nl.tudelft.labracore.api.dto.PersonSummaryDTO>"-->

    <!--@thymesVar id="requests" type="org.springframework.data.domain.Page<nl.tudelft.queue.dto.view.RequestViewDTO>"-->
    <!--@thymesVar id="requestCounts" type="java.util.Map<java.lang.Long, java.lang.Long>"-->

    <head>
        <title>Requests</title>

        <script th:unless="${#uri.matches('.*/history.*')}" type="text/javascript" src="/js/request_table.js"></script>
        <script type="text/javascript" src="/webjars/handlebars/handlebars.min.js"></script>

        <link rel="stylesheet" type="text/css" href="/css/request_colours.css" />
        <link th:if="${@thymeleafConfig.isTheDay() && @requestTableService.partakes()}" rel="stylesheet" type="text/css" href="/css/stack.css" />
    </head>

    <main layout:fragment="content">
        <div class="flex vertical gap-3 mb-5">
            <h1 class="font-800">Requests</h1>

            <form
                th:if="${@thymeleafConfig.isTheDay() && @requestTableService.partakes()}"
                method="post"
                th:action="@{/requests/ilikemyeyesthankyou}">
                <button type="submit" class="button" data-style="outlined">Unstack me please</button>
            </form>
            <form
                th:if="${@thymeleafConfig.isTheDay() && !@requestTableService.partakes()}"
                method="post"
                th:action="@{/requests/iloveallqueuedevelopers}">
                <button type="submit" class="button" data-style="outlined">Stack me please</button>
            </form>
        </div>

        <div class="tabs mb-5" role="tablist">
            <a role="tab" th:aria-selected="not ${#uri.matches('.*/history.*')}" th:href="@{/requests}">
                <i class="fa fa-question" aria-hidden="true"></i>
                Current requests
            </a>
            <a role="tab" th:aria-selected="${#uri.matches('.*/history.*')}" th:href="@{/requests/history}">
                <i class="fa fa-history" aria-hidden="true"></i>
                History
            </a>
        </div>

        <th:block
            th:replace="~{request/list/filters :: filters (returnPath=${#uri.matches('.*/history.*') ? '/requests/history' : '/requests'}, multipleLabs=${true})}"></th:block>

        <div class="flex gap-3 wrap mb-5" th:unless="${#uri.matches('.*/history.*')}">
            <form th:action="@{/requests/next/{labId}(labId = ${lab.id})}" method="get" th:each="lab : ${labs}">
                <button
                    class="button"
                    th:id="|get-next-${lab.id}|"
                    th:if="${lab.isActiveOrGracePeriod}"
                    th:disabled="${requestCounts.getOrDefault(lab.id, 0) == 0}">
                    <span th:text="${@thymeleafConfig.isTheDay()} ? 'Pop from' : 'Get next for'"></span>
                    <th:block th:text="${lab.name}">Lab name</th:block>
                    <span th:id="|span-${lab.id}|" th:text="|(${requestCounts.getOrDefault(lab.id, 0)})|">(0)</span>
                </button>
            </form>
        </div>

        <div class="flex vertical">
            <th:block
                th:replace="~{request/list/request-table :: request-table(showName=${showName}, showOnlyRelevant=${showOnlyRelevant})}"></th:block>
            <th:block th:replace="~{pagination :: pagination (page=${requests}, size=3)}"></th:block>
        </div>
    </main>
</html>
