import type { ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" import { FEEDBACK_STATUS_LABELS, FEEDBACK_TYPE_LABELS, FEEDBACK_RATING_LABELS, } from "@/lib/constants" import type { Feedback, FeedbackStatus } from "@/types/feedback" const STATUS_VARIANTS: Record = { pending: "destructive", read: "secondary", resolved: "default", } interface ColumnContext { onMarkRead: (fb: Feedback) => void onMarkResolved: (fb: Feedback) => void onViewDetail: (fb: Feedback) => void } export function getColumns(ctx: ColumnContext): ColumnDef[] { return [ { accessorKey: "type", header: "类型", cell: ({ row }) => { const type = row.getValue("type") as string return ( {FEEDBACK_TYPE_LABELS[type as keyof typeof FEEDBACK_TYPE_LABELS] ?? type} ) }, }, { id: "content", header: "内容", cell: ({ row }) => { const fb = row.original if (fb.type === "quiz_rating") { return (
{FEEDBACK_RATING_LABELS[fb.rating ?? ""] ?? fb.rating} {fb.questionStem && (

{fb.questionStem}

)}
) } return ( {fb.content ?? "—"} ) }, }, { accessorKey: "userNickname", header: "用户", cell: ({ row }) => ( {(row.getValue("userNickname") as string) || "匿名"} ), }, { accessorKey: "status", header: "状态", cell: ({ row }) => { const status = row.getValue("status") as FeedbackStatus return {FEEDBACK_STATUS_LABELS[status]} }, }, { accessorKey: "createdAt", header: "提交时间", cell: ({ row }) => ( {new Date(row.getValue("createdAt") as string).toLocaleString("zh-CN")} ), }, { id: "actions", header: "", cell: ({ row }) => { const fb = row.original return (
{fb.status === "pending" && ( )} {fb.status !== "resolved" && ( )}
) }, }, ] }