<x-layouts.tenant pageTitle="Plantillas de consentimiento">
    <x-page-header title="Plantillas de consentimiento" subtitle="Gestiona las plantillas de consentimientos informados de tu empresa.">
        <x-btn href="{{ route('tenant.consent-templates.create') }}" variant="primary">+ Nueva plantilla</x-btn>
    </x-page-header>

    @if(session('success'))
        <div class="mb-4 bg-green-50 border border-green-200 text-green-800 rounded-lg px-4 py-3 text-sm">{{ session('success') }}</div>
    @endif

    <x-card>
        @forelse($templates as $template)
            <div class="flex items-center justify-between border-b border-gray-100 py-4 last:border-0">
                <div>
                    <p class="text-sm font-semibold text-gray-800">{{ $template->title }}</p>
                    <p class="text-xs text-gray-500 mt-0.5">
                        Actualizada {{ $template->updated_at->format('d/m/Y') }} ·
                        @if($template->requires_signature)
                            <span class="text-indigo-600">Requiere firma</span>
                        @else
                            <span class="text-gray-400">Sin firma requerida</span>
                        @endif
                    </p>
                </div>
                <div class="flex items-center gap-3">
                    <span class="text-xs px-2 py-0.5 rounded-full
                        {{ $template->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-400' }}">
                        {{ $template->is_active ? 'Activa' : 'Inactiva' }}
                    </span>
                    <a href="{{ route('tenant.consent-templates.edit', $template) }}"
                       class="text-xs text-indigo-600 hover:underline">Editar</a>
                    <form method="POST" action="{{ route('tenant.consent-templates.destroy', $template) }}"
                          onsubmit="return confirm('¿Eliminar esta plantilla?')">
                        @csrf @method('DELETE')
                        <button type="submit" class="text-xs text-red-400 hover:text-red-600">Eliminar</button>
                    </form>
                </div>
            </div>
        @empty
            <p class="text-center text-sm text-gray-400 py-8">No hay plantillas creadas.</p>
        @endforelse

        @if($templates->hasPages())
            <div class="mt-4">{{ $templates->links() }}</div>
        @endif
    </x-card>
</x-layouts.tenant>
