@php
    $breadcrumbs = [
        ['label' => __('common.home'), 'url' => route('dashboard.index')],
        ['label' => __('settings.title')],
        ['label' => __('rbac.users.title'), 'url' => route('settings.users.index')],
        ['label' => __('rbac.users.invite')],
    ];
@endphp

<x-ui.layout.page
    :title="__('rbac.users.invite_title')"
    :subtitle="__('rbac.users.invite_subtitle')"
    page-icon="fe fe-user-plus"
    :breadcrumbs="$breadcrumbs"
>
    <div class="card border-0 shadow-sm" style="max-width: 640px;">
        <div class="card-body p-4">
            <form method="POST" action="{{ route('settings.users.invite.store') }}" novalidate>
                @csrf
                <div class="mb-3">
                    <x-ui.form.input name="name" :label="__('rbac.users.columns.name')" :value="old('name')" required />
                </div>
                <div class="mb-3">
                    <x-ui.form.input name="email" type="email" :label="__('rbac.users.columns.email')" :value="old('email')" required />
                </div>
                <div class="mb-3">
                    <x-ui.form.search-select
                        name="employee_id"
                        lookup="employees"
                        :label="__('rbac.users.columns.employee')"
                        :options="$employeeOptions"
                        :selected="old('employee_id')"
                        :placeholder="__('rbac.users.placeholders.employee')"
                        optional
                    />
                </div>
                <div class="mb-4">
                    <label class="form-label">{{ __('rbac.users.columns.roles') }}</label>
                    <div class="d-flex flex-column gap-2">
                        @foreach ($roles as $role)
                            <label class="d-flex align-items-center gap-2 mb-0">
                                <input type="checkbox" name="role_ids[]" value="{{ $role->id }}"
                                    class="form-check-input @error('role_ids') is-invalid @enderror"
                                    @checked(in_array($role->id, old('role_ids', []), true))>
                                <span>{{ $role->name }}</span>
                            </label>
                        @endforeach
                    </div>
                    @error('role_ids')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                </div>
                <div class="d-flex justify-content-end gap-2">
                    <x-ui.buttons.secondary :href="route('settings.users.index')">{{ __('common.cancel') }}</x-ui.buttons.secondary>
                    <x-ui.buttons.primary type="submit" icon="fe fe-send">{{ __('rbac.users.invite') }}</x-ui.buttons.primary>
                </div>
            </form>
        </div>
    </div>
</x-ui.layout.page>
