{% extends "base.html" %}

{% block title %}{{ _('Permisos') }} - {{ report.name }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h2">
            <i class="bi bi-shield-lock me-2"></i>{{ _('Permisos del Reporte') }}: {{ report.name }}
        </h1>
        <a href="{{ url_for('report.admin_index') }}" class="btn btn-outline-secondary">
            <i class="bi bi-arrow-left me-1"></i>{{ _('Volver') }}
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            <form method="post">
                <table class="table">
                    <thead>
                        <tr>
                            <th>{{ _('Rol') }}</th>
                            <th class="text-center">{{ _('Ver') }}</th>
                            <th class="text-center">{{ _('Ejecutar') }}</th>
                            <th class="text-center">{{ _('Exportar') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for role in roles %}
                        {% set perm = existing_permissions.get(role) %}
                        <tr>
                            <td>
                                <strong>{{ role|capitalize }}</strong>
                            </td>
                            <td class="text-center">
                                <input type="checkbox" class="form-check-input" name="{{ role }}_can_view" 
                                       {% if perm and perm.can_view %}checked{% endif %}>
                            </td>
                            <td class="text-center">
                                <input type="checkbox" class="form-check-input" name="{{ role }}_can_execute"
                                       {% if perm and perm.can_execute %}checked{% endif %}>
                            </td>
                            <td class="text-center">
                                <input type="checkbox" class="form-check-input" name="{{ role }}_can_export"
                                       {% if perm and perm.can_export %}checked{% endif %}>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>

                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-check-circle me-1"></i>{{ _('Guardar Permisos') }}
                    </button>
                    <a href="{{ url_for('report.admin_index') }}" class="btn btn-secondary">
                        {{ _('Cancelar') }}
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}
