<?php
/**
 * HuSNS - 一款免费开源的社交平台
 * 
 * @author  HYR
 * @QQ      281900864
 * @website https://huyourui.com
 * @license MIT
 * @声明    严禁用于违法违规用途
 */
$currentPage = 'register';
$pageType = 'register';
$bodyClass = 'register-page';
$hideTabBar = true;
$headerTitle = '注册';
$userId = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
$this->setLayout('app');
?>
<style>
    /* 注册页面特定样式 */
    .register-content {
        background-color: var(--background-color);
        min-height: calc(100vh - 44px);
        padding: 40px 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .register-logo {
        margin-bottom: 40px;
        text-align: center;
    }
    
    .register-logo img {
        max-width: 180px;
        max-height: 60px;
        object-fit: contain;
    }
    
    .register-logo-text {
        font-size: 32px;
        font-weight: 700;
        color: var(--primary-color);
    }
    
    .register-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-row {
        display: flex;
        gap: 12px;
    }
    
    .form-row .form-group {
        flex: 1;
    }
    
    .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;
    }
    
    .terms-agreement {
        display: flex;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 24px;
    }
    
    .terms-agreement input[type="checkbox"] {
        margin-top: 4px;
        accent-color: var(--primary-color);
    }
    
    .terms-agreement label {
        font-size: 14px;
        color: var(--text-secondary-color);
        line-height: 1.4;
    }
    
    .terms-agreement a {
        color: var(--primary-color);
        text-decoration: none;
    }
    
    .register-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;
    }
    
    .register-btn:hover {
        background-color: #0066CC;
    }
    
    .register-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) {
        .register-form {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }
    }
    
    /* 响应式调整 */
    @media (max-width: 320px) {
        .register-content {
            padding: 20px 16px;
        }
        
        .register-logo {
            font-size: 28px;
            margin-bottom: 30px;
        }
        
        .register-form {
            padding: 20px;
        }
        
        .form-input {
            padding: 10px 14px;
            font-size: 15px;
        }
        
        .send-code-btn {
            padding: 10px 12px;
            font-size: 13px;
        }
        
        .register-btn {
            padding: 12px;
            font-size: 15px;
        }
    }
</style>

<div class="register-content">
    <div class="register-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="register-logo-text">HuSNS</div>
        <?php endif; ?>
    </div>
    
    <form class="register-form" id="registerForm" method="post">
        <?php echo $this->csrf(); ?>
        <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="email">邮箱</label>
            <input type="email" class="form-input" id="email" name="email" placeholder="请输入邮箱" required>
        </div>
        
        <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="password">密码</label>
            <input type="password" class="form-input" id="password" name="password" 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>
        
        <div class="terms-agreement">
            <input type="checkbox" id="agreeTerms" name="agreeTerms" required>
            <label for="agreeTerms">我已阅读并同意 <a href="#">用户协议</a> 和 <a href="#">隐私政策</a></label>
        </div>
        
        <button type="submit" class="register-btn" id="registerBtn">注册</button>
        
        <div class="login-link">
            已有账号？ <a href="<?php echo $this->url('mobile/login'); ?>">立即登录</a>
        </div>
    </form>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const registerForm = document.getElementById('registerForm');
        const registerBtn = document.getElementById('registerBtn');
        const password = document.getElementById('password');
        const confirmPassword = document.getElementById('confirmPassword');
        
        registerForm.addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 验证密码
            if (password.value !== confirmPassword.value) {
                alert('两次输入的密码不一致');
                return;
            }
            
            registerBtn.textContent = '注册中...';
            registerBtn.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>