{% extends 'base.html' %}
{% from 'macros.html' import render_messages %}

{% block content %}
<div class="container">
    {{ render_messages() }}

    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>{{ _('Plugins') }}</h2>
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>{{ _('Paquete') }}</th>
                            <th>{{ _('Versión') }}</th>
                            <th>{{ _('Instalado') }}</th>
                            <th>{{ _('Estado') }}</th>
                            <th>{{ _('Acciones') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for plugin in plugins %}
                        <tr>
                            <td><strong>{{ plugin.distribution_name }}</strong></td>
                            <td>{{ plugin.version or '-' }}</td>
                            <td>
                                {% if plugin.installed %}
                                    <span class="badge bg-success">{{ _('Sí') }}</span>
                                {% else %}
                                    <span class="badge bg-secondary">{{ _('No') }}</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if plugin.active %}
                                    <span class="badge bg-success">{{ _('Activo') }}</span>
                                {% else %}
                                    <span class="badge bg-warning">{{ _('Inactivo') }}</span>
                                {% endif %}
                            </td>
                            <td>
                                <form action="{{ url_for('plugins.toggle', plugin_id=plugin.id) }}" method="POST" class="d-inline">
                                    {% if plugin.active %}
                                        <button type="submit" class="btn btn-sm btn-outline-warning">
                                            <i class="bi bi-toggle-off"></i>
                                            {{ _('Desactivar') }}
                                        </button>
                                    {% else %}
                                        <button type="submit" class="btn btn-sm btn-outline-success" {% if not plugin.installed %}disabled{% endif %}>
                                            <i class="bi bi-toggle-on"></i>
                                            {{ _('Activar') }}
                                        </button>
                                    {% endif %}
                                </form>
                            </td>
                        </tr>
                        {% else %}
                        <tr>
                            <td colspan="5" class="text-center text-muted">{{ _('No se encontraron plugins.') }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
