<div>
    <x-slot name="header">
        <h2 class="text-xl font-semibold leading-tight text-gray-800">
            Permisos del sistema
        </h2>
    </x-slot>

    <div class="py-6">
        <div class="mx-auto max-w-8xl sm:px-6 lg:px-8 mt-2">

            <div class="mb-4 flex items-center justify-between">
                <div class="w-1/3">
                    <input
                        type="text"
                        wire:model.live.debounce.300ms="search"
                        placeholder="Buscar permiso..."
                        class="w-full rounded border px-3 py-2"
                    >
                </div>

                <a href="{{ route('permissions.create') }}"
                   class="rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700">
                    Crear permiso
                </a>
            </div>

            <div class="bg-white shadow rounded p-6">

                <table class="min-w-full text-sm">
                    <thead>
                    <tr class="border-b text-left font-semibold">
                        <th class="px-3 py-2">ID</th>
                        <th class="px-3 py-2">Nombre</th>
                        <th class="px-3 py-2">Módulo</th>
                        <th class="px-3 py-2">Descripción</th>
                        <th class="px-3 py-2">Creado</th>
                        <th class="px-3 py-2">Actualizado</th>
                        <th class="px-3 py-2 text-right">Acciones</th>
                    </tr>
                    </thead>

                    <tbody>
                    @forelse($permissions as $perm)
                        <tr class="border-b hover:bg-gray-50">
                            <td class="px-3 py-2">{{ $perm->id }}</td>

                            <td class="px-3 py-2 font-mono text-blue-700">
                                {{ $perm->name }}
                            </td>

                            <td class="px-3 py-2">
                                {{ $perm->model ?? '—' }}
                            </td>

                            <td class="px-3 py-2">
                                {{ $perm->description ?? '—' }}
                            </td>

                            <td class="px-3 py-2 text-gray-500">
                                {{ $perm->created_at->format('Y-m-d') }}
                            </td>

                            <td class="px-3 py-2 text-gray-500">
                                {{ $perm->updated_at->format('Y-m-d') }}
                            </td>

                            <td class="px-3 py-2 text-right">
                                <a href="{{ route('permissions.edit', $perm) }}"
                                   class="text-blue-600 hover:text-blue-800">
                                    Editar
                                </a>
                            </td>
                        </tr>

                    @empty
                        <tr>
                            <td colspan="7" class="py-4 text-center text-gray-500">
                                No se encontraron permisos.
                            </td>
                        </tr>
                    @endforelse
                    </tbody>
                </table>

                <div class="mt-4">
                    {{ $permissions->links() }}
                </div>

            </div>
        </div>
    </div>
</div>

