<!--

    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="~{edition/view}">
    <!--@thymesVar id="#authenticatedP" type="nl.tudelft.labracore.api.dto.Person"-->

    <!--@thymesVar id="edition" type="nl.tudelft.labracore.api.dto.EditionDetailsDTO"-->

    <!--@thymesVar id="qSession" type="nl.tudelft.queue.dto.view.QueueSessionViewDTO"-->

    <!--@thymesVar id="rooms" type="java.util.List<nl.tudelft.labracore.api.dto.RoomSummaryDTO>"-->
    <!--@thymesVar id="assignments" type="java.util.List<nl.tudelft.labracore.api.dto.AssignmentSummaryDTO>"-->
    <!--@thymesVar id="modules" type="java.util.List<nl.tudelft.labracore.api.dto.ModuleDetailsDTO>"-->

    <!--@thymesVar id="requests" type="java.util.List<nl.tudelft.queue.dto.view.RequestViewDTO>"-->

    <!--@thymesVar id="current" type="nl.tudelft.queue.dto.view.RequestViewDTO"-->
    <!--@thymesVar id="currentDto" type="nl.tudelft.queue.dto.patch.RequestPatchDTO"-->

    <!--@thymesVar id="types" type="java.util.Map<java.lang.Long, java.util.Set<java.lang.String>>"-->

    <head>
        <title th:text="|Session ${qSession.id}|"></title>

        <link rel="stylesheet" href="/css/request_colours.css" />

        <script th:inline="javascript" type="text/javascript">
            //<![CDATA[
            const labId = /*[[${qSession.id}]]*/ -1;
            //]]>
        </script>
        <script type="text/javascript" src="/js/lab_view.js"></script>
    </head>

    <body>
        <section layout:fragment="subcontent">
            <div class="flex space-between align-center mb-5 | md:vertical md:align-start">
                <h3 class="font-600" th:text="'Session #' + ${qSession.id} + ': ' + ${qSession.session.name}"></h3>

                <div class="flex gap-3 wrap">
                    <th:block th:if="${current == null && @permissionService.canEnqueueSelf(qSession.id)}">
                        <a
                            th:href="@{/lab/{id}/enqueue(id=${qSession.id})}"
                            class="button"
                            th:classappend="${!@permissionService.canEnqueueSelfNow(qSession.id)} ? 'disabled'"
                            th:disabled="${!@permissionService.canEnqueueSelfNow(qSession.id)}">
                            Enqueue
                        </a>
                    </th:block>

                    <th:block th:if="${@permissionService.canManageSession(qSession.data)}">
                        <a class="button" data-style="outlined" th:href="@{/lab/{id}/status(id=${qSession.id})}">Lab Statistics</a>
                        <a class="button" data-style="outlined" target="_blank" th:href="@{/present/{id}(id=${qSession.id})}">Present</a>
                        <a class="button" data-style="outlined" th:href="@{/lab/{id}/export(id=${qSession.id})}" download>Export lab</a>

                        <a class="button" data-style="outlined" th:href="@{/lab/{id}/presentation/edit(id=${qSession.id})}">Edit presentation</a>
                        <a th:href="@{/lab/{id}/edit(id=${qSession.id})}" class="button" data-style="outlined">Edit session</a>

                        <form th:action="@{/lab/{id}/close-enqueue/{bool}(id=${qSession.id}, bool=${!qSession.enqueueClosed})}" method="post">
                            <button th:unless="${qSession.enqueueClosed}" class="button" data-style="outlined" data-type="error" type="submit">
                                Close enqueueing
                            </button>
                            <button th:if="${qSession.enqueueClosed}" class="button" data-style="outlined" data-type="accept" type="submit">
                                Open enqueueing
                            </button>
                        </form>
                    </th:block>
                </div>
            </div>

            <div class="flex vertical">
                <th:block th:replace="~{lab/view/components/selection-result :: selection-result}"></th:block>

                <th:block th:if="${current != null}">
                    <th:block th:replace="~{lab/view/components/current-request :: current-request}"></th:block>

                    <th:block layout:fragment="current-request-edit">
                        <th:block th:replace="~{lab/view/components/current-request-edit :: current-request-edit}"></th:block>
                    </th:block>
                </th:block>

                <th:block layout:fragment="session-info"></th:block>

                <th:block layout:fragment="request-table"></th:block>
            </div>

            <script src="/js/map_loader.js"></script>
            <script type="text/javascript">
                $(function () {
                    const roomId = $("select[name='room']").val();
                    if (roomId) {
                        updateRequestInfo(roomId);
                    }
                });
            </script>
        </section>
    </body>
</html>
