import type { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import { Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import type { Announcement } from '@/types/announcement'; export type { Announcement } from '@/types/announcement'; type CreateColumnsParams = { handleEdit: (announcement: Announcement) => void; handleDeleteClick: (announcement: Announcement) => void; canUpdate: boolean; canDelete: boolean; }; export function createAnnouncementColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params; const columns: ColumnDef[] = [ { accessorKey: 'title', header: () => Judul, cell: ({ row }) => { const announcement = row.original; return (

{announcement.title}

{announcement.content}

); }, }, { accessorKey: 'department.name', header: () => Target, cell: ({ row }) => { const announcement = row.original; if (!announcement.department && !announcement.enrollment_year) { return Semua Mahasiswa; } return (
{announcement.department?.name ?? 'Semua Jurusan'} {announcement.enrollment_year && ( Angkatan {announcement.enrollment_year} )}
); }, }, { accessorKey: 'creator.profile.full_name', header: () => Dibuat Oleh, cell: ({ row }) => row.original.creator?.profile?.full_name ?? '-', }, { accessorKey: 'created_at', header: () => Tanggal, cell: ({ row }) => format(new Date(row.original.created_at), 'd MMM yyyy, HH:mm'), }, ]; if (canUpdate || canDelete) { columns.push({ id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => ( , show: canUpdate, onClick: () => handleEdit(row.original), }, { label: 'Hapus', icon: ( ), show: canDelete, onClick: () => handleDeleteClick(row.original), }, ]} /> ), }); } return columns; }