import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
import * as MailAccountApi from '@/api/system/mail/account'
const { t } = useI18n()

// 邮箱账号的列表
const accountList = await MailAccountApi.getSimpleMailAccountList()

const crudSchemas = reactive<CrudSchema[]>([
  {
    label:  t('system.no'),
    field: 'id'
  },
  {
    label:  t('system.sendingTime'),
    field: 'sendTime',
    formatter: dateFormatter,
    search: {
      show: true,
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    }
  },
  {
    label:  t('system.receivingEmail'),
    field: 'toMail'
  },
  {
    label:  t('system.userId'),
    field: 'userId',
    isSearch: true,
    isTable: false
  },
  {
    label:  t('system.userType'),
    field: 'userType',
    dictType: DICT_TYPE.USER_TYPE,
    dictClass: 'number',
    isSearch: true,
    isTable: false
  },
  {
    label:  t('system.emailTitle'),
    field: 'templateTitle'
  },
  {
    label:  t('system.emailContent'),
    field: 'templateContent',
    isTable: false
  },
  {
    label:  t('system.emailParameters'),
    field: 'templateParams',
    isTable: false
  },
  {
    label:  t('system.sendingStatus'),
    field: 'sendStatus',
    dictType: DICT_TYPE.SYSTEM_MAIL_SEND_STATUS,
    dictClass: 'string',
    isSearch: true
  },
  {
    label:  t('system.emailAccount'),
    field: 'accountId',
    isTable: false,
    search: {
      show: true,
      component: 'Select',
      api: () => accountList,
      componentProps: {
        optionsAlias: {
          labelField: 'mail',
          valueField: 'id'
        }
      }
    }
  },
  {
    label:  t('system.sendingEmailAddress'),
    field: 'fromMail',
    table: {
      label:  t('system.emailAccount')
    }
  },
  {
    label:  t('system.templateNumber'),
    field: 'templateId',
    isSearch: true
  },
  {
    label:  t('system.templateCode'),
    field: 'templateCode',
    isTable: false
  },
  {
    label:  t('system.templateSenderName'),
    field: 'templateNickname',
    isTable: false
  },
  {
    label:  t('system.sendingReturnedMessageNumber'),
    field: 'sendMessageId',
    isTable: false
  },
  {
    label:  t('system.sendingException'),
    field: 'sendException',
    isTable: false
  },
  {
    label:  t('system.creationTime'),
    field: 'createTime',
    isTable: false,
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    }
  },
  {
    label:  t('system.operation'),
    field: 'action',
    isDetail: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
