import { BasicColumn, FormSchema } from '/@/components/Table';

export const columns: BasicColumn[] = [
  { title: '模板编码', dataIndex: 'templateCode', width: 140 },
  { title: '模板名称', dataIndex: 'templateName', width: 180 },
  {
    title: '分类',
    dataIndex: 'category',
    width: 100,
    customRender: ({ text }) => {
      const m = { barcode: '条码', form: '表单套打', report: '报表' };
      return m[text] || text;
    },
  },
  {
    title: '纸张(mm)',
    dataIndex: 'paperWidthMm',
    width: 130,
    customRender: ({ record }) =>
      record?.paperWidthMm != null && record?.paperHeightMm != null
        ? `${record.paperWidthMm}×${record.paperHeightMm}`
        : '-',
  },
  { title: '备注', dataIndex: 'remark', ellipsis: true },
  { title: '创建时间', dataIndex: 'createTime', width: 165 },
];

export const searchFormSchema: FormSchema[] = [
  { label: '模板编码', field: 'templateCode', component: 'Input', colProps: { span: 6 } },
  { label: '模板名称', field: 'templateName', component: 'Input', colProps: { span: 6 } },
  {
    label: '分类',
    field: 'category',
    component: 'Select',
    componentProps: {
      options: [
        { label: '条码', value: 'barcode' },
        { label: '表单套打', value: 'form' },
        { label: '报表', value: 'report' },
      ],
      allowClear: true,
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '模板编码',
    field: 'templateCode',
    component: 'Input',
    required: true,
    componentProps: { maxlength: 64 },
    dynamicDisabled: ({ values }) => !!values?.id,
  },
  {
    label: '模板名称',
    field: 'templateName',
    component: 'Input',
    required: true,
  },
  {
    label: '分类',
    field: 'category',
    component: 'Select',
    defaultValue: 'form',
    componentProps: {
      options: [
        { label: '条码', value: 'barcode' },
        { label: '表单套打', value: 'form' },
        { label: '报表', value: 'report' },
      ],
    },
    required: true,
  },
  {
    label: '纸宽(mm)',
    field: 'paperWidthMm',
    component: 'InputNumber',
    defaultValue: 210,
    componentProps: { min: 10, max: 2000, style: { width: '100%' } },
  },
  {
    label: '纸高(mm)',
    field: 'paperHeightMm',
    component: 'InputNumber',
    defaultValue: 297,
    componentProps: { min: 10, max: 2000, style: { width: '100%' } },
  },
  {
    label: '方向',
    field: 'paperOrientation',
    component: 'Select',
    defaultValue: 'portrait',
    componentProps: {
      options: [
        { label: '纵向', value: 'portrait' },
        { label: '横向', value: 'landscape' },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: { rows: 2 },
  },
  { label: '', field: 'id', component: 'Input', show: false },
  { label: '', field: 'templateJson', component: 'Input', show: false, defaultValue: '{}' },
];
