<div class="user-create">
    <x-title>
        Create User
    </x-title>

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

                    <div class="row mb-3">
                        <div class="col-6">
                            <x-ui.input name="name_first" label="First Name"/>
                        </div>

                        <div class="col-6">
                            <x-ui.input name="name_last" label="Last Name"/>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-6">
                            <x-ui.input name="email" type="email" label="Email Address"/>
                        </div>

                        <div class="col-6">
                            <x-ui.input name="username" label="Username"/>
                        </div>
                    </div>

                    <div class="mb-3">
                        <x-ui.input name="password" label="Password" type="password"/>
                    </div>

                    <div class="mb-4">
                        <label class="form-label">Roles</label>
                        <div class="d-flex flex-wrap gap-3">
                            @foreach($roles as $role)
                                <div class="form-check">
                                    <input class="form-check-input"
                                           type="checkbox"
                                           wire:model.defer="selectedRoles[]"
                                           value="{{ $role->name }}">
                                    <label class="form-check-label">
                                        {{ $role->name }}
                                    </label>
                                </div>
                            @endforeach
                        </div>
                    </div>

                    <div class="mb-4">
                        <label class="form-label">Workspace Access</label>

                        <div class="form-check mb-2">
                            <input class="form-check-input"
                                   type="checkbox"
                                   id="allWorkspaces"
                                   wire:model.live="allWorkspaces">
                            <label class="form-check-label" for="allWorkspaces">
                                All workspaces (no restriction)
                            </label>
                        </div>

                        <div class="d-flex flex-wrap gap-3 ps-3">
                            @foreach(\App\Components\Admin\Users\UserEdit::WORKSPACES as $ws)
                                <div class="form-check">
                                    <input class="form-check-input"
                                           type="checkbox"
                                           wire:model.defer="allowedWorkspaces"
                                           value="{{ $ws }}"
                                           @if($allWorkspaces) disabled @endif>
                                    <label class="form-check-label">
                                        {{ strtoupper($ws) }}
                                    </label>
                                </div>
                            @endforeach
                        </div>

                        <p class="text-muted small mt-2 mb-0">
                            When restricted, the user can only switch to and access the ticked workspaces.
                            The <code>workspaces.override</code> permission bypasses this whitelist entirely.
                        </p>
                    </div>

                    <div class="d-flex justify-content-end">
                        <button class="btn btn-success"
                                wire:click="save">
                            Create User
                        </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 mb-0">
                        Assign roles carefully. Permissions are inherited
                        automatically from roles.
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
