"use client" import { ColumnDef } from "@tanstack/react-table" import { Checkbox } from "@/shared/components/ui/checkbox" import { Badge, type BadgeProps } from "@/shared/components/ui/badge" import { cn, formatDate } from "@/shared/lib/utils" import { Exam } from "../types" import { ExamActions } from "./exam-actions" type TranslationFn = (key: string, params?: Record) => string export function createExamColumns(t: TranslationFn): ColumnDef[] { return [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label={t("exam.actions.selectAll")} /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label={t("exam.actions.selectRow")} /> ), enableSorting: false, enableHiding: false, size: 36, }, { accessorKey: "title", header: t("exam.columns.examInfo"), cell: ({ row }) => (
{row.original.title} {row.original.tags && row.original.tags.length > 0 && (
{row.original.tags.slice(0, 2).map((tag, idx) => ( {tag} ))} {row.original.tags.length > 2 && ( +{row.original.tags.length - 2} )}
)}
{row.original.subject} {row.original.grade}
), }, { accessorKey: "status", header: t("exam.columns.status"), cell: ({ row }) => { const status = row.original.status const variant: BadgeProps["variant"] = status === "published" ? "default" : status === "archived" ? "secondary" : "outline" return ( {t(`exam.status.${status}`)} ) }, }, { id: "stats", header: t("exam.columns.stats"), cell: ({ row }) => (
{row.original.questionCount} {t("exam.columns.questions")} {row.original.totalScore} {t("exam.columns.points")}
{row.original.durationMin} min
), }, { accessorKey: "difficulty", header: t("exam.columns.difficulty"), cell: ({ row }) => { const diff = row.original.difficulty return (
{[1, 2, 3, 4, 5].map((level) => (
))}
{t(`exam.difficulty.${diff}`)}
) }, }, { id: "dates", header: t("exam.columns.date"), cell: ({ row }) => { const scheduled = row.original.scheduledAt const created = row.original.createdAt return (
{scheduled ? ( <> {t("exam.columns.scheduled")} {formatDate(scheduled)} ) : ( <> {t("exam.columns.created")} {formatDate(created)} )}
) }, }, { id: "actions", cell: ({ row }) => , }, ] }