<x-admin-layout title="Roles">
    <div class="card">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h5 class="fw-bold mb-0">Roles</h5>
                <a href="{{ route('admin.roles.create') }}" class="btn btn-dark btn-sm">
                    <i class="bi bi-plus-lg me-1"></i>Add Role
                </a>
            </div>

            @if ($roles->isEmpty())
                <div class="text-center text-muted py-5">
                    <i class="bi bi-shield-lock fs-1 d-block mb-2"></i>
                    No roles yet.
                </div>
            @else
                <div class="table-responsive">
                    <table class="table align-middle datatable">
                        <thead>
                            <tr>
                                <th>Role</th>
                                <th>Key</th>
                                <th>Users</th>
                                <th class="text-end">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($roles as $role)
                                <tr>
                                    <td class="fw-semibold">{{ $role->label }}</td>
                                    <td><code>{{ $role->name }}</code></td>
                                    <td>{{ $role->users_count }}</td>
                                    <td class="text-end">
                                        <a href="{{ route('admin.roles.edit', $role) }}" class="btn btn-sm btn-outline-secondary">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form method="POST" action="{{ route('admin.roles.destroy', $role) }}" class="d-inline"
                                              data-confirm-title="Delete role?" data-confirm-text="Delete {{ $role->label }}? This cannot be undone."
                                              data-confirm-button="Delete">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif
        </div>
    </div>
</x-admin-layout>
