import { usePermission } from '@/hooks/use-permission'; import type { ColumnDef } from '@tanstack/react-table'; import { PencilRuler, Trash2 } from 'lucide-react'; import { DataTableColumnHeader } from '@/components/data-table-column-header'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Switch } from '@/components/ui/switch'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import type { Payroll } from '@/types'; interface ColumnProps { onEdit: (payroll: Payroll) => void; onDelete: (payroll: Payroll) => void; onTogglePaid: (id: number) => void; } export const getColumns = ({ onEdit, onDelete, onTogglePaid }: ColumnProps): ColumnDef[] => [ { accessorKey: "user.name", header: ({ column }) => ( ), cell: ({ row }) => row.original.user?.name || '-', meta: { title: "Pegawai" }, }, { accessorKey: "period_month", header: ({ column }) => ( ), cell: ({ row }) => row.original.period_month_formatted, meta: { title: "Periode" }, }, { accessorKey: "total_salary", header: ({ column }) => ( ), cell: ({ row }) => { const payroll = row.original; return (
Gaji Pokok {payroll.base_salary_formatted}
{payroll.adjustments && payroll.adjustments.length > 0 && (
{payroll.adjustments.map((adj, idx) => (
{adj.description} {adj.type === 'bonus' ? '+' : '-'}{adj.amount_formatted}
))}
)}
Gaji Bersih {payroll.total_salary_formatted}
); }, meta: { title: "Total Gaji" }, }, { accessorKey: "is_paid", header: "Status", cell: ({ row }) => { const payroll = row.original; const { hasPermission } = usePermission(); return (
onTogglePaid(payroll.id)} disabled={!hasPermission('Pay:Payroll')} /> {payroll.is_paid ? 'Dibayar' : 'Pending'}
); }, meta: { title: "Status" }, }, { id: "actions", header: "Aksi", cell: ({ row }) => { const payroll = row.original; const { hasPermission } = usePermission(); return (
{hasPermission('Edit:PayrollAdjustment') && (

Ubah / Sesuaikan

)} {hasPermission('Delete:Payroll') && (

Hapus

)}
); }, meta: { title: "Aksi" }, }, ];