<script setup lang="ts">
import { Head, Link } from '@inertiajs/vue3';
import { ArrowLeft } from '@lucide/vue';
import { computed } from 'vue';
import EmployeeForm from '@/components/hr/EmployeeForm.vue';
import { Button } from '@/components/ui/button';
import AdminLayout from '@/layouts/AdminLayout.vue';
import type { EmployeeEditItem, EnumOption } from '@/types/employee';

const props = defineProps<{
    employee: EmployeeEditItem;
    genders: EnumOption[];
    employmentStatuses: EnumOption[];
    roles: EnumOption[];
}>();

const initialData = computed(() => ({
    email: props.employee.email ?? '',
    username: props.employee.username ?? '',
    full_name: props.employee.full_name ?? '',
    phone_number: props.employee.phone_number ?? '',
    gender: props.employee.gender ?? '',
    birth_date: props.employee.birth_date ?? '',
    address: props.employee.address ?? '',
    join_date: props.employee.join_date ?? '',
    employment_status: props.employee.employment_status ?? 'full_time',
    base_salary: props.employee.base_salary != null ? String(props.employee.base_salary) : '',
    role: props.employee.role ?? '',
}));
</script>

<template>

    <Head title="Ubah Pegawai" />

    <AdminLayout title="Ubah Pegawai">
        <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
            <div class="space-y-1">
                <h2 class="text-2xl font-bold tracking-tight">
                    Ubah Pegawai
                </h2>
            </div>

            <Button variant="outline" as-child class="shrink-0 self-start sm:self-center">
                <Link href="/admin/hr/employees">
                    <ArrowLeft class="size-4" />
                    Kembali
                </Link>
            </Button>
        </div>

        <EmployeeForm :submit-url="`/admin/hr/employees/${employee.id}`" method="put" submit-label="Perbarui"
            :initial-data="initialData" :employee-id="employee.id" :employee-name="employee.full_name"
            :genders="genders"
            :employment-statuses="employmentStatuses"
            :roles="roles"
        />
    </AdminLayout>
</template>
