import type { ColumnDef } from '@tanstack/vue-table'; import { h } from 'vue'; import AttendancePhotoCell from '@/components/admin/hr/attendances/attendance-photo-cell.vue'; import DataTableActions from '@/components/admin/hr/attendances/data-table-actions.vue'; import { DataTableColumnHeader } from '@/components/data-table'; import type { AttendanceListItem } from '@/types/attendance'; export function createColumns(canManageAll: boolean): ColumnDef[] { const columns: ColumnDef[] = []; if (canManageAll) { columns.push({ accessorKey: 'employee_name', enableSorting: false, header: () => h(DataTableColumnHeader, { title: 'Pegawai', column: 'employee_name' }), cell: ({ row }) => row.original.employee_name ?? '-', }); } columns.push( { accessorKey: 'attendance_date', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Tanggal', column: 'attendance_date' }), cell: ({ row }) => row.original.attendance_date_formatted, }, { accessorKey: 'check_in_at', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Masuk', column: 'check_in_at' }), cell: ({ row }) => row.original.check_in_at_formatted ?? '-', }, { accessorKey: 'check_out_at', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Pulang', column: 'check_out_at' }), cell: ({ row }) => row.original.check_out_at_formatted ?? '-', }, { id: 'duration', enableSorting: false, header: () => h(DataTableColumnHeader, { title: 'Durasi', column: 'duration' }), cell: ({ row }) => row.original.work_duration_formatted ?? '-', }, { id: 'photos', enableSorting: false, header: () => h(DataTableColumnHeader, { title: 'Foto', column: 'photos' }), cell: ({ row }) => h(AttendancePhotoCell, { checkInPhotoUrl: row.original.check_in_photo_url, checkOutPhotoUrl: row.original.check_out_photo_url, checkInLocationTag: row.original.check_in_location_tag, checkOutLocationTag: row.original.check_out_location_tag, }), }, { id: 'actions', enableSorting: false, enableHiding: false, cell: ({ row }) => h(DataTableActions, { attendance: row.original, }), }, ); return columns; }