import { BasicColumn } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

export function getHistoryColumns(): BasicColumn[] {
  return [
    {
      title: 'id',
      dataIndex: 'id',
      ifShow: false,
    },
    {
      title: 'schemeInfoId',
      dataIndex: 'schemeInfoId',
      ifShow: false,
    },
    {
      title: 'scheme',
      dataIndex: 'scheme',
      ifShow: false,
    },
    {
      title: 'createUserId',
      dataIndex: 'createUserId',
      ifShow: false,
    },
    {
      title: '创建人',
      width: 150,
      dataIndex: 'createUserName',
    },
    {
      title: '创建时间',
      width: 150,
      dataIndex: 'createDate',
    },
    {
      title: 'tenantId',
      dataIndex: 'tenantId',
      ifShow: false,
    },
    {
      title: '状态',
      dataIndex: 'type',
      width: 80,
      customRender: ({ record }) => {
        if (!record.type || record.type === 2) {
          const color = 'gray';
          const text = '草稿';
          return h(Tag, { color: color }, () => text);
        } else {
          const color = 'green';
          const text = '正式';
          return h(Tag, { color: color }, () => text);
        }
      },
    },
    {
      title: '当前版本',
      dataIndex: 'currentVersion',
      width: 80,
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: 80,
    },
  ];
}

export const dbMainColumns: BasicColumn[] = [
  {
    title: '类型',
    dataIndex: 'type',
    width: 50,
    customRender: ({ record }) => {
      const status = record.type;
      let enable;
      if (status == 'main') {
        enable = true;
      } else {
        enable = false;
      }
      const color = enable ? '#67c23a' : '#e6a23c';
      const text = enable ? '主表' : '子表';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '表名',
    dataIndex: 'tableName',
    width: 150,
  },
  {
    title: '备注',
    dataIndex: 'description',
    width: 150,
  },
];

export const dbColumnInfoColumns: BasicColumn[] = [
  {
    title: '字段名',
    dataIndex: 'dbColumnName',
    width: 150,
  },
  {
    title: '长度',
    dataIndex: 'length',
    width: 100,
  },
  {
    title: '数据格式（默认varchar）',
    dataIndex: 'dataType',
    width: 120,
  },
  {
    title: '备注',
    dataIndex: 'columnDescription',
    width: 120,
  },
  {
    dataIndex: 'isNullable',
    ifShow: false,
  },
  {
    dataIndex: 'isIdentity',
    ifShow: false,
  },
  {
    dataIndex: 'isPrimarykey',
    ifShow: false,
  },
  {
    dataIndex: 'decimalDigits',
    ifShow: false,
  },
];
