import type { ColumnDef } from '@tanstack/vue-table'; import { h } from 'vue'; import DataTableActions from '@/components/admin/hr/leave-requests/data-table-actions.vue'; import { DataTableColumnHeader } from '@/components/data-table'; import { Badge } from '@/components/ui/badge'; import type { LeaveRequestListItem } from '@/types/leave-request'; function statusVariant(status: string): 'default' | 'secondary' | 'destructive' | 'outline' { switch (status) { case 'approved': return 'default'; case 'rejected': return 'destructive'; default: return 'outline'; } } export function createColumns( authEmployeeId: number | null, onEdit: (leaveRequest: LeaveRequestListItem) => void, onReject: (leaveRequest: LeaveRequestListItem) => void, ): ColumnDef[] { return [ { accessorKey: 'created_at_formatted', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Tanggal Pengajuan', column: 'created_at' }), }, { accessorKey: 'employee_name', enableSorting: false, header: () => 'Pegawai', }, { accessorKey: 'start_date_formatted', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Mulai', column: 'start_date' }), }, { accessorKey: 'end_date_formatted', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Selesai', column: 'end_date' }), }, { accessorKey: 'total_days', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Hari', column: 'total_days' }), cell: ({ row }) => `${row.original.total_days} hari`, }, { accessorKey: 'status_label', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Status', column: 'status' }), cell: ({ row }) => h( Badge, { variant: statusVariant(row.original.status) }, () => row.original.status_label, ), }, { accessorKey: 'rejection_reason', enableSorting: false, header: () => 'Alasan Penolakan', cell: ({ row }) => row.original.rejection_reason ?? '-', }, { id: 'actions', enableSorting: false, enableHiding: false, cell: ({ row }) => h(DataTableActions, { leaveRequest: row.original, authEmployeeId, onEdit: () => onEdit(row.original), onReject: () => onReject(row.original), }), }, ]; }