{% extends "layouts/admin.twig" %}

{% block title %}{{ ta.dashboard|default('Dashboard') }} - {{ ta.admin_title|default('CodePress Admin') }}{% endblock %}

{% block content %}
<h2 class="mb-4"><i class="bi bi-speedometer2"></i> {{ ta.dashboard|default('Dashboard') }}</h2>

<div class="alert alert-light border mb-4">
    <strong>{{ ta.welcome|default('Welkom,') }} {{ user.username }}</strong> — {{ ta.logged_in_as|default('Ingelogd als') }} <span class="badge bg-{{ user_role == 'admin' ? 'danger' : (user_role == 'content-manager' ? 'primary' : (user_role == 'bi-manager' ? 'success' : 'warning')) }}">{{ role_label(user_role) }}</span>
</div>

<div class="row g-4">
    {# Site information #}
    <div class="col-md-6">
        <div class="card shadow-sm">
            <div class="card-header"><i class="bi bi-info-circle"></i> {{ ta.site_info|default('Site informatie') }}</div>
            <div class="card-body">
                <table class="table table-sm mb-0">
                    <tr><td class="text-muted">{{ ta.site_title|default('Site titel') }}</td><td>{{ site_config.site_title|default('CodePress') }}</td></tr>
                    <tr><td class="text-muted">{{ ta.default_lang|default('Standaard taal') }}</td><td>{{ site_config.language.default|default('nl') }}</td></tr>
                    <tr><td class="text-muted">{{ ta.cms_version|default('CodePress versie') }}</td><td>{{ stats.cms_version }}</td></tr>
                    <tr><td class="text-muted">{{ ta.php_version|default('PHP versie') }}</td><td>{{ stats.php_version }}</td></tr>
                    <tr><td class="text-muted">{{ ta.os|default('Besturingssysteem') }}</td><td>{{ stats.os }}</td></tr>
                    <tr><td class="text-muted">{{ ta.config_loaded|default('Config geladen') }}</td><td>{% if stats.config_exists %}<span class="badge bg-success">{{ ta.yes|default('Ja') }}</span>{% else %}<span class="badge bg-danger">{{ ta.no|default('Nee') }}</span>{% endif %}</td></tr>
                </table>
            </div>
        </div>
    </div>

    {# Content information #}
    {% if has_permission('content') %}
    <div class="col-md-6">
        <div class="card shadow-sm">
            <div class="card-header"><i class="bi bi-folder2-open"></i> {{ ta.content_info|default('Content informatie') }}</div>
            <div class="card-body">
                <table class="table table-sm mb-0">
                    <tr><td class="text-muted">{{ ta.pages|default('Pagina\'s') }}</td><td><span class="badge bg-primary">{{ stats.pages }}</span></td></tr>
                    <tr><td class="text-muted">{{ ta.folders|default('Mappen') }}</td><td><span class="badge bg-warning text-dark">{{ stats.directories }}</span></td></tr>
                    <tr><td class="text-muted">{{ ta.content_size|default('Content grootte') }}</td><td>{{ stats.content_size }}</td></tr>
                </table>
            </div>
        </div>
    </div>
    {% endif %}

    {# Plugins overview #}
    {% if has_permission('plugins') %}
    <div class="col-md-6">
        <div class="card shadow-sm">
            <div class="card-header d-flex justify-content-between align-items-center">
                <span><i class="bi bi-plug"></i> {{ ta.plugins|default('Plugins') }}</span>
                <a href="/admin/plugins" class="btn btn-sm btn-outline-secondary">{{ ta.manage|default('Beheren') }}</a>
            </div>
            <div class="card-body">
                <table class="table table-sm mb-0">
                    {% for pluginName, pluginInfo in plugin_overview %}
                    <tr>
                        <td>
                            <i class="bi bi-plug-fill"></i> {{ pluginName }}
                        </td>
                        <td>
                            {% if pluginInfo.enabled %}
                                <span class="badge bg-success">{{ ta.active|default('Actief') }}</span>
                            {% else %}
                                <span class="badge bg-secondary">{{ ta.inactive|default('Inactief') }}</span>
                            {% endif %}
                        </td>
                    </tr>
                    {% else %}
                    <tr><td colspan="2" class="text-muted text-center">{{ ta.no_plugins|default('Geen plugins gevonden.') }}</td></tr>
                    {% endfor %}
                </table>
            </div>
        </div>
    </div>
    {% endif %}
</div>
{% endblock %}