/* eslint-disable unicorn/numeric-separators-style */

import { mj_form_money } from '#/components/mj/mj-table'
import { rangeValidator } from '#/components/mj/mj-table/fmt'

export type RenewProps = {
  months?: any
  userId: any
  years?: any
}

type CoinCfg = {
  key: string
  max?: number
  min?: number
  orgDefault: number
  spDefault: number
  title: string
}

export const firstMonthCreditCfg = {
  min: 1000,
  orgDefault: 2000,
  spDefault: 1000,
  title: '首月体验',
  key: 'firstMonthCredit',
} as CoinCfg
export const renewalMonthCreditCfg = {
  min: 2000,
  orgDefault: 4000,
  spDefault: 2000,
  title: '次月体验',
  key: 'renewalMonthCredit',
} as CoinCfg
export const normalMonthlyCreditCfg = {
  min: 3000,
  orgDefault: 6000,
  spDefault: 4000,
  title: '按月续费',
  key: 'normalMonthlyCredit',
} as CoinCfg
export const annualCreditCfg = {
  min: 30000,
  orgDefault: 60000,
  spDefault: 43200,
  title: '按年续费',
  key: 'annualCredit',
} as CoinCfg
export const referralDaysCfg = {
  min: 1,
  max: 7,
  orgDefault: 7,
  spDefault: 7,
  title: '导流天数',
  key: 'referralDays',
} as CoinCfg
export const referralCreditCfg = {
  min: 50,
  max: 350,
  orgDefault: 350,
  spDefault: 350,
  title: '导流乐贝',
  key: 'referralCredit',
} as CoinCfg

// export const createCfgRule = (...cfgs: CoinCfg[]) => {
//   const res = {} as any
//   for (const cfg of cfgs) {
//     res[cfg.key] = [
//       {
//         message: `请输入${cfg.title}`,
//         validator: rangeValidator(cfg.min, cfg.max),
//       },
//     ]
//   }
//   return res
// }

export const createFormItem = (cfg: CoinCfg, options?: any) => {
  return {
    validator: rangeValidator(cfg.min, cfg.max),
    field: cfg.key,
    title: cfg.title,
    span: 12,
    itemRender: {
      name: mj_form_money,
      props: { clearable: true, showPrefix: false },
    },
    ...options,
  }
}
