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

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

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-plug"></i> {{ ta.plugins|default('Plugins') }}</h2>
    <a href="/admin/plugins-new" class="btn btn-primary btn-sm">
        <i class="bi bi-plus-lg"></i> {{ ta.new_plugin|default('Nieuwe plugin') }}
    </a>
</div>

<div class="row g-4">
    {% for plugin in plugins %}
    <div class="col-md-6 col-lg-4">
        <div class="card shadow-sm h-100 {% if plugin.type == 'system' %}border-primary{% elseif plugin.type == 'content' %}border-success{% endif %}">
            <div class="card-header d-flex justify-content-between align-items-center">
                <span class="fw-bold">
                    {% if plugin.type == 'system' %}<i class="bi bi-gear-fill text-primary"></i>
                    {% elseif plugin.type == 'content' %}<i class="bi bi-puzzle-fill text-success"></i>
                    {% else %}<i class="bi bi-plug-fill"></i>{% endif %}
                    {{ plugin.name|default(plugin.name) }}
                </span>
                <div class="d-flex gap-1">
                    {% if plugin.type == 'system' %}
                        <span class="badge bg-primary">{{ ta.plugin_type_system|default('Systeem') }}</span>
                    {% elseif plugin.type == 'content' %}
                        <span class="badge bg-success">{{ ta.plugin_type_content|default('Content') }}</span>
                    {% endif %}
                    <span class="badge bg-{{ plugin.enabled ? 'success' : 'secondary' }}">{{ plugin.enabled ? ta.active|default('Actief') : ta.inactive|default('Inactief') }}</span>
                </div>
            </div>
            <div class="card-body">
                <p class="card-text text-muted mb-2">{{ plugin.description|default(ta.no_description|default('Geen beschrijving')) }}</p>
                <p class="small text-muted mb-3">
                    {% if plugin.version %}<span class="badge bg-info">v{{ plugin.version }}</span>{% endif %}
                    {% if plugin.author %}<span class="badge bg-secondary">{{ plugin.author }}</span>{% endif %}
                </p>
            </div>
            <div class="card-footer bg-white">
                <div class="btn-group w-100" role="group">
                    {% if plugin.protected or plugin.essential %}
                        <span class="btn btn-sm btn-outline-secondary disabled" title="{{ ta.essential_title|default('Essentiële plugin - kan niet worden bewerkt, gedeactiveerd of verwijderd') }}">
                            <i class="bi bi-shield-check"></i> {{ ta.essential|default('Essentieel') }}
                        </span>
                    {% else %}
                    <a href="/admin/plugins-edit?plugin={{ plugin.name|url_encode }}" class="btn btn-sm btn-outline-primary">
                        <i class="bi bi-pencil"></i> {{ ta.edit|default('Bewerken') }}
                    </a>
                    {% if plugin.hasConfig %}
                    <a href="/admin/plugins-config?plugin={{ plugin.name|url_encode }}" class="btn btn-sm btn-outline-info">
                        <i class="bi bi-gear"></i> {{ ta.config|default('Config') }}
                    </a>
                    {% endif %}
                    <form method="POST" action="/admin/plugins-toggle" class="d-inline">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
                        <input type="hidden" name="plugin" value="{{ plugin.name }}">
                        <button type="submit" class="btn btn-sm btn-{{ plugin.enabled ? 'outline-warning' : 'outline-success' }}">
                            <i class="bi bi-{{ plugin.enabled ? 'pause' : 'play' }}"></i> {{ plugin.enabled ? ta.deactivate|default('Deactiveren') : ta.activate|default('Activeren') }}
                        </button>
                    </form>
                    <form method="POST" action="/admin/plugins-delete" class="d-inline" onsubmit="return confirm('{{ ta.confirm_delete_plugin|default('Weet je zeker dat je deze plugin wilt verwijderen?') }}')">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
                        <input type="hidden" name="plugin" value="{{ plugin.name }}">
                        <button type="submit" class="btn btn-sm btn-outline-danger">
                            <i class="bi bi-trash"></i>
                        </button>
                    </form>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    {% else %}
    <div class="col-12">
        <div class="alert alert-info">
            <i class="bi bi-info-circle"></i> {{ ta.no_plugins|default('Geen plugins gevonden. Maak een nieuwe plugin aan om te beginnen.') }}
        </div>
    </div>
    {% endfor %}
</div>
{% endblock %}