<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>WBX Admin - Users</title><link rel="stylesheet" th:href="@{/admin/css/admin.css}"></head>
<body>
<div class="admin-layout">
    <div th:replace="~{admin/fragments :: sidebar('users')}"></div>
    <div class="admin-content">
        <div class="page-header"><h1>사용자 관리</h1><p>사용자 추가/수정/삭제 및 역할 할당</p></div>
        <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
        <div th:if="${error}" class="alert" style="background:#ffebee;color:#c62828;border:1px solid #ffcdd2;padding:12px 16px;border-radius:6px;margin-bottom:16px;font-size:13px;" th:text="${error}"></div>

        <!-- 사용자 추가 폼 -->
        <div style="background:#fff;border-radius:8px;padding:16px;margin-bottom:20px;box-shadow:0 1px 3px rgba(0,0,0,0.08);">
            <h3 style="margin-bottom:12px;font-size:15px;color:#1e3c78;">새 사용자 추가</h3>
            <form th:action="@{/admin/users/add}" method="post" style="display:flex;gap:8px;align-items:end;flex-wrap:wrap;">
                <div>
                    <label style="font-size:12px;color:#888;display:block;margin-bottom:4px;">이메일 *</label>
                    <input name="email" type="email" required placeholder="user@company.com" style="padding:6px 10px;border:1px solid #ddd;border-radius:4px;font-size:13px;width:180px;">
                </div>
                <div>
                    <label style="font-size:12px;color:#888;display:block;margin-bottom:4px;">사용자명 *</label>
                    <input name="username" required placeholder="hong" style="padding:6px 10px;border:1px solid #ddd;border-radius:4px;font-size:13px;width:120px;">
                </div>
                <div>
                    <label style="font-size:12px;color:#888;display:block;margin-bottom:4px;">비밀번호 *</label>
                    <input name="password" type="password" required placeholder="********" style="padding:6px 10px;border:1px solid #ddd;border-radius:4px;font-size:13px;width:130px;">
                </div>
                <div>
                    <label style="font-size:12px;color:#888;display:block;margin-bottom:4px;">이름</label>
                    <input name="fullName" placeholder="홍길동" style="padding:6px 10px;border:1px solid #ddd;border-radius:4px;font-size:13px;width:100px;">
                </div>
                <div>
                    <label style="font-size:12px;color:#888;display:block;margin-bottom:4px;">전화</label>
                    <input name="phone" placeholder="010-0000-0000" style="padding:6px 10px;border:1px solid #ddd;border-radius:4px;font-size:13px;width:120px;">
                </div>
                <div style="display:flex;align-items:center;gap:4px;padding-bottom:2px;">
                    <input name="isAdmin" type="checkbox" value="true" id="chkAdmin">
                    <label for="chkAdmin" style="font-size:12px;color:#888;">관리자</label>
                </div>
                <button type="submit" class="btn btn-primary">추가</button>
            </form>
        </div>

        <!-- 사용자 목록 -->
        <div class="data-table">
            <table>
                <thead>
                <tr><th>ID</th><th>이메일</th><th>사용자명</th><th>이름</th><th>관리자</th><th>상태</th><th>잠금</th><th>최종 로그인</th><th>관리</th></tr>
                </thead>
                <tbody>
                <tr th:each="user : ${users}">
                    <td th:text="${user.id}"></td>
                    <td th:text="${user.email}"></td>
                    <td th:text="${user.username}"></td>
                    <td th:text="${user.fullName}"></td>
                    <td><span th:if="${user.admin}" class="badge badge-info">SA</span></td>
                    <td>
                        <span th:if="${user.active}" class="badge badge-success">활성</span>
                        <span th:unless="${user.active}" class="badge badge-danger">비활성</span>
                    </td>
                    <td><span th:if="${user.locked}" class="badge badge-danger">잠금</span></td>
                    <td th:text="${user.lastLoginAt != null} ? ${#temporals.format(user.lastLoginAt, 'yy-MM-dd HH:mm')} : '-'"></td>
                    <td style="white-space:nowrap;">
                        <a th:href="@{/admin/users/{id}(id=${user.id})}" class="btn btn-outline" style="padding:3px 10px;font-size:12px;">상세</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
