<?php
/**
 * HuSNS - 一款免费开源的社交平台
 * 
 * @author  HYR
 * @QQ      281900864
 * @website https://huyourui.com
 * @license MIT
 * @声明    严禁用于违法违规用途
 */
$currentPage = 'password';
$pageType = 'password';
$bodyClass = 'password-page';
$hideTabBar = true;
$showBack = true;
$headerTitle = '忘记密码';
$userId = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
$this->setLayout('app');
?>
<style>
    /* 密码重置页面特定样式 */
    .password-content {
        background-color: var(--background-color);
        min-height: calc(100vh - 44px);
        padding: 40px 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .password-logo {
        margin-bottom: 40px;
        text-align: center;
    }
    
    .password-logo img {
        max-width: 180px;
        max-height: 60px;
        object-fit: contain;
    }
    
    .password-logo-text {
        font-size: 32px;
        font-weight: 700;
        color: var(--primary-color);
    }
    
    .password-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);
    }
    
    .verification-code {
        display: flex;
        gap: 12px;
    }
    
    .verification-code .form-input {
        flex: 1;
    }
    
    .send-code-btn {
        padding: 12px 16px;
        background-color: var(--primary-color);
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        white-space: nowrap;
    }
    
    .send-code-btn:hover {
        background-color: #0066CC;
    }
    
    .send-code-btn:disabled {
        background-color: var(--border-color);
        cursor: not-allowed;
    }
    
    .password-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;
    }
    
    .password-btn:hover {
        background-color: #0066CC;
    }
    
    .password-btn:disabled {
        background-color: var(--border-color);
        cursor: not-allowed;
    }
    
    .login-link {
        text-align: center;
        font-size: 14px;
        color: var(--text-secondary-color);
    }
    
    .login-link a {
        color: var(--primary-color);
        text-decoration: none;
        font-weight: 600;
        transition: color 0.3s ease;
    }
    
    .login-link a:hover {
        color: #0066CC;
    }
    
    /* 适配暗黑模式 */
    @media (prefers-color-scheme: dark) {
        .password-form {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }
    }
    
    /* 响应式调整 */
    @media (max-width: 320px) {
        .password-content {
            padding: 20px 16px;
        }
        
        .password-logo {
            font-size: 28px;
            margin-bottom: 30px;
        }
        
        .password-form {
            padding: 20px;
        }
        
        .form-input {
            padding: 10px 14px;
            font-size: 15px;
        }
        
        .send-code-btn {
            padding: 10px 12px;
            font-size: 13px;
        }
        
        .password-btn {
            padding: 12px;
            font-size: 15px;
        }
    }
</style>

<div class="password-content">
    <div class="password-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="password-logo-text">HuSNS</div>
        <?php endif; ?>
    </div>
    
    <form class="password-form" id="passwordForm" method="post">
        <?php echo $this->csrf(); ?>
        <div class="form-group">
            <label class="form-label" for="phone">手机号</label>
            <div class="verification-code">
                <input type="tel" class="form-input" id="phone" name="phone" placeholder="请输入手机号" required>
                <button type="button" class="send-code-btn" id="sendCodeBtn" onclick="sendVerificationCode()">获取验证码</button>
            </div>
        </div>
        
        <div class="form-group">
            <label class="form-label" for="code">验证码</label>
            <input type="text" class="form-input" id="code" name="code" placeholder="请输入验证码" required>
        </div>
        
        <div class="form-group">
            <label class="form-label" for="newPassword">新密码</label>
            <input type="password" class="form-input" id="newPassword" name="newPassword" placeholder="请输入新密码（至少6位）" required>
        </div>
        
        <div class="form-group">
            <label class="form-label" for="confirmPassword">确认密码</label>
            <input type="password" class="form-input" id="confirmPassword" name="confirmPassword" placeholder="请再次输入新密码" required>
        </div>
        
        <button type="submit" class="password-btn" id="passwordBtn">重置密码</button>
        
        <div class="login-link">
            想起密码了？ <a href="<?php echo $this->url('mobile/login'); ?>">立即登录</a>
        </div>
    </form>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const passwordForm = document.getElementById('passwordForm');
        const passwordBtn = document.getElementById('passwordBtn');
        const newPassword = document.getElementById('newPassword');
        const confirmPassword = document.getElementById('confirmPassword');
        
        passwordForm.addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 验证密码
            if (newPassword.value !== confirmPassword.value) {
                alert('两次输入的密码不一致');
                return;
            }
            
            passwordBtn.textContent = '重置中...';
            passwordBtn.disabled = true;
            
            // 模拟重置请求
            setTimeout(function() {
                alert('密码重置成功！');
                window.location.href = '<?php echo $this->url('mobile/login'); ?>';
            }, 1500);
        });
    });
    
    // 发送验证码
    function sendVerificationCode() {
        const phone = document.getElementById('phone').value.trim();
        const sendCodeBtn = document.getElementById('sendCodeBtn');
        
        if (!phone) {
            alert('请输入手机号');
            return;
        }
        
        // 模拟发送验证码
        sendCodeBtn.disabled = true;
        sendCodeBtn.textContent = '60s后重发';
        
        let countdown = 60;
        const timer = setInterval(function() {
            countdown--;
            sendCodeBtn.textContent = countdown + 's后重发';
            
            if (countdown <= 0) {
                clearInterval(timer);
                sendCodeBtn.disabled = false;
                sendCodeBtn.textContent = '获取验证码';
            }
        }, 1000);
        
        alert('验证码已发送到您的手机');
    }
</script>