<x-app-layout>
    <x-slot name="header">{{ __('Roles & Permissions') }}</x-slot>

    <div class="mb-3 d-flex justify-content-between align-items-center">
        <span class="text-muted small">{{ $roles->count() }} {{ __('roles') }}</span>
        <a href="{{ route('roles.create') }}" class="btn btn-primary btn-sm">
            <i class="bi bi-shield-plus me-1"></i>{{ __('Add Role') }}
        </a>
    </div>

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-dark">
                    <tr>
                        <th>#</th>
                        <th>{{ __('Role Name') }}</th>
                        <th>{{ __('Permissions') }}</th>
                        <th>{{ __('Users') }}</th>
                        <th class="text-end">{{ __('Actions') }}</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($roles as $role)
                    <tr>
                        <td>{{ $loop->iteration }}</td>
                        <td><strong>{{ $role->name }}</strong></td>
                        <td><span class="badge bg-secondary">{{ $role->permissions_count }}</span></td>
                        <td><span class="badge bg-primary">{{ $role->users_count }}</span></td>
                        <td class="text-end">
                            <a href="{{ route('roles.edit', $role) }}" class="btn btn-sm btn-outline-primary">
                                <i class="bi bi-pencil"></i>
                            </a>
                            <form method="POST" action="{{ route('roles.destroy', $role) }}" class="d-inline" onsubmit="return confirm('{{ __('Delete this role?') }}')">
                                @csrf @method('DELETE')
                                <button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
                            </form>
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="5" class="text-center text-muted py-4">{{ __('No roles found.') }}</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</x-app-layout>
