<!DOCTYPE html>
<html lang="zh-CN" data-theme="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录卡片 - HoloLake Design System</title>
    <link rel="stylesheet" href="../components.css">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: var(--bg-primary);
            margin: 0;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }
        .container {
            width: 100%;
            max-width: 400px;
            padding: 1rem;
        }
        .card {
            background: var(--bg-card);
            border: 1px solid var(--border-default);
            border-radius: 16px;
            padding: 2rem;
            box-shadow: var(--shadow-card);
        }
        .card h2 {
            margin-bottom: 1.5rem;
            text-align: center;
            color: var(--text-primary);
        }
        .input-group {
            margin-bottom: 1rem;
        }
        .input-group label {
            display: block;
            margin-bottom: 0.25rem;
            color: var(--text-secondary);
            font-size: 0.9rem;
        }
        .input {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid var(--border-default);
            border-radius: 8px;
            background: var(--bg-input);
            color: var(--text-primary);
        }
        .checkbox-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin: 1rem 0;
        }
        .btn-block {
            width: 100%;
            margin-bottom: 0.5rem;
        }
        .switch-label {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            color: var(--text-secondary);
        }
        .alert {
            margin-top: 1rem;
        }
        .hidden {
            display: none;
        }
        .register-fields {
            margin-top: 1rem;
            border-top: 1px solid var(--border-default);
            padding-top: 1rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="card">
            <h2 id="formTitle">登录</h2>
            <div id="loginForm">
                <div class="input-group">
                    <label>用户名</label>
                    <input type="text" class="input" id="loginUsername" placeholder="请输入用户名">
                </div>
                <div class="input-group">
                    <label>密码</label>
                    <input type="password" class="input" id="loginPassword" placeholder="请输入密码">
                </div>
            </div>
            <div id="registerForm" class="hidden">
                <div class="input-group">
                    <label>用户名</label>
                    <input type="text" class="input" id="regUsername" placeholder="请输入用户名">
                </div>
                <div class="input-group">
                    <label>密码</label>
                    <input type="password" class="input" id="regPassword" placeholder="请输入密码">
                </div>
                <div class="input-group">
                    <label>确认密码</label>
                    <input type="password" class="input" id="regConfirm" placeholder="请再次输入密码">
                </div>
            </div>

            <div class="checkbox-row">
                <label class="switch-label">
                    <span>记住我</span>
                    <label class="switch">
                        <input type="checkbox" id="rememberMe">
                        <span class="slider"></span>
                    </label>
                </label>
                <button class="btn btn-ghost btn-sm" id="toggleFormBtn">注册账号</button>
            </div>

            <button class="btn btn-primary btn-block" id="actionBtn">登录</button>
            <button class="btn btn-outline btn-block" id="switchToRegister" style="display: none;">已有账号？去登录</button>

            <div id="messageArea" class="alert hidden"></div>
        </div>
    </div>

    <script src="../components.js"></script>
    <script>
        (function() {
            const loginForm = document.getElementById('loginForm');
            const registerForm = document.getElementById('registerForm');
            const formTitle = document.getElementById('formTitle');
            const actionBtn = document.getElementById('actionBtn');
            const toggleFormBtn = document.getElementById('toggleFormBtn');
            const switchToRegister = document.getElementById('switchToRegister');
            const rememberMe = document.getElementById('rememberMe');
            const messageArea = document.getElementById('messageArea');

            let isLogin = true;

            // 加载记住我状态
            const savedRemember = localStorage.getItem('rememberMe');
            if (savedRemember === 'true') {
                rememberMe.checked = true;
            }

            // 记住我开关变化时保存
            rememberMe.addEventListener('change', function() {
                localStorage.setItem('rememberMe', this.checked);
            });

            function showMessage(type, text) {
                messageArea.className = `alert alert-${type}`;
                messageArea.textContent = text;
                messageArea.classList.remove('hidden');
                setTimeout(() => {
                    messageArea.classList.add('hidden');
                }, 3000);
            }

            function toggleForms() {
                isLogin = !isLogin;
                if (isLogin) {
                    loginForm.classList.remove('hidden');
                    registerForm.classList.add('hidden');
                    formTitle.textContent = '登录';
                    actionBtn.textContent = '登录';
                    toggleFormBtn.textContent = '注册账号';
                } else {
                    loginForm.classList.add('hidden');
                    registerForm.classList.remove('hidden');
                    formTitle.textContent = '注册';
                    actionBtn.textContent = '注册';
                    toggleFormBtn.textContent = '返回登录';
                }
            }

            toggleFormBtn.addEventListener('click', toggleForms);

            actionBtn.addEventListener('click', function() {
                if (isLogin) {
                    const username = document.getElementById('loginUsername').value;
                    const password = document.getElementById('loginPassword').value;
                    if (!username || !password) {
                        showMessage('error', '请输入用户名和密码');
                    } else {
                        showMessage('success', '登录成功（模拟）');
                    }
                } else {
                    const username = document.getElementById('regUsername').value;
                    const password = document.getElementById('regPassword').value;
                    const confirm = document.getElementById('regConfirm').value;
                    if (!username || !password || !confirm) {
                        showMessage('error', '请填写所有字段');
                    } else if (password !== confirm) {
                        showMessage('error', '两次密码不一致');
                    } else {
                        showMessage('success', '注册成功（模拟）');
                    }
                }
            });
        })();
    </script>
</body>
</html>
