import { Tag } from 'ant-design-vue';
import { BasicColumn } from '/@/components/Table/index';
import { ErrorTypeEnum } from '/@/enums/exceptionEnum';
import locales from '/@/utils/locales';
export function getColumns(): BasicColumn[] {
  return [
    {
      dataIndex: 'type',
      title: locales.errorLog.tableColumnType,
      width: 80,
      customRender: ({ text }) => {
        const color =
          text === ErrorTypeEnum.VUE
            ? 'green'
            : text === ErrorTypeEnum.RESOURCE
              ? 'cyan'
              : text === ErrorTypeEnum.PROMISE
                ? 'blue'
                : ErrorTypeEnum.AJAX
                  ? 'red'
                  : 'purple';
        return <Tag color={color}>{() => text}</Tag>;
      },
    },
    {
      dataIndex: 'url',
      title: 'URL',
      width: 200,
    },
    {
      dataIndex: 'time',
      title: locales.errorLog.tableColumnDate,
      width: 160,
    },
    {
      dataIndex: 'file',
      title: locales.errorLog.tableColumnFile,
      width: 200,
    },
    {
      dataIndex: 'name',
      title: 'Name',
      width: 200,
    },
    {
      dataIndex: 'message',
      title: locales.errorLog.tableColumnMsg,
      width: 300,
    },
    {
      dataIndex: 'stack',
      title: locales.errorLog.tableColumnStackMsg,
    },
  ];
}

export function getDescSchema(): any {
  return getColumns().map(column => {
    return {
      field: column.dataIndex!,
      label: column.title,
    };
  });
}
