import { Badge, Text } from '@mantine/core';
import type { TFunction } from 'i18next';
import type { AdvancedColumn } from '@ema-platform/ui';
import type { Question, QuestionStatus } from '../../types/question';

/** Bank items travel DRAFT → PENDING_APPROVAL → APPROVED (US-EXAM-003). */
const QC_COLOR: Record<QuestionStatus, string> = {
  DRAFT: 'gray',
  PENDING_APPROVAL: 'yellow',
  APPROVED: 'teal',
  REJECTED: 'red',
  RETIRED: 'dark',
};

export function questionColumns(
  t: TFunction,
  opts: {
    locale: 'en' | 'am';
    getCertName: (id: string) => string;
  },
): AdvancedColumn<Question>[] {
  return [
    {
      header: t('question.columns.title'),
      cell: ({ row }) => <Text fz="sm" maw={300} lineClamp={2}>{row.original.title[opts.locale]}</Text>,
    },
    {
      header: t('question.columns.certification'),
      cell: ({ row }) => <Text fz="sm">{opts.getCertName(row.original.certificationId)}</Text>,
    },
    {
      header: t('question.columns.form'),
      cell: ({ row }) => (
        <Badge size="sm" variant="light" color={row.original.form === 'ESSAY' ? 'blue' : 'violet'}>
          {t(`question.form.${row.original.form === 'ESSAY' ? 'essay' : 'choice'}`)}
        </Badge>
      ),
    },
    {
      header: t('question.columns.points'),
      cell: ({ row }) => <Text fz="sm" fw={600}>{row.original.points}</Text>,
    },
    {
      header: t('question.qc.column'),
      cell: ({ row }) => (
        <Badge size="sm" variant="light" color={QC_COLOR[row.original.status] ?? 'gray'} title={row.original.reviewRemark ?? undefined}>
          {t(`question.qc.${row.original.status}`)}
        </Badge>
      ),
    },
  ];
}
