<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org"
    th:replace="~{modules/layouts/layout :: layout(_head = null,_content = ~{::content},_title = ${title + ' - ' + site.title})}">

<th:block th:fragment="content">

    <div class="page_main uk-width-2-3@m">

        <th:block th:replace="~{modules/header}" />

        <div id="pjax-container" th:with="
            page = ${#lists.isEmpty(param.page) or #strings.isEmpty(param.page[0]) ? 1 : param.page[0]},
            selectedTag = ${#lists.isEmpty(param.tag) ? null : param.tag[0]},
            equipmentGroups = ${groups},
            pageSize = ${equipments.size}
        ">

            <!-- 未筛选时直接查询全部装备。 -->
            <th:block th:if="${#strings.isEmpty(selectedTag)}"
                th:with="equipmentPage = ${equipmentFinder.list(page, pageSize)}">
                <th:block th:replace="~{macro/equipment :: equipment-page(${equipmentPage},${equipmentGroups},${selectedTag})}"></th:block>
            </th:block>

            <!-- URL 中的 tag 使用分组 displayName，Finder 查询使用分组 metadata.name。 -->
            <th:block th:unless="${#strings.isEmpty(selectedTag)}" th:each="group : ${equipmentGroups}">
                <th:block th:if="${#strings.equals(selectedTag, group.spec.displayName) or #strings.equals(selectedTag, group.metadata.name)}"
                    th:with="equipmentPage = ${equipmentFinder.list(page, pageSize, group.metadata.name)}">
                    <th:block th:replace="~{macro/equipment :: equipment-page(${equipmentPage},${equipmentGroups},${selectedTag})}"></th:block>
                </th:block>
            </th:block>

        </div>

        <th:block th:replace="~{modules/footer-main}" />

    </div>
</th:block>

</html>
