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

    <div class="d-flex justify-content-center align-items-center" style="height: 70vh;">
        <div class="card shadow p-4" style="width: 350px;">        <form id="loginForm" style="width: 300px;" method="post" action="/api/login_process.php">
                <h3 class="text-center mb-4">로그인</h3>

                <div class="mb-3">
                    <label for="userid" class="form-label">아이디</label>
                    <input type="text" class="form-control" id="userid" name="userid" placeholder="아이디를 입력하세요" required>
                </div>

                <div class="mb-4">
                    <label for="password" class="form-label">비밀번호</label>
                    <input type="password" class="form-control" id="password" name="password" placeholder="비밀번호를 입력하세요" required>
                </div>

                <button type="submit" class="btn btn-primary w-100">로그인</button>
            </form>
        </div>
    </div>

    <script>
        $(function() {
            $('#loginForm').on('submit', function(e) {
                e.preventDefault();

                // 간단 밸리데이션 예제
                const userid = $('#userid').val().trim();
                const password = $('#password').val().trim();

                if (!userid) {
                    alert('아이디를 입력하세요.');
                    $('#userid').focus();
                    return;
                }
                if (!password) {
                    alert('비밀번호를 입력하세요.');
                    $('#password').focus();
                    return;
                }

                // AJAX 로그인 요청 (예시)
                $.ajax({
                    url: '/tenant/api/login_process.php',
                    type: 'POST',
                    data: { userid: userid, password: password },
                    dataType: 'json',
                    success: function(response) {
                        if(response.success) {
                            alert('로그인 성공!');
                            window.location.href = '/tenant/member/dashboard.php';
                        } else {
                            alert('로그인 실패: ' + response.message);
                        }
                    },
                    error: function() {
                        alert('서버 오류가 발생했습니다.');
                    }
                });
            });
        });
    </script>

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