<?php
/**
 * HuSNS - 举报详情后台页面
 */
?>
<div class="admin-content">
    <div class="admin-header">
        <h1>举报详情</h1>
        <a href="<?php echo Helper::url('admin/reports'); ?>" class="btn btn-default">
            <i class="fa fa-arrow-left"></i> 返回列表
        </a>
    </div>
    
    <div class="report-detail">
        <div class="panel">
            <div class="panel-header">
                <h3>举报信息</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>举报ID</label>
                            <p class="form-control-static">#<?php echo $report['id']; ?></p>
                        </div>
                        
                        <div class="form-group">
                            <label>举报人</label>
                            <div class="user-info">
                                <img src="<?php echo $report['reporter_avatar'] ? $this->uploadUrl($report['reporter_avatar']) : $this->assetUrl('images/default-avatar.png'); ?>" 
                                     alt="" class="avatar-md">
                                <span><?php echo htmlspecialchars($report['reporter_name']); ?></span>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label>举报原因</label>
                            <span class="badge badge-info">
                                <?php echo $reasonOptions[$report['reason']] ?? $report['reason']; ?>
                            </span>
                        </div>
                        
                        <div class="form-group">
                            <label>状态</label>
                            <?php echo $report['status_label']; ?>
                        </div>
                    </div>
                    
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>举报时间</label>
                            <p class="form-control-static"><?php echo $report['created_at_text']; ?></p>
                        </div>
                        
                        <div class="form-group">
                            <label>处理时间</label>
                            <p class="form-control-static"><?php echo $report['handled_at_text']; ?></p>
                        </div>
                        
                        <div class="form-group">
                            <label>处理结果</label>
                            <p class="form-control-static"><?php echo htmlspecialchars($report['handle_result'] ?: '-'); ?></p>
                        </div>
                    </div>
                </div>
                
                <?php if (!empty($report['detail'])): ?>
                <div class="form-group">
                    <label>详细说明</label>
                    <p class="form-control-static"><?php echo htmlspecialchars($report['detail']); ?></p>
                </div>
                <?php endif; ?>
            </div>
        </div>
        
        <?php if ($report['post_id']): ?>
        <div class="panel">
            <div class="panel-header">
                <h3>被举报内容</h3>
            </div>
            <div class="panel-body">
                <div class="post-preview">
                    <div class="post-header">
                        <img src="<?php echo $report['post_user_avatar'] ? $this->uploadUrl($report['post_user_avatar']) : $this->assetUrl('images/default-avatar.png'); ?>" 
                             alt="" class="avatar-md">
                        <div class="post-author">
                            <a href="<?php echo Helper::url('user/profile?id=' . $report['post_user_id']); ?>">
                                <?php echo htmlspecialchars($report['post_user_name']); ?>
                            </a>
                        </div>
                    </div>
                    <div class="post-content">
                        <?php echo htmlspecialchars($report['post_content']); ?>
                    </div>
                    <div class="post-actions">
                        <a href="<?php echo Helper::url('post/detail?id=' . $report['post_id']); ?>" 
                           target="_blank" class="btn btn-sm btn-default">
                            <i class="fa fa-external-link"></i> 查看原帖
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <?php endif; ?>
        
        <?php if ($report['status'] == 0): ?>
        <div class="panel">
            <div class="panel-header">
                <h3>处理操作</h3>
            </div>
            <div class="panel-body">
                <form id="handleForm">
                    <input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
                    <input type="hidden" name="id" value="<?php echo $report['id']; ?>">
                    
                    <div class="form-group">
                        <label>处理方式</label>
                        <div class="radio-group">
                            <label class="radio-inline">
                                <input type="radio" name="status" value="1" checked> 确认处理
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="status" value="2"> 驳回举报
                            </label>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label>处理结果说明</label>
                        <textarea name="result" class="form-control" rows="3" placeholder="请输入处理结果说明（可选）"></textarea>
                    </div>
                    
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">确认处理</button>
                        <a href="<?php echo Helper::url('admin/reports'); ?>" class="btn btn-default">取消</a>
                    </div>
                </form>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>

<script>
$(function() {
    $('#handleForm').submit(function(e) {
        e.preventDefault();
        
        $.post('<?php echo Helper::url('admin/reports/handle'); ?>', $(this).serialize(), function(res) {
            if (res.success) {
                alert(res.message);
                window.location.href = '<?php echo Helper::url('admin/reports'); ?>';
            } else {
                alert(res.message);
            }
        }, 'json');
    });
});
</script>
