<div class="card shadow-sm border-0">
    <div class="card-header d-flex justify-content-between align-items-center py-3">
        <div>
        <h5 class="mb-0">
            Permission: {{ $permission->name }}
        </h5>
            <small>{{ $permission->description }}</small>
    </div>
    </div>

    <div class="card-body p-4">
        <div class="row g-3">
            @foreach(Spatie\Permission\Models\Role::where('guard_name', $permission->guard_name)->get() as $role)
                <div class="col-sm-6 col-md-4">
                    <label class="card h-100 border transition-all hover-shadow p-3 mb-0" style="cursor: pointer;" for="role-{{ $role->id }}">
                        <div class="form-check form-switch d-flex align-items-center justify-content-between w-100 m-0 p-0">
                            <span class="fw-semibold text-dark">{{ ucfirst($role->name) }}</span>
                            <input
                                    class="form-check-input ms-0"
                                    type="checkbox"
                                    role="switch"
                                    id="role-{{ $role->id }}"
                                    value="{{ $role->name }}"
                                    wire:model.live="selectedRoles"
                                    style="cursor: pointer; float: none;"
                            >
                        </div>
                    </label>
                </div>
            @endforeach
        </div>
    </div>

    <div class="card-footer bg-light border-top-0 py-3">
        <div class="d-flex align-items-center justify-content-end">
            <div wire:loading wire:target="selectedRoles" class="me-3">
                <div class="spinner-border spinner-border-sm text-primary" role="status">
                    <span class="visually-hidden">Syncing...</span>
                </div>
                <span class="text-primary small ms-2 fw-medium">Syncing database...</span>
            </div>

            <div wire:loading.remove wire:target="selectedRoles">
                        <span class="text-success small fw-medium">
                            <i class="bi bi-cloud-check-fill me-1"></i>
                            All roles synchronized
                        </span>
            </div>
        </div>
    </div>

    <style>
        .transition-all { transition: all 0.2s ease-in-out; }
        .hover-shadow:hover { border-color: #0d6efd !important; background-color: #f8f9ff; }
        /* Fixing alignment by removing the default absolute positioning/padding of form-check-input in switches */
        .form-switch.d-flex .form-check-input {
            margin-left: 0;
            margin-top: 0;
            width: 2.5em;
            height: 1.25em;
        }
        .form-check-input:checked { background-color: #0d6efd; border-color: #0d6efd; }
    </style>
</div>