<div class="role-create">
    <x-title>
        Create Role
    </x-title>

    <div class="row">
        <div class="col-12 col-md-9">
            <div class="card">
                <div class="card-body">

                    {{-- ROLE NAME --}}
                    <div class="mb-4">
                        <label class="form-label">Role Name</label>
                        <input type="text"
                               class="form-control"
                               wire:model.defer="name"
                               placeholder="e.g. Support Agent">

                        @error('name')
                        <div class="text-danger small">{{ $message }}</div>
                        @enderror
                    </div>

                    {{-- PERMISSIONS --}}
                    <h4 class="mb-3">Permissions</h4>

                    @foreach($permissionGroups as $group => $permissions)
                        <div class="card mb-3 border">
                            <div class="card-header bg-light fw-semibold">
                                {{ $group }}
                            </div>

                            <div class="card-body">
                                @foreach($permissions as $permission)
                                    <div class="form-check mb-2">
                                        <input class="form-check-input"
                                               type="checkbox"
                                               wire:model.defer="permissions"
                                               value="{{ $permission->name }}"
                                               id="perm_{{ $permission->id }}">

                                        <label class="form-check-label"
                                               for="perm_{{ $permission->id }}">
                                            <strong>{{ $permission->label }}</strong>

                                            <div class="text-muted small">
                                                {{ $permission->description }}
                                            </div>

                                            <code class="small text-muted">
                                                {{ $permission->name }}
                                            </code>
                                        </label>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                    @endforeach


                    {{-- ACTIONS --}}
                    <div class="d-flex justify-content-end mt-4">
                        <button class="btn btn-success"
                                wire:click="save">
                            Create Role
                        </button>
                    </div>

                </div>
            </div>
        </div>

        {{-- SIDEBAR --}}
        <div class="col-12 col-md-3">
            <div class="card">
                <div class="card-body">
                    <h4 class="card-title">Guidance</h4>
                    <hr>

                    <p class="text-muted small">
                        Roles define what users are allowed to do.
                        Grant the minimum permissions necessary.
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
