{% extends "admin/base.html" %}

{% block title %}Dashboard - Focomy{% endblock %}
{% block header_title %}Dashboard{% endblock %}

{% block content %}
<div class="grid grid-4 mb-2">
    {% for ct_name, ct in content_types.items() %}
    {% if ct.admin_menu %}
    <div class="stat-card">
        <div class="stat-label">{{ ct.label }}</div>
        <div class="stat-value">{{ stats.get(ct_name, 0) }}</div>
    </div>
    {% endif %}
    {% endfor %}
</div>

<div class="grid grid-2 mt-4">
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Recent Posts</h3>
        </div>
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>Title</th>
                        <th>Channel</th>
                        <th>Status</th>
                        <th>Created</th>
                    </tr>
                </thead>
                <tbody>
                    {% for post in recent_posts %}
                    <tr>
                        <td>
                            <a href="{{ AdminURL.entity_edit('post', post.id, post.channel_slug) }}">{{ post.title or 'Untitled' }}</a>
                        </td>
                        <td class="text-muted">{{ post.channel_title or '-' }}</td>
                        <td>
                            <span class="badge {% if post.status == 'published' %}badge-success{% else %}badge-warning{% endif %}">
                                {{ post.status or 'draft' }}
                            </span>
                        </td>
                        <td class="text-muted">{{ post.created_at[:10] if post.created_at else '-' }}</td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="4" class="text-muted text-center">No posts yet</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Quick Actions</h3>
        </div>
        <div class="flex gap-2" style="flex-wrap: wrap;">
            {% for ct_name, ct in content_types.items() %}
            {% if ct.admin_menu %}
            <a href="/admin/{{ ct_name }}/new" class="btn btn-secondary">
                New {{ ct.label }}
            </a>
            {% endif %}
            {% endfor %}
        </div>
    </div>
</div>

<div class="grid grid-1 mt-4">
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Focomy バージョン</h3>
        </div>
        <div class="card-body">
            {% if update_info.has_update %}
            <div class="alert alert-warning mb-2">
                <strong>新バージョン {{ update_info.latest_version }} が利用可能です</strong>
                {% if update_info.release_url %}
                <a href="{{ update_info.release_url }}" target="_blank" class="ml-2">リリースノート →</a>
                {% endif %}
            </div>
            <p class="text-muted mb-1">アップデート方法:</p>
            <code>pip install --upgrade focomy</code>
            {% else %}
            <span class="badge badge-success">最新バージョン ({{ update_info.current_version }})</span>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
