<?php $this->layout('default') ?>

<?php $this->start('title'); ?>圈子 - <?php echo Setting::getSiteName(); ?><?php $this->end(); ?>

<?php $this->start('content'); ?>
<div class="circle-page">
    <div class="circle-header">
        <div class="container">
            <h1>发现圈子</h1>
            <p>加入感兴趣的圈子，与志同道合的朋友交流</p>
            
            <form method="get" action="<?php echo Helper::url('circle'); ?>" class="search-form">
                <div class="input-group">
                    <input type="text" name="keyword" placeholder="搜索圈子" 
                           value="<?php echo htmlspecialchars($keyword ?? ''); ?>" class="form-control">
                    <button type="submit" class="btn btn-primary">搜索</button>
                </div>
            </form>
        </div>
    </div>
    
    <div class="container">
        <div class="row">
            <!-- 热门圈子侧边栏 -->
            <div class="col-md-3">
                <div class="sidebar">
                    <h3>热门圈子</h3>
                    <div class="hot-circles">
                        <?php foreach ($hotCircles as $hotCircle): ?>
                        <div class="hot-circle-item">
                            <a href="<?php echo Helper::url('circle/detail?id=' . $hotCircle['id']); ?>">
                                <img src="<?php echo $hotCircle['avatar'] ? $this->uploadUrl($hotCircle['avatar']) : $this->assetUrl('images/default-circle.png'); ?>" 
                                     alt="" class="circle-avatar">
                                <div class="circle-info">
                                    <div class="circle-name"><?php echo htmlspecialchars($hotCircle['name']); ?></div>
                                    <div class="circle-meta"><?php echo $hotCircle['member_count']; ?> 成员</div>
                                </div>
                            </a>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
            
            <!-- 圈子列表 -->
            <div class="col-md-9">
                <div class="circle-list">
                    <?php foreach ($circles as $circle): ?>
                    <div class="circle-card">
                        <div class="circle-banner" style="background-image: url(<?php echo !empty($circle['cover']) ? $this->uploadUrl($circle['cover']) : $this->assetUrl('images/default-banner.jpg'); ?>);">
                            <div class="circle-avatar-wrap">
                                <img src="<?php echo $circle['avatar'] ? $this->uploadUrl($circle['avatar']) : $this->assetUrl('images/default-circle.png'); ?>" 
                                     alt="" class="circle-avatar-lg">
                                <?php if ($circle['is_verified']): ?>
                                <span class="verified-badge"><i class="fa fa-check-circle"></i></span>
                                <?php endif; ?>
                            </div>
                        </div>
                        
                        <div class="circle-content">
                            <h3><a href="<?php echo Helper::url('circle/detail?id=' . $circle['id']); ?>">
                                <?php echo htmlspecialchars($circle['name']); ?>
                            </a></h3>
                            <p class="circle-desc"><?php echo htmlspecialchars($circle['description']); ?></p>
                            
                            <div class="circle-stats">
                                <span class="stat-item">
                                    <i class="fa fa-users"></i> <?php echo $circle['member_count']; ?> 成员
                                </span>
                                <span class="stat-item">
                                    <i class="fa fa-file-text"></i> <?php echo $circle['post_count']; ?> 帖子
                                </span>
                                <span class="stat-item">
                                    <i class="fa fa-eye"></i> 浏览
                                </span>
                            </div>
                            
                            <div class="circle-tags">
                                <span class="tag <?php echo empty($circle['is_private']) ? 'tag-public' : 'tag-private'; ?>">
                                    <?php echo empty($circle['is_private']) ? '公开' : '私密'; ?>
                                </span>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
                
                <?php if (empty($circles)): ?>
                <div class="empty-state">
                    <i class="fa fa-search"></i>
                    <p>没有找到相关圈子</p>
                </div>
                <?php endif; ?>
                
                <?php if ($totalPages > 1): ?>
                <div class="pagination-wrap">
                    <?php echo $this->pagination($page, $totalPages, 'circle?keyword=' . urlencode($keyword ?? '')); ?>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<?php $this->end(); ?>
