<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
    layout:decorate="~{layouts/signin-layout}" lang="ko" xml:lang="ko">
    <head>
        <title>Sign In</title>
    </head>
    <body>
        <section layout:fragment="content">
            <div class="container">
                <div class="row justify-content-center align-items-center min-vh-100">
                    <div class="col-lg-4 col-md-6">
                        <div class="card shadow-sm">
                            <div class="card-body p-5">
                                <div class="text-center mb-4">
                                    <i class="bi bi-person-circle text-primary" style="font-size: 3rem;"></i>
                                    <h2 class="card-title mt-3">Sign in to NXCUS-Agent</h2>
                                </div>
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text">
                                            <i class="bi bi-person"></i>
                                        </span>
                                        <input type="text" id="username" name="username" class="form-control" placeholder="아이디" required>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <div class="input-group">
                                        <span class="input-group-text">
                                            <i class="bi bi-lock"></i>
                                        </span>
                                        <input type="password" id="password" name="password" class="form-control" placeholder="비밀번호" required>
                                    </div>
                                </div>
                                <div class="d-grid gap-2">
                                    <button id="signIn" type="button" class="btn btn-primary">
                                        <i class="bi bi-box-arrow-in-right me-2"></i>Sign in
                                    </button>
                                    <button id="signUp" type="button" class="btn btn-outline-secondary">
                                        <i class="bi bi-person-plus-fill me-2"></i>Sign up
                                    </button>
                                </div>
                                <div class="text-end mt-3">
                                    <span id="changePassword" class="text-info text-decoration-none" style="cursor: pointer;">
                                        <small><i class="bi bi-key-fill me-1"></i>Reset your password</small>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 회원가입 모달 -->
            <div class="modal fade" id="signupModal" tabindex="-1" aria-labelledby="signupModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered">
                    <div class="modal-content">
                        <div class="modal-header bg-dark text-white">
                            <h5 class="modal-title" id="signupModalLabel">Join Membership</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <form id="signupForm">
                            <div class="modal-body">
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-person"></i></span>
                                        <input type="text" class="form-control" id="userId" name="userId" placeholder="아이디" required>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-key"></i></span>
                                        <input type="password" class="form-control" id="userPassword" name="userPassword" placeholder="비밀번호" required>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-person-vcard"></i></span>
                                        <input type="text" class="form-control" id="userName" name="userName" placeholder="사용자명" required>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-envelope"></i></span>
                                        <input type="email" class="form-control" id="email" name="email" placeholder="이메일" required>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-shield-lock"></i></span>
                                        <select id="userRole" name="userRole" class="form-select" required>
                                            <option th:each="role : ${roles}" th:value="${role}" th:text="${role.roleName}"></option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">
                                    <i class="bi bi-x-circle me-2"></i>Cancel
                                </button>
                                <button type="submit" class="btn btn-outline-primary" id="signupSubmit">
                                    <i class="bi bi-check-circle me-2"></i>Join
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- 비밀번호 변경 모달 -->
            <div class="modal fade" id="changePasswordModal" tabindex="-1" aria-labelledby="changePasswordModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered">
                    <div class="modal-content">
                        <div class="modal-header bg-info text-white">
                            <h5 class="modal-title" id="changePasswordModalLabel">Reset Password</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <form id="changePasswordForm">
                            <div class="modal-body">
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-person"></i></span>
                                        <input type="text" class="form-control" id="changePasswordUserId" name="userId" placeholder="아이디" required>
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-key-fill"></i></span>
                                        <input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="새 비밀번호" required>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">
                                    <i class="bi bi-x-circle me-2"></i>Cancel
                                </button>
                                <button type="submit" class="btn btn-outline-info" id="changePasswordSubmit">
                                    <i class="bi bi-check-circle me-2"></i>Change
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <script type="module" th:src="@{/js/pages/sign/sign-in.js}" defer></script>
        </section>
    </body>
</html>