<?php
/**
 * HuSNS - 一款免费开源的社交平台
 * 
 * @author  HYR
 * @QQ      281900864
 * @website https://huyourui.com
 * @license MIT
 * @声明    严禁用于违法违规用途
 */
$currentPage = 'login';
$pageType = 'login';
$bodyClass = 'login-page';
$hideTabBar = true;
$headerTitle = '登录';
$userId = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
$this->setLayout('app');
?>
<style>
    /* 登录页面特定样式 */
    .login-content {
        background-color: var(--background-color);
        min-height: calc(100vh - 44px);
        padding: 40px 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .login-logo {
        margin-bottom: 40px;
        text-align: center;
    }
    
    .login-logo img {
        max-width: 180px;
        max-height: 60px;
        object-fit: contain;
    }
    
    .login-logo-text {
        font-size: 32px;
        font-weight: 700;
        color: var(--primary-color);
    }
    
    .login-form {
        width: 100%;
        max-width: 400px;
        background-color: var(--card-color);
        border-radius: 12px;
        padding: 24px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .form-group {
        margin-bottom: 20px;
    }
    
    .form-label {
        display: block;
        font-size: 14px;
        font-weight: 600;
        color: var(--text-color);
        margin-bottom: 8px;
    }
    
    .form-input {
        width: 100%;
        padding: 12px 16px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        font-size: 16px;
        color: var(--text-color);
        background-color: var(--background-color);
        outline: none;
        transition: all 0.3s ease;
    }
    
    .form-input:focus {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
    }
    
    .form-input::placeholder {
        color: var(--text-secondary-color);
    }
    
    .form-options {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 24px;
    }
    
    .remember-me {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .remember-me input[type="checkbox"] {
        width: 16px;
        height: 16px;
        accent-color: var(--primary-color);
    }
    
    .remember-me label {
        font-size: 14px;
        color: var(--text-secondary-color);
        cursor: pointer;
    }
    
    .forgot-password {
        font-size: 14px;
        color: var(--primary-color);
        text-decoration: none;
        transition: color 0.3s ease;
    }
    
    .forgot-password:hover {
        color: #0066CC;
    }
    
    .login-btn {
        width: 100%;
        padding: 14px;
        background-color: var(--primary-color);
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        margin-bottom: 16px;
    }
    
    .login-btn:hover {
        background-color: #0066CC;
    }
    
    .login-btn:disabled {
        background-color: var(--border-color);
        cursor: not-allowed;
    }
    
    .divider {
        display: flex;
        align-items: center;
        margin: 24px 0;
    }
    
    .divider::before,
    .divider::after {
        content: '';
        flex: 1;
        height: 1px;
        background-color: var(--border-color);
    }
    
    .divider-text {
        padding: 0 16px;
        font-size: 14px;
        color: var(--text-secondary-color);
    }
    
    .social-login {
        display: flex;
        gap: 16px;
        justify-content: center;
        margin-bottom: 24px;
    }
    
    .social-btn {
        width: 48px;
        height: 48px;
        border: 1px solid var(--border-color);
        border-radius: 50%;
        background-color: var(--card-color);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
    }
    
    .social-btn:hover {
        border-color: var(--primary-color);
        background-color: rgba(0, 122, 255, 0.05);
    }
    
    .social-icon {
        font-size: 20px;
    }
    
    .register-link {
        text-align: center;
        font-size: 14px;
        color: var(--text-secondary-color);
    }
    
    .register-link a {
        color: var(--primary-color);
        text-decoration: none;
        font-weight: 600;
        transition: color 0.3s ease;
    }
    
    .register-link a:hover {
        color: #0066CC;
    }
    
    /* 适配暗黑模式 */
    @media (prefers-color-scheme: dark) {
        .login-form {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }
    }
    
    /* 响应式调整 */
    @media (max-width: 320px) {
        .login-content {
            padding: 20px 16px;
        }
        
        .login-logo {
            font-size: 28px;
            margin-bottom: 30px;
        }
        
        .login-form {
            padding: 20px;
        }
        
        .form-input {
            padding: 10px 14px;
            font-size: 15px;
        }
        
        .login-btn {
            padding: 12px;
            font-size: 15px;
        }
    }
</style>

<div class="login-content">
    <div class="login-logo">
        <?php if (file_exists(ROOT_PATH . 'static/logo.png')): ?>
            <img src="<?php echo $this->url('static/logo.png'); ?>" alt="Logo">
        <?php else: ?>
            <div class="login-logo-text">HuSNS</div>
        <?php endif; ?>
    </div>
    
    <form class="login-form" id="loginForm" method="post">
        <div class="form-group">
            <label class="form-label" for="username">用户名</label>
            <input type="text" class="form-input" id="username" name="username" placeholder="请输入用户名" required>
        </div>
        
        <div class="form-group">
            <label class="form-label" for="password">密码</label>
            <input type="password" class="form-input" id="password" name="password" placeholder="请输入密码" required>
        </div>
        
        <div class="form-options">
            <div class="remember-me">
                <input type="checkbox" id="remember" name="remember">
                <label for="remember">记住我</label>
            </div>
            <a href="<?php echo $this->url('mobile/password'); ?>" class="forgot-password">忘记密码？</a>
        </div>
        
        <button type="submit" class="login-btn" id="loginBtn">登录</button>
        
        <div class="divider">
            <span class="divider-text">其他登录方式</span>
        </div>
        
        <div class="social-login">
            <button type="button" class="social-btn" onclick="loginWithWechat()">
                <span class="social-icon"><span class="iconify" data-icon="mdi:wechat"></span></span>
            </button>
            <button type="button" class="social-btn" onclick="loginWithQQ()">
                <span class="social-icon"><span class="iconify" data-icon="mdi:qqchat"></span></span>
            </button>
            <button type="button" class="social-btn" onclick="loginWithWeibo()">
                <span class="social-icon"><span class="iconify" data-icon="mdi:sina-weibo"></span></span>
            </button>
        </div>
        
        <div class="register-link">
            还没有账号？ <a href="<?php echo $this->url('mobile/register'); ?>">立即注册</a>
        </div>
    </form>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const loginForm = document.getElementById('loginForm');
        const loginBtn = document.getElementById('loginBtn');
        
        loginForm.addEventListener('submit', function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value.trim();
            
            if (!username || !password) {
                alert('请输入用户名和密码');
                return;
            }
            
            loginBtn.textContent = '登录中...';
            loginBtn.disabled = true;
            
            // 模拟登录请求
            setTimeout(function() {
                alert('登录成功！');
                window.location.href = '<?php echo $this->url('mobile'); ?>';
            }, 1500);
        });
    });
    
    // 社交登录
    function loginWithWechat() {
        alert('微信登录功能开发中');
    }
    
    function loginWithQQ() {
        alert('QQ登录功能开发中');
    }
    
    function loginWithWeibo() {
        alert('社交登录功能开发中');
    }
</script>