"use client" import { ColumnDef } from "@tanstack/react-table" import { Badge } from "@/shared/components/ui/badge" import { Checkbox } from "@/shared/components/ui/checkbox" import { Question, QuestionType } from "../types" import { QuestionActions } from "./question-actions" const getTypeColor = (type: QuestionType) => { switch (type) { case "single_choice": return "default" case "multiple_choice": return "secondary" case "judgment": return "outline" case "text": return "secondary" default: return "secondary" } } const getTypeLabel = (type: QuestionType) => { switch (type) { case "single_choice": return "Single Choice" case "multiple_choice": return "Multiple Choice" case "judgment": return "True/False" case "text": return "Short Answer" case "composite": return "Composite" default: return type } } export const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "type", header: "Type", cell: ({ row }) => { const type = row.getValue("type") as QuestionType return ( {getTypeLabel(type)} ) }, }, { accessorKey: "content", header: "Content", cell: ({ row }) => { const content = row.getValue("content") as unknown let preview = "" if (typeof content === "string") { preview = content } else if (content && typeof content === "object") { const text = (content as { text?: unknown }).text if (typeof text === "string") { preview = text } else { preview = JSON.stringify(content) } } preview = preview.slice(0, 80) return (
{preview}
) }, }, { accessorKey: "difficulty", header: "Difficulty", cell: ({ row }) => { const diff = row.getValue("difficulty") as number const label = diff === 1 ? "Easy" : diff === 2 ? "Easy-Med" : diff === 3 ? "Medium" : diff === 4 ? "Med-Hard" : "Hard" return (
{label} ({diff})
) }, }, { accessorKey: "knowledgePoints", header: "Knowledge Points", cell: ({ row }) => { const kps = row.original.knowledgePoints if (!kps || kps.length === 0) return - return (
{kps.slice(0, 2).map((kp) => ( {kp.name} ))} {kps.length > 2 && ( +{kps.length - 2} )}
) }, }, { accessorKey: "createdAt", header: "Created", cell: ({ row }) => { return ( {new Date(row.getValue("createdAt")).toLocaleDateString()} ) }, }, { id: "actions", cell: ({ row }) => , }, ]