@props(['employee' => null])

<div class="row g-3" data-geo-cascade>
    @if ($employee !== null)
        <div class="col-md-4">
            <x-ui.form.reference
                :label="__('employees.fields.employee_reference')"
                :value="$employee->employee_code"
            />
        </div>
    @endif
    <div class="{{ $employee !== null ? 'col-md-4' : 'col-md-6' }}">
        <x-ui.form.input
            name="full_name"
            :label="__('employees.fields.full_name')"
            :value="$employee?->full_name"
            :placeholder="__('employees.placeholders.full_name')"
            required
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="arabic_name"
            :label="__('employees.fields.arabic_name')"
            :value="$employee?->arabic_name"
            :placeholder="__('employees.placeholders.arabic_name')"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="fingerprint_id"
            :label="__('employees.fields.fingerprint_id')"
            :value="$employee?->fingerprint_id"
            :placeholder="__('employees.placeholders.fingerprint_id')"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="email"
            type="email"
            :label="__('employees.fields.email')"
            :value="$employee?->email"
            :placeholder="__('employees.placeholders.email')"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="company_email"
            type="email"
            :label="__('employees.fields.company_email')"
            :value="$employee?->company_email"
            :placeholder="__('employees.placeholders.company_email')"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="phone_1"
            :label="__('employees.fields.phone_1')"
            :value="$employee?->phone_1"
            :placeholder="__('employees.placeholders.phone_1')"
            required
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="phone_2"
            :label="__('employees.fields.phone_2')"
            :value="$employee?->phone_2"
            :placeholder="__('employees.placeholders.phone_2')"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.search-select
            name="department_id"
            lookup="departments"
            :label="__('employees.fields.department')"
            :options="$departmentOptions"
            :selected="$employee?->department_id"
            :placeholder="__('employees.placeholders.department')"
            required
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.search-select
            name="position_id"
            lookup="positions"
            lookup-parent="department_id"
            :label="__('employees.fields.position')"
            :options="$positionOptions"
            :selected="$employee?->position_id"
            :placeholder="__('employees.placeholders.position')"
            required
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.search-select
            name="manager_employee_id"
            lookup="employees"
            :lookup-exclude="$employee?->id"
            :label="__('employees.fields.manager')"
            :options="$managerOptions"
            :selected="old('manager_employee_id', $employee?->manager_employee_id)"
            :placeholder="__('employees.placeholders.manager')"
            optional
        />
    </div>
    @foreach ([
        ['branch_id', __('employees.fields.branch'), $branchOptions ?? [], $employee?->branch_id],
        ['section_id', __('employees.fields.section'), $sectionOptions ?? [], $employee?->section_id],
        ['team_id', __('employees.fields.team'), $teamOptions ?? [], $employee?->team_id],
        ['job_grade_id', __('employees.fields.job_grade'), $jobGradeOptions ?? [], $employee?->job_grade_id],
        ['work_location_id', __('employees.fields.work_location'), $workLocationOptions ?? [], $employee?->work_location_id],
        ['cost_center_id', __('employees.fields.cost_center'), $costCenterOptions ?? [], $employee?->cost_center_id],
    ] as [$field, $label, $options, $selected])
        <div class="col-md-4">
            <x-ui.form.select :name="$field" :label="$label" :options="$options" :selected="old($field, $selected)" optional />
        </div>
    @endforeach
    @can('employees.salary.view')
        <div class="col-md-4">
            <x-ui.form.input
                name="salary"
                type="number"
                step="0.01"
                min="0"
                :label="__('employees.fields.salary')"
                :value="old('salary', $employee !== null ? $employee->salary : null)"
                :placeholder="__('employees.placeholders.salary')"
                required
            />
        </div>
        <div class="col-md-4">
            <x-ui.form.search-select
                name="salary_structure_id"
                :label="__('employees.fields.salary_structure')"
                lookup="salary_structures"
                :selected="old('salary_structure_id', $employee?->salary_structure_id)"
                optional
            />
        </div>
        <div class="col-md-4">
            <x-ui.form.select
                name="payment_method"
                :label="__('employees.fields.payment_method')"
                :options="[
                    'bank_transfer' => __('employees.payment_methods.bank_transfer'),
                    'cash' => __('employees.payment_methods.cash'),
                    'cheque' => __('employees.payment_methods.cheque'),
                    'other' => __('employees.payment_methods.other'),
                ]"
                :selected="old('payment_method', $employee?->payment_method)"
                :placeholder="__('common.select')"
                optional
            />
        </div>
        <div class="col-md-4">
            <x-ui.form.input
                name="currency"
                :label="__('employees.fields.currency')"
                :value="old('currency', $employee?->currency ?? 'SAR')"
                maxlength="3"
                optional
            />
        </div>
    @endcan
    <div class="col-md-4">
        <x-ui.form.input
            name="hire_date"
            type="date"
            :label="__('employees.fields.hire_date')"
            :value="old('hire_date', $employee?->hire_date?->format('Y-m-d'))"
            required
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.input
            name="probation_end_date"
            type="date"
            :label="__('employees.fields.probation_end_date')"
            :value="old('probation_end_date', $employee?->probation_end_date?->format('Y-m-d'))"
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.input
            name="confirmation_date"
            type="date"
            :label="__('employees.fields.confirmation_date')"
            :value="old('confirmation_date', $employee?->confirmation_date?->format('Y-m-d'))"
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.select
            name="gender"
            :label="__('employees.fields.gender')"
            :options="[
                'male' => __('employees.gender.male'),
                'female' => __('employees.gender.female'),
                'other' => __('employees.gender.other'),
            ]"
            :selected="old('gender', $employee?->gender)"
            required
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.input
            name="date_of_birth"
            type="date"
            :label="__('employees.fields.date_of_birth')"
            :value="old('date_of_birth', $employee?->date_of_birth?->format('Y-m-d'))"
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.select
            name="marital_status"
            :label="__('employees.fields.marital_status')"
            :options="[
                '' => __('common.select'),
                'single' => __('employees.marital.single'),
                'married' => __('employees.marital.married'),
                'divorced' => __('employees.marital.divorced'),
                'widowed' => __('employees.marital.widowed'),
            ]"
            :selected="old('marital_status', $employee?->marital_status)"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="nationality"
            :label="__('employees.fields.nationality')"
            :value="$employee?->nationality"
            :placeholder="__('employees.placeholders.nationality')"
        />
    </div>
    <div class="col-md-3">
        <x-ui.form.select name="blood_type" :label="__('employees.fields.blood_type')"
            :options="array_combine(['A+','A-','B+','B-','AB+','AB-','O+','O-'], ['A+','A-','B+','B-','AB+','AB-','O+','O-'])"
            :selected="old('blood_type', $employee?->blood_type)" optional />
    </div>
    <div class="col-md-3">
        <x-ui.form.input name="religion" :label="__('employees.fields.religion')" :value="$employee?->religion" />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="national_id"
            :label="__('employees.fields.national_id')"
            :value="$employee?->national_id"
            :placeholder="__('employees.placeholders.national_id')"
            required
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="passport_number"
            :label="__('employees.fields.passport_number')"
            :value="$employee?->passport_number"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input
            name="social_insurance_number"
            :label="__('employees.fields.social_insurance_number')"
            :value="$employee?->social_insurance_number"
        />
    </div>
    <div class="col-md-6">
        <x-ui.form.input name="tax_number" :label="__('employees.fields.tax_number')" :value="$employee?->tax_number" />
    </div>
    <div class="col-md-4">
        <x-ui.form.input
            name="bank_name"
            :label="__('employees.fields.bank_name')"
            :value="$employee?->bank_name"
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.input
            name="bank_account_number"
            :label="__('employees.fields.bank_account_number')"
            :value="$employee?->bank_account_number"
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.input
            name="iban"
            :label="__('employees.fields.iban')"
            :value="$employee?->iban"
        />
    </div>
    <div class="col-md-4">
        <x-ui.form.input name="swift_code" :label="__('employees.fields.swift_code')" :value="$employee?->swift_code" />
    </div>
    <div class="col-md-6">
        <x-ui.form.search-select
            name="employment_status_id"
            lookup="employment_statuses"
            :label="__('employees.fields.employment_status')"
            :options="$employmentStatusOptions ?? []"
            :selected="old('employment_status_id', $employee?->employment_status_id ?? ($defaultEmploymentStatusId ?? null))"
            :placeholder="__('employees.placeholders.employment_status')"
            required
        />
    </div>
    @if ($employee !== null)
        <div class="col-md-6">
            <x-ui.form.select
                name="is_active"
                :label="__('employees.fields.status')"
                :options="[
                    1 => __('employees.status.active'),
                    0 => __('employees.status.inactive'),
                ]"
                :selected="$employee->is_active ? 1 : 0"
                required
            />
        </div>
    @endif
</div>
