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

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

const initialData = computed(() => ({
    email: props.employee.email ?? '',
    username: props.employee.username ?? '',
    full_name: props.employee.profile?.full_name ?? '',
    phone_number: props.employee.profile?.phone_number ?? '',
    gender: props.employee.profile?.gender ?? '',
    birth_date: props.employee.profile?.birth_date_input ?? '',
    address: props.employee.profile?.address ?? '',
    join_date: props.employee.employee?.join_date_input ?? '',
    employment_status: props.employee.employee?.employment_status ?? '',
    base_salary: props.employee.employee?.base_salary != null ? String(props.employee.employee.base_salary) : '',
    role: props.employee.roles?.[0]?.name ?? '',
}));
</script>

<template>

    <Head title="Ubah Pegawai" />

    <AdminLayout>
        <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.profile?.full_name"
            :genders="genders" :employment-statuses="employmentStatuses" :roles="roles" />
    </AdminLayout>
</template>
