import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
const { t } = useI18n() // 国际化

// 表单校验
export const rules = reactive({
  mail: [
    { required: true, message: t('profile.rules.mail'), trigger: 'blur' },
    {
      type: 'email',
      message: t('profile.rules.truemail'),
      trigger: ['blur', 'change']
    }
  ],
  username: [required],
  password: [required],
  host: [required],
  port: [required],
  sslEnable: [required],
  starttlsEnable: [required]
})

const crudSchemas = reactive<CrudSchema[]>([
  {
    label: t('system.email'),
    field: 'mail',
    isSearch: true
  },
  {
    label: t('system.userName'),
    field: 'username',
    isSearch: true
  },
  {
    label: t('system.password'),
    field: 'password',
    isTable: false
  },
  {
    label: t('system.SMTPserverDomainName'),
    field: 'host'
  },
  {
    label: t('system.SMTPserverPort'),
    field: 'port',
    form: {
      component: 'InputNumber',
      value: 465
    }
  },
  {
    label: t('system.whetherToEnableSSL'),
    field: 'sslEnable',
    dictType: DICT_TYPE.INFRA_BOOLEAN_STRING,
    dictClass: 'boolean',
    form: {
      component: 'Radio'
    }
  },
  {
    label: t('system.whetherToEnableSTARTTLS'),
    field: 'starttlsEnable',
    dictType: DICT_TYPE.INFRA_BOOLEAN_STRING,
    dictClass: 'boolean',
    form: {
      component: 'Radio'
    }
  },
  {
    label: t('system.creationTime'),
    field: 'createTime',
    isForm: false,
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    }
  },
  {
    label: t('system.operation'),
    field: 'action',
    isForm: false,
    isDetail: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
