import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { examStatusOptions } from '#/utils/dicts';
import { renderTag } from '#/utils/render';

/**
 * 查询表单schema
 */
export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'examName',
    label: '考试名称',
    componentProps: {
      placeholder: '请输入考试名称',
    },
  },
];

/**
 * 表格列配置
 */
export const tableColumns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 80 },
  { field: 'examName', title: '考试名称', minWidth: 200 },
  { field: 'categoryName', title: '类别', minWidth: 120 },
  { field: 'examStartTime', title: '开始时间', minWidth: 120 },
  { field: 'examEndTime', title: '结束时间', minWidth: 120 },
  { field: 'examDuration', title: '考试时长', minWidth: 120 },
  { field: 'passScore', title: '及格分数线', minWidth: 120 },
  { field: 'createBy', title: '创建人', minWidth: 120 },
  { field: 'totalScore', title: '考试总分', minWidth: 100 },
  { field: 'questionCount', title: '试题总数', minWidth: 100 },
  { field: 'updateTime', title: '更新日期', minWidth: 120 },
  {
    field: 'examStatus',
    title: '考试状态',
    minWidth: 120,
    slots: {
      default: ({ row }) => {
        const status = examStatusOptions.find(
          (item) => item.value === row.examStatus,
        );
        return renderTag(status?.label || row.examStatus, status?.color);
      },
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 280,
  },
];
