{% extends "base.html" %}
{% from "components/cards.html" import info_card %}

{% block content %}
<div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-6">
    <div>
        <h1 class="text-2xl font-bold">Admin Dashboard</h1>
        <p class="text-text-muted-light dark:text-text-muted-dark">System overview and management.</p>
    </div>
</div>

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6">
    {{ info_card("Total Users", stats.total_users, "All time") }}
    {{ info_card("Active Users", stats.active_users, "Currently active") }}
    {{ info_card("Total Projects", stats.total_projects, "All time") }}
    {{ info_card("Active Projects", stats.active_projects, "Currently active") }}
</div>

<div class="bg-card-light dark:bg-card-dark p-6 rounded-lg shadow mb-6">
    <h2 class="text-lg font-semibold mb-4">Admin Sections</h2>
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
        <a href="{{ url_for('admin.list_users') }}" class="bg-primary text-white p-4 rounded-lg text-center hover:bg-blue-600">
            <i class="fas fa-users mb-2"></i>
            <div>Manage Users</div>
        </a>
        <a href="{{ url_for('permissions.list_roles') }}" class="bg-primary text-white p-4 rounded-lg text-center hover:bg-blue-600">
            <i class="fas fa-shield-alt mb-2"></i>
            <div>Roles & Permissions</div>
        </a>
        <a href="{{ url_for('admin.api_tokens') }}" class="bg-green-600 text-white p-4 rounded-lg text-center hover:bg-green-700">
            <i class="fas fa-key mb-2"></i>
            <div>API Tokens</div>
            <div class="text-xs mt-1 opacity-90">REST API Access</div>
        </a>
        <a href="{{ url_for('admin.email_support') }}" class="bg-purple-600 text-white p-4 rounded-lg text-center hover:bg-purple-700">
            <i class="fas fa-envelope mb-2"></i>
            <div>Email Configuration</div>
            <div class="text-xs mt-1 opacity-90">Test & Configure</div>
        </a>
        <a href="{{ url_for('admin.settings') }}" class="bg-primary text-white p-4 rounded-lg text-center hover:bg-blue-600">
            <i class="fas fa-cog mb-2"></i>
            <div>Settings</div>
        </a>
        <a href="{{ url_for('admin.system_info') }}" class="bg-primary text-white p-4 rounded-lg text-center hover:bg-blue-600">
            <i class="fas fa-info-circle mb-2"></i>
            <div>System Info</div>
        </a>
    </div>
</div>

<div class="bg-card-light dark:bg-card-dark p-6 rounded-lg shadow overflow-x-auto">
    <h2 class="text-lg font-semibold mb-4">Recent Activity</h2>
    <table class="w-full text-left">
        <thead class="border-b border-border-light dark:border-border-dark">
            <tr>
                <th class="p-4">User</th>
                <th class="p-4">Project</th>
                <th class="p-4">Duration</th>
                <th class="p-4">Date</th>
            </tr>
        </thead>
        <tbody>
            {% for entry in recent_entries %}
            <tr class="border-b border-border-light dark:border-border-dark">
                <td class="p-4">{{ entry.user.username }}</td>
                <td class="p-4">{{ entry.project.name }}</td>
                <td class="p-4">{{ entry.duration }}</td>
                <td class="p-4">{{ entry.start_time.strftime('%Y-%m-%d') }}</td>
            </tr>
            {% else %}
            <tr>
                <td colspan="4" class="p-4 text-center text-text-muted-light dark:text-text-muted-dark">No recent activity.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}
