<?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><a href="<?php echo $this->url('user/settings'); ?>">⚙️ 设置</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-my-reports">
    <h2>我的举报</h2>
    
    <!-- 统计信息 -->
    <div class="report-stats">
        <div class="stat-item">
            <div class="stat-value"><?php echo $total_reports ?? 0; ?></div>
            <div class="stat-label">总举报</div>
        </div>
        <div class="stat-item">
            <div class="stat-value pending"><?php echo $pending_count ?? 0; ?></div>
            <div class="stat-label">待处理</div>
        </div>
        <div class="stat-item">
            <div class="stat-value accepted"><?php echo $accepted_count ?? 0; ?></div>
            <div class="stat-label">已采纳</div>
        </div>
        <div class="stat-item">
            <div class="stat-value rejected"><?php echo $rejected_count ?? 0; ?></div>
            <div class="stat-label">已驳回</div>
        </div>
    </div>
    
    <!-- 筛选标签 -->
    <div class="filter-tabs">
        <button class="filter-tab active" data-status="">全部</button>
        <button class="filter-tab" data-status="pending">⏳ 待处理</button>
        <button class="filter-tab" data-status="accepted">✅ 已采纳</button>
        <button class="filter-tab" data-status="rejected">❌ 已驳回</button>
    </div>
    
    <!-- 举报列表 -->
    <div class="report-list">
        <?php if (!empty($my_reports)): ?>
            <?php foreach ($my_reports as $report): ?>
            <div class="report-item">
                <div class="report-header">
                    <span class="report-status <?php echo $report['status']; ?>">
                        <?php 
                        $status_text = '';
                        switch ($report['status']) {
                            case 'pending': $status_text = '待处理'; break;
                            case 'accepted': $status_text = '已采纳'; break;
                            case 'rejected': $status_text = '已驳回'; break;
                        }
                        echo $status_text;
                        ?>
                    </span>
                    <span class="report-time"><?php echo $this->escape($report['created_at']); ?></span>
                </div>
                <div class="report-content">
                    <div class="report-info">
                        <span class="report-type">举报类型：<?php echo $this->escape($report['type']); ?></span>
                        <span class="report-target">举报对象：<?php echo $this->escape($report['target_type']); ?></span>
                    </div>
                    <p class="report-reason">举报原因：<?php echo $this->escape($report['reason']); ?></p>
                    <?php if ($report['evidence']): ?>
                    <div class="report-evidence">
                        <img src="<?php echo $this->escape($report['evidence']); ?>" alt="证据图片" class="evidence-img">
                    </div>
                    <?php endif; ?>
                </div>
                <div class="report-meta">
                    <span>被举报人：<?php echo $this->escape($report['target_name']); ?></span>
                </div>
                <?php if ($report['status'] !== 'pending'): ?>
                <div class="report-result">
                    处理结果：<?php echo $report['status'] === 'accepted' ? '✅ 举报已采纳，感谢你的反馈！' : '❌ 举报已驳回，未发现违规内容'; ?>
                    <?php if ($report['processed_at']): ?>
                    <span class="processed-time">（处理时间：<?php echo $this->escape($report['processed_at']); ?>）</span>
                    <?php endif; ?>
                </div>
                <?php endif; ?>
                <?php if ($report['status'] === 'pending'): ?>
                <div class="report-actions">
                    <button class="action-btn cancel" data-report-id="<?php echo $report['id']; ?>">取消举报</button>
                </div>
                <?php endif; ?>
            </div>
            <?php endforeach; ?>
        <?php else: ?>
            <div class="empty-state">
                <div class="empty-icon">📋</div>
                <p>暂无举报记录</p>
            </div>
        <?php endif; ?>
    </div>
    
    <!-- 分页 -->
    <?php if ($total_pages > 1): ?>
    <div class="pagination">
        <a href="?page=1" class="page-link">首页</a>
        <?php if ($current_page > 1): ?>
        <a href="?page=<?php echo $current_page - 1; ?>" class="page-link">上一页</a>
        <?php endif; ?>
        <span class="page-current"><?php echo $current_page; ?>/<?php echo $total_pages; ?></span>
        <?php if ($current_page < $total_pages): ?>
        <a href="?page=<?php echo $current_page + 1; ?>" class="page-link">下一页</a>
        <?php endif; ?>
        <a href="?page=<?php echo $total_pages; ?>" class="page-link">末页</a>
    </div>
    <?php endif; ?>
    </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 filterTabs = document.querySelectorAll('.filter-tab');
    
    filterTabs.forEach(function(tab) {
        tab.addEventListener('click', function() {
            filterTabs.forEach(function(t) { t.classList.remove('active'); });
            this.classList.add('active');
            
            var status = this.dataset.status;
            window.location.href = '?status=' + status;
        });
    });
    
    // 取消举报
    var cancelBtns = document.querySelectorAll('.action-btn.cancel');
    cancelBtns.forEach(function(btn) {
        btn.addEventListener('click', function() {
            var reportId = this.dataset.reportId;
            
            if (!confirm('确定要取消这个举报吗？')) return;
            
            fetch('<?php echo $this->url('user/cancelReport'); ?>', {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                body: 'report_id=' + reportId + '&csrf_token=' + '<?php echo $_SESSION['csrf_token'] ?? ''; ?>'
            }).then(function(response) {
                return response.json();
            }).then(function(data) {
                if (data.code === 0) {
                    btn.closest('.report-item').remove();
                    alert('已取消举报');
                } else {
                    alert(data.message || '操作失败');
                }
            }).catch(function() {
                alert('网络错误');
            });
        });
    });
})();
</script>