import num from '#/utils/num'
import obj from '#/utils/obj'

// 类型
// 充值
export const coin_type_charge = 1
// 发放奖励
export const coin_type_reward = 2
// 转让
export const coin_type_transfer = 5
// 开户未激活退回
export const coin_type_refund = 6
// 购买礼物
export const coin_type_buy_gift = 7
// 转让
export const coin_type_sp_transfer = 2
// 回收
export const coin_type_punish = 3
// 用户开户
export const coin_type_create_account = 4
// 交易锁定
export const coin_type_trade_lock = 5
// 交易
export const coin_type_trade = 6
// 增加
export const coin_operation_add = 1
// 减少
export const coin_operation_sub = 2

export const targetTypeOptions = [
  {
    label: '服务商',
    value: '1',
  },
  {
    label: '学校机构',
    value: '2',
  },
]

export const transTypeOptions = [
  {
    label: '赠送',
    value: '0',
  },
  {
    label: '销售',
    value: '1',
  },
  {
    label: '公益捐赠',
    value: '2',
  },
]
export const transTypeMap = obj.options2map(transTypeOptions)

export const operationList = [
  {
    value: coin_operation_add,
    label: '增加',
  },
  {
    value: coin_operation_sub,
    label: '减少',
  },
]
export const typeMap = {
  [coin_type_charge]: '充值',
  [coin_type_reward]: '发放奖励',
  [coin_type_punish]: '回收',
  [coin_type_create_account]: '开户续费',
  [coin_type_transfer]: '转让',
  [coin_type_refund]: '开户未激活退回',
  [coin_type_buy_gift]: '购买礼物',
} as any
export const typeList = obj.map2options(typeMap)
export const spTypeMap = {
  [coin_type_charge]: '充值',
  [coin_type_sp_transfer]: '转让',
  [coin_type_create_account]: '开户续费',
  [coin_type_trade_lock]: '交易锁定',
  [coin_type_trade]: '交易',
} as any
export const spTypeList = obj.map2options(spTypeMap)

// 充值
const parent_coin_type_charge = 1
// 购买
const parent_coin_type_buy = 2
// 点赞
const parent_coin_type_like = 3
// 激活
const parent_coin_type_active = 4
// 未激活
const parent_coin_type_unactive = 5
export const parentTypeMap = {
  [parent_coin_type_charge]: '充值',
  [parent_coin_type_buy]: '购买',
  [parent_coin_type_like]: '点赞',
  [parent_coin_type_active]: '激活',
  [parent_coin_type_unactive]: '未激活',
} as any
export const parentTypeList = obj.map2options(parentTypeMap)

export function useCoin() {
  function getTypeClass(row: any) {
    // const type = Number(row.typeCode)
    // if (type === coin_type_punish) {
    //   return 'type-punish'
    // }
    return row.operation === coin_operation_add ? 'progress-100' : 'progress-1'
    // if (type === coin_type_charge) {
    //   return 'type-charge'
    // }
    // if (type === coin_type_reward) {
    //   return 'type-reward'
    // }
    // if (type === coin_type_create_account) {
    //   return 'type-reward'
    // }
    // return 'type-charge'
  }

  function getAmount(row: any) {
    const val = num.formatMoney(row.amount)
    return row.operation === coin_operation_add ? `+${val}` : `-${val}`
  }
  return {
    getTypeClass,
    getAmount,
  }
}
