<!--

    Queue - A Queueing system that can be used to handle labs in higher education
    Copyright (C) 2016-2020  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}">
    <head>
        <title>Editions</title>
    </head>

    <!--@thymesVar id="editions" type="org.springframework.data.domain.Page<nl.tudelft.labracore.api.dto.EditionDetailsDTO>"-->

    <!--@thymesVar id="programs" type="java.util.List<nl.tudelft.labracore.api.dto.ProgramSummaryDTO>"-->

    <!--@thymesVar id="filter" type="nl.tudelft.queue.dto.util.EditionFilterDTO"-->

    <body>
        <main layout:fragment="content">
            <h1 class="font-800 mb-5">Catalog</h1>

            <form class="flex mb-5" th:action="@{/editions/filter}" method="post">
                <div class="flex gap-3 align-center">
                    <span>Programmes:</span>
                    <div>
                        <select multiple class="select" size="10" id="program-select" name="programs" data-select>
                            <option
                                th:each="program : ${programs}"
                                th:value="${program.id}"
                                th:selected="${(filter?.programs ?: {}).contains(program.id)}"
                                th:text="${program.name}"></option>
                        </select>
                    </div>
                </div>

                <input
                    aria-label="Search for courses"
                    class="textfield"
                    name="nameSearch"
                    placeholder="Search for courses"
                    th:value="${filter?.nameSearch ?: ''}" />

                <button class="button" type="submit">Filter</button>
            </form>

            <div class="flex vertical">
                <table th:unless="${#lists.isEmpty(editions)}" class="table" data-style="surface">
                    <thead>
                        <tr class="table__header">
                            <th>Edition</th>
                            <th>Code</th>
                            <th>Teachers</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="edition : ${editions}">
                            <td>
                                <a class="link" th:href="@{/edition/{id}(id=${edition.id})}" th:text="|${edition.course.name} (${edition.name})|"></a>
                            </td>
                            <td th:text="${edition.course.code}"></td>
                            <td th:text="${#strings.listJoin(@roleDTOService.teacherNames(edition), ', ')}"></td>
                            <td class="flex justify-end">
                                <a
                                    class="button p-min"
                                    th:unless="${@permissionService.canViewEdition(edition.id) or edition.isArchived}"
                                    th:href="@{/edition/{id}/enrol(id=${edition.id})}">
                                    Enrol
                                </a>
                                <button
                                    class="button p-min"
                                    th:if="${@permissionService.canViewEdition(edition.id) or edition.isArchived}"
                                    disabled
                                    th:href="@{/edition/{id}/enrol(id=${edition.id})}">
                                    Enrol
                                </button>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <nav th:replace="pagination :: pagination (page=${editions}, size=3)"></nav>
            </div>
        </main>
    </body>
</html>
