<?php
$CURRENT_SECTION = 'member';
include '../inc/header.php';

// 샘플: 세션에서 값 읽기 (실제론 DB에서 조회)
$userid = isset($_SESSION['userid']) ? $_SESSION['userid'] : 'user';
$username = isset($_SESSION['username']) ? $_SESSION['username'] : '홍길동';
?>

    <div class="d-flex justify-content-center align-items-center" style="min-height: 75vh;">
        <div class="card shadow p-4" style="width: 400px;">
            <form id="profileEditForm" method="post" action="/tenant/api/profile_edit_process.php" autocomplete="off">
                <h3 class="text-center mb-4">내 정보 수정</h3>

                <div class="mb-3">
                    <label class="form-label">아이디</label>
                    <input type="text" class="form-control" name="userid" value="<?= htmlspecialchars($userid)?>" readonly>
                </div>
                <div class="mb-3">
                    <label for="username" class="form-label">이름</label>
                    <input type="text" class="form-control" id="username" name="username" value="<?= htmlspecialchars($username)?>" required>
                </div>
                <div class="mb-3">
                    <label for="password" class="form-label">새 비밀번호</label>
                    <input type="password" class="form-control" id="password" name="password" maxlength="30" placeholder="변경 시 입력">
                </div>
                <div class="mb-4">
                    <label for="password2" class="form-label">비밀번호 확인</label>
                    <input type="password" class="form-control" id="password2" name="password2" maxlength="30" placeholder="변경 시 입력">
                </div>

                <button type="submit" class="btn btn-primary w-100">수정하기</button>
            </form>
        </div>
    </div>

    <script>
        $(function(){
            $('#profileEditForm').on('submit', function(e){
                var username = $('#username').val().trim();
                var pw1 = $('#password').val();
                var pw2 = $('#password2').val();

                if (username.length < 2) {
                    alert('이름은 2글자 이상 입력하세요.');
                    $('#username').focus();
                    e.preventDefault(); return false;
                }
                if (pw1 || pw2) {
                    if (pw1.length < 4) {
                        alert('비밀번호는 4글자 이상이어야 합니다.');
                        $('#password').focus();
                        e.preventDefault(); return false;
                    }
                    if (pw1 !== pw2) {
                        alert('비밀번호가 일치하지 않습니다.');
                        $('#password2').focus();
                        e.preventDefault(); return false;
                    }
                }
                // 서버로 전송
            });
        });
    </script>

<?php include '../inc/footer.php'; ?>
