@extends('layouts.app')
@section('title', 'Roles & Permissions')
@section('page_title', 'Roles & Permissions')
@section('breadcrumbs')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Home</a></li>
    <li class="breadcrumb-item active">Roles</li>
@endsection
@section('page_actions')
    @can('roles.create')
        <a href="{{ route('roles.create') }}" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i>Add Role</a>
    @endcan
@endsection

@section('content')
    <div class="row g-3">
        @foreach($roles as $role)
            <div class="col-md-6 col-xl-4">
                <div class="card h-100">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-start">
                            <div>
                                <h6 class="mb-1"><i class="bi bi-shield-lock text-primary me-1"></i>{{ $role->name }}</h6>
                                <div class="small text-muted">{{ $role->users_count }} user(s)</div>
                            </div>
                            <span class="badge bg-soft-info">{{ $role->permissions_count }} perms</span>
                        </div>
                        <div class="mt-3 d-flex gap-2">
                            @can('roles.update')
                                <a href="{{ route('roles.edit', $role) }}" class="btn btn-sm btn-light border"><i class="bi bi-pencil me-1"></i>Edit</a>
                            @endcan
                            @can('roles.delete')
                                @if($role->name !== \App\Models\User::SUPER_ADMIN)
                                    <form method="POST" action="{{ route('roles.destroy', $role) }}" data-confirm="Delete role “{{ $role->name }}”?">
                                        @csrf @method('DELETE')
                                        <button class="btn btn-sm btn-light border text-danger"><i class="bi bi-trash"></i></button>
                                    </form>
                                @endif
                            @endcan
                        </div>
                    </div>
                </div>
            </div>
        @endforeach
    </div>
@endsection
