<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>WBX Admin - Permissions</title><link rel="stylesheet" th:href="@{/admin/css/admin.css}"></head>
<body>
<div class="admin-layout">
    <div th:replace="~{admin/fragments :: sidebar('permissions')}"></div>
    <div class="admin-content">
        <div class="page-header">
            <h1>권한 매트릭스</h1>
            <p>전체 역할-모듈-액션 권한 현황. 개별 역할 편집은 <a th:href="@{/admin/roles}" style="color:#1e3c78;">역할 관리</a>에서 가능합니다.</p>
        </div>
        <div class="data-table">
            <table>
                <thead><tr><th>역할</th><th>모듈</th><th>액션</th><th>범위</th><th>관리</th></tr></thead>
                <tbody>
                <tr th:each="perm : ${permissions}">
                    <td>
                        <span th:each="role : ${roles}" th:if="${role.id == perm.roleId}">
                            <a th:href="@{/admin/roles/{id}(id=${role.id})}" class="badge badge-info" style="text-decoration:none;" th:text="${role.code}"></a>
                        </span>
                    </td>
                    <td th:text="${perm.module}"></td>
                    <td th:text="${perm.action}"></td>
                    <td>
                        <span class="badge" th:classappend="${perm.deptScope?.name() == 'COMPANY'} ? 'badge-success' : (${perm.deptScope?.name() == 'DEPT'} ? 'badge-warning' : '')"
                              th:text="${perm.deptScope?.name()}"></span>
                    </td>
                    <td>
                        <form th:action="@{/admin/permissions/{id}/delete(id=${perm.id})}" method="post" style="display:inline;" onsubmit="return confirm('삭제하시겠습니까?')">
                            <button type="submit" class="btn btn-danger" style="padding:2px 8px;font-size:11px;">삭제</button>
                        </form>
                    </td>
                </tr>
                <tr th:if="${#lists.isEmpty(permissions)}"><td colspan="5" style="text-align:center;color:#888;padding:20px;">등록된 권한이 없습니다. 역할 관리에서 권한을 추가하세요.</td></tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
