<?php
/**
 * HuSNS - 一款免费开源的社交平台
 *
 * @author  HYR
 * @QQ      281900864
 * @website https://huyourui.com
 * @license MIT
 * @声明    严禁用于违法违规用途
 */
?>
<!-- 左侧栏 -->
<aside class="sidebar-left">
    <?php if (isset($_SESSION['user_id'])): ?>
    <div class="user-card">
            <img src="/templates/defaultpro/images/avatar_default.png" alt="" style="width:70px;height:70px;border-radius:50%;object-fit:cover;">
            <div class="user-card-name"><?php echo $this->escape($_SESSION['username'] ?? '用户'); ?></div>
            <div class="user-card-bio">这个人很懒，什么都没写</div>
            <div class="user-card-stats">
                <div class="stat-item"><div class="stat-value">-</div><div class="stat-label">动态</div></div>
                <div class="stat-item"><div class="stat-value">-</div><div class="stat-label">关注</div></div>
                <div class="stat-item"><div class="stat-value">-</div><div class="stat-label">粉丝</div></div>
            </div>
        </div>
        <?php else: ?>
        <div class="user-card">
            <img src="/templates/defaultpro/images/avatar_default.png" alt="" style="width:70px;height:70px;border-radius:50%;object-fit:cover;">
            <div class="user-card-name">游客</div>
            <div class="user-card-bio">登录后体验更多功能</div>
            <div class="user-card-stats">
                <div class="stat-item"><div class="stat-value">-</div><div class="stat-label">动态</div></div>
                <div class="stat-item"><div class="stat-value">-</div><div class="stat-label">关注</div></div>
                <div class="stat-item"><div class="stat-value">-</div><div class="stat-label">粉丝</div></div>
            </div>
        </div>
    <?php endif; ?>
    <?php if (!isset($_SESSION['user_id'])): ?>
    <div class="guest-tip">
        <p><a href="<?php echo $this->url('user/login'); ?>">登录</a> | <a href="<?php echo $this->url('user/register'); ?>">注册</a></p>
    </div>
    <?php endif; ?>

    <ul class="menu">
        <li><a href="<?php echo $this->url(); ?>">🏠 首页</a></li>
        <li><a href="<?php echo $this->url('?tab=following'); ?>">❤️ 关注</a></li>
        <li><a href="<?php echo $this->url('post/hot'); ?>">🔥 热门</a></li>
        <li><a href="<?php echo $this->url('post/featured'); ?>">✨ 推荐</a></li>
        <li><a href="<?php echo $this->url('notification'); ?>">💬 消息</a></li>
        <?php if (isset($_SESSION['user_id'])): ?>
        <li><a href="<?php echo $this->url('user/profile'); ?>">👤 我的主页</a></li>
        <li class="active"><a href="<?php echo $this->url('user/password'); ?>" aria-current="page">🔐 修改密码</a></li>
        <?php else: ?>
        <li><a href="<?php echo $this->url('user/login'); ?>">🔑 登录</a></li>
        <li><a href="<?php echo $this->url('user/register'); ?>">📝 注册</a></li>
        <?php endif; ?>
    </ul>

    <div class="side-card">
        <div class="side-title">快捷操作</div>
        <ul class="menu">
            <li><a href="#" onclick="showPublishPopup();return false;">✍️ 发布动态</a></li>
            <li><a href="<?php echo $this->url('user/search'); ?>">🔍 查找用户</a></li>
            <li><a href="<?php echo $this->url('post/topic'); ?>">🏷️ 话题广场</a></li>
        </ul>
    </div>
</aside>

<!-- 中间内容 -->
<section class="home-main">
    <div class="page-settings">
    <h2>修改密码</h2>
    
    <?php if ($this->hasFlash('success')): ?>
    <div class="alert alert-success"><?php echo $this->flash('success'); ?></div>
    <?php endif; ?>
    
    <?php if ($this->hasFlash('error')): ?>
    <div class="alert alert-error"><?php echo $this->flash('error'); ?></div>
    <?php endif; ?>
    
    <form method="post" id="passwordForm">
        <?php echo $this->csrf(); ?>
        
        <div class="form-group">
            <label>当前密码</label>
            <input type="password" name="old_password" id="oldPassword" required placeholder="请输入当前密码">
        </div>
        
        <div class="form-group">
            <label>新密码</label>
            <input type="password" name="password" id="newPassword" required placeholder="请输入新密码">
            <small>密码长度至少6位，建议包含字母、数字和特殊字符</small>
        </div>
        
        <div class="form-group">
            <label>确认新密码</label>
            <input type="password" name="password_confirm" id="confirmPassword" required placeholder="请再次输入新密码">
        </div>
        
        <div style="display:flex;gap:12px;">
            <button type="submit" class="btn btn-primary">确认修改</button>
            <a href="<?php echo $this->url('user/settings'); ?>" class="btn">取消</a>
        </div>
    </form>
    </div>
</section>

<!-- 右侧栏 -->
<aside class="sidebar-right">
    <div class="side-card">
        <div class="side-title">推荐关注</div>
        <div id="recommend-users">
            <div class="empty-tip">登录后查看推荐</div>
        </div>
    </div>

    <div class="side-card">
        <div class="side-title">热门话题</div>
        <div id="hot-topics">
            <div class="empty-tip">登录后查看热门话题</div>
        </div>
    </div>
</aside>

<script>
(function() {
    var passwordForm = document.getElementById('passwordForm');
    var newPassword = document.getElementById('newPassword');
    var confirmPassword = document.getElementById('confirmPassword');
    
    passwordForm.addEventListener('submit', function(e) {
        var pwd = newPassword.value;
        var confirm = confirmPassword.value;
        
        // 验证密码长度
        if (pwd.length < 6) {
            alert('密码长度至少6位');
            e.preventDefault();
            return;
        }
        
        // 验证两次输入是否一致
        if (pwd !== confirm) {
            alert('两次输入的密码不一致');
            e.preventDefault();
            return;
        }
        
        // 验证密码强度
        if (!/(?=.*[a-zA-Z])(?=.*\d)/.test(pwd)) {
            if (!confirm('密码建议包含字母和数字，是否继续？')) {
                e.preventDefault();
                return;
            }
        }
    });
})();
</script>