{% extends 'admin/master.html' %}

{% block body %}
<div class="dashboard-container">
    <div class="row">
        <!-- 统计卡片 -->
        <div class="col-md-2-4 mb-4">
            <div class="stat-card">
                <div class="stat-icon" style="background: rgba(0, 82, 217, 0.1); color: #0052D9;">
                    <span class="material-symbols-outlined">public</span>
                </div>
                <div class="stat-info">
                    <div class="stat-value">{{ stats.sites_count or 0 }}</div>
                    <div class="stat-label">AI工具总数</div>
                </div>
            </div>
        </div>

        <div class="col-md-2-4 mb-4">
            <div class="stat-card">
                <div class="stat-icon" style="background: rgba(0, 168, 112, 0.1); color: #00A870;">
                    <span class="material-symbols-outlined">label</span>
                </div>
                <div class="stat-info">
                    <div class="stat-value">{{ stats.tags_count or 0 }}</div>
                    <div class="stat-label">标签分类</div>
                </div>
            </div>
        </div>

        <div class="col-md-2-4 mb-4">
            <div class="stat-card">
                <div class="stat-icon" style="background: rgba(227, 115, 24, 0.1); color: #E37318;">
                    <span class="material-symbols-outlined">newspaper</span>
                </div>
                <div class="stat-info">
                    <div class="stat-value">{{ stats.news_count or 0 }}</div>
                    <div class="stat-label">新闻动态</div>
                </div>
            </div>
        </div>

        <div class="col-md-2-4 mb-4">
            <div class="stat-card">
                <div class="stat-icon" style="background: rgba(123, 97, 255, 0.1); color: #7B61FF;">
                    <span class="material-symbols-outlined">group</span>
                </div>
                <div class="stat-info">
                    <div class="stat-value">{{ stats.users_count or 0 }}</div>
                    <div class="stat-label">注册用户</div>
                </div>
            </div>
        </div>

        <div class="col-md-2-4 mb-4">
            <div class="stat-card">
                <div class="stat-icon" style="background: rgba(213, 73, 65, 0.1); color: #D54941;">
                    <span class="material-symbols-outlined">visibility</span>
                </div>
                <div class="stat-info">
                    <div class="stat-value">{{ stats.total_views or 0 }}</div>
                    <div class="stat-label">总浏览量</div>
                </div>
            </div>
        </div>
    </div>

    <!-- 快捷操作 -->
    <div class="row">
        <div class="col-md-12 mb-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">快捷操作</h5>
                </div>
                <div class="card-body">
                    <div class="quick-actions">
                        <a href="{{ url_for('site.create_view') }}" class="quick-action-btn">
                            <span class="material-symbols-outlined">add_circle</span>
                            <span>添加新工具</span>
                        </a>
                        <a href="{{ url_for('tag.index_view') }}" class="quick-action-btn">
                            <span class="material-symbols-outlined">label</span>
                            <span>管理标签</span>
                        </a>
                        <a href="{{ url_for('news.create_view') }}" class="quick-action-btn">
                            <span class="material-symbols-outlined">post_add</span>
                            <span>发布新闻</span>
                        </a>
                        <a href="{{ url_for('index') }}" class="quick-action-btn" target="_blank">
                            <span class="material-symbols-outlined">open_in_new</span>
                            <span>查看网站</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 最近添加的工具 -->
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">最近添加的工具</h5>
                </div>
                <div class="card-body">
                    {% if recent_sites %}
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>名称</th>
                                    <th>URL</th>
                                    <th>浏览量</th>
                                    <th>状态</th>
                                    <th>添加时间</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for site in recent_sites %}
                                <tr>
                                    <td>
                                        <div class="d-flex align-items-center">
                                            {% if site.logo %}
                                            <img src="{{ site.logo }}" alt="{{ site.name }}" style="width: 32px; height: 32px; border-radius: 4px; margin-right: 12px; object-fit: cover;">
                                            {% endif %}
                                            <strong>{{ site.name }}</strong>
                                        </div>
                                    </td>
                                    <td>
                                        <a href="{{ site.url }}" target="_blank" style="color: #0052D9; text-decoration: none;">
                                            {{ site.url[:50] }}...
                                        </a>
                                    </td>
                                    <td>{{ site.view_count }}</td>
                                    <td>
                                        {% if site.is_active %}
                                        <span class="badge badge-success">已启用</span>
                                        {% else %}
                                        <span class="badge badge-secondary">已禁用</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ site.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <p class="text-muted text-center mb-0">暂无数据</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.dashboard-container {
    max-width: 1400px;
}

.stat-card {
    background: white;
    border: 1px solid #DCDFE6;
    border-radius: 6px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .05);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon .material-symbols-outlined {
    font-size: 28px;
}

.stat-info {
    flex: 1;
}

.stat-value {
    font-size: 28px;
    font-weight: 600;
    color: #000000;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: #606266;
}

.col-md-2-4 {
    flex: 0 0 20%;
    max-width: 20%;
}

@media (max-width: 768px) {
    .col-md-2-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media (max-width: 480px) {
    .col-md-2-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #F5F7FA;
    border: 1px solid #DCDFE6;
    border-radius: 6px;
    color: #000000;
    text-decoration: none;
    transition: all 0.2s;
}

.quick-action-btn:hover {
    background: #ECF2FE;
    border-color: #0052D9;
    color: #0052D9;
    text-decoration: none;
    transform: translateY(-2px);
}

.quick-action-btn .material-symbols-outlined {
    font-size: 24px;
}

.badge {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
}

.badge-success {
    background: rgba(0, 168, 112, 0.1);
    color: #00A870;
}

.badge-secondary {
    background: #F5F5F5;
    color: #606266;
}
</style>
{% endblock %}
