@extends('layouts.app')

@section('content')
<div class="container mx-auto max-w-5xl px-4">
    @include('admin.panel._nav')

    <div class="mb-4 flex items-center justify-between">
        <h1 class="text-xl font-semibold text-gray-900">Permission</h1>
        <a href="{{ route('admin.permissions.create') }}" class="rounded bg-gray-900 px-3 py-2 text-sm text-white hover:bg-gray-700">
            Tambah Permission
        </a>
    </div>

    <div class="overflow-x-auto rounded border border-gray-200">
        <table class="min-w-full text-sm">
            <thead class="bg-gray-50 text-left text-gray-600">
                <tr>
                    <th class="px-4 py-2">Nama</th>
                    <th class="px-4 py-2">Jumlah Role</th>
                    <th class="px-4 py-2">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @forelse ($permissions as $permission)
                    <tr class="border-t border-gray-100">
                        <td class="px-4 py-2">{{ $permission->name }}</td>
                        <td class="px-4 py-2">{{ $permission->roles_count }}</td>
                        <td class="px-4 py-2">
                            <div class="flex flex-wrap gap-2">
                                <a href="{{ route('admin.permissions.edit', $permission) }}" class="text-blue-600 hover:underline">Edit</a>
                                <form method="POST" action="{{ route('admin.permissions.destroy', $permission) }}"
                                      onsubmit="return confirm('Hapus permission ini?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-600 hover:underline">Hapus</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="px-4 py-6 text-center text-gray-500">Belum ada permission.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

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