@props([
    'action',
    'method' => 'POST',
    'department' => null,
    'parentOptions' => [],
    'submitLabel',
])

<form method="POST" action="{{ $action }}" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                @if ($department !== null)
                    <div class="col-md-4">
                        <x-ui.form.reference
                            :label="__('departments.fields.reference')"
                            :value="$department->code"
                        />
                    </div>
                @endif
                <div class="{{ $department !== null ? 'col-md-4' : 'col-md-6' }}">
                    <x-ui.form.input
                        name="name"
                        :label="__('departments.fields.name')"
                        :value="$department?->name"
                        :placeholder="__('departments.placeholders.name')"
                        required
                    />
                </div>

                <div class="{{ $department !== null ? 'col-md-4' : 'col-md-6' }}">
                    <x-ui.form.search-select
                        name="parent_id"
                        lookup="departments"
                        :lookup-exclude="$department?->id"
                        :label="__('departments.fields.parent')"
                        :options="$parentOptions"
                        :selected="$department?->parent_id"
                        :placeholder="__('departments.placeholders.parent')"
                    />
                </div>

                <div class="col-12">
                    <x-ui.form.input
                        name="description"
                        :label="__('departments.fields.description')"
                        :value="$department?->description"
                        :placeholder="__('departments.placeholders.description')"
                        optional
                    />
                </div>

                <div class="col-12">
                    <x-ui.form.select
                        name="is_active"
                        :label="__('departments.fields.status')"
                        :options="[
                            1 => __('departments.status.active'),
                            0 => __('departments.status.inactive'),
                        ]"
                        :selected="$department?->is_active ?? 1"
                        required
                    />
                </div>
            </div>
        </div>

        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('hr.departments.index')">
                {{ __('common.cancel') }}
            </x-ui.buttons.secondary>

            <x-ui.buttons.primary type="submit" icon="fe fe-save">
                {{ $submitLabel }}
            </x-ui.buttons.primary>
        </div>
    </div>
</form>
