import moment from 'moment'
import { papersType } from '@/assets/staticData'
moment.locale('zh-CN')

export function yesOrNo (num) {
  return num === 1 ? '是' : '否'
}
export const ifNolimit = (input) => {
  return input === -1 ? '不限' : input
}
// 票大类团散客
export const groupIndividual = (category) => {
  switch (category) {
    case 'ticket':
      return '景区门票'
    case 'batch':
      return '场次售票'
    case 'member':
      return '年卡次卡'
  }
}
// 检票类型
export function checkTypeName (num) {
  switch (num - 0) {
    case 1:
      return '单人按次'
    case 2:
      return '多人按次'
    case 3:
      return '按有效期'
    case 4:
      return '管理卡'
  }
}
// 证件类型
export function paperType (key) {
  return papersType[key] || '暂无'
}

// 会员大类
export const memberCategory = (input) => {
  switch (input) {
    case 1:
      return '游客'
    case 2:
      return '多人卡'
    case 3:
      return '居民'
    case 4:
      return '管理员'
    case 5:
      return '储值卡'
    default:
      return '其他'
  }
}
// 会员检票方案
export const complicatedCheckType = (arr) => {
  /* 0: check_pattern,
     1: scenic_checkTimes_type,
     2: valid_days,
     3: checkLimitTimes */
  switch (arr[0]) {
    case 'count':
      switch (arr[1]) {
        case 1:
          return `单人按次 单独限制`
        case 2:
          return `单人按次 批量限制 共可检${arr[3]}次`
        default:
          return ''
      }
    case 'time':
      switch (arr[2]) {
        case -1:
          return `按有效期 截止到票种有效期`
        default:
          return `按有效期 ${arr[2]}天`
      }
    default:
      return ''
  }
}
// 订单状态
export const orderStatus = (input) => {
  switch (input) {
    case 'WAIT_PAY':
      return '待支付'
    case 'WAIT_USE':
      return '未检票'
    case 'PART_USE':
      return '部分检票'
    case 'COMPLETE':
      return '已检票'
    case 'CANCELED':
      return '已退票'
    case 'CLOSED':
      return '已关闭'
    default:
      return '其他'
  }
}
// 订单状态
export const orderStatusColor = (input) => {
  switch (input) {
    case 'WAIT_PAY':
      return ''
    case 'WAIT_USE':
      return 'success'
    case 'PART_USE':
      return 'warning'
    case 'COMPLETE':
      return ''
    case 'CANCELED':
      return 'danger'
    case 'CLOSED':
      return 'info'
    default:
      return 'info'
  }
}
// 票状态
export const ticketStatus = (input) => {
  switch (input) {
    case 'WAIT_USE':
      return '未检票'
    case 'PART_USE':
      return '部分检票'
    case 'USED':
      return '已检票'
    case 'OUTOFDATE':
      return '已过期'
    case 'CANCELED':
      return '已退票'
    case 'REFUNDING':
      return '退款中'
    default:
      return '其他'
  }
}

// 订单状态
export const ticketStatusColor = (input) => {
  switch (input) {
    case 'WAIT_USE':
      return 'success'
    case 'PART_USE':
      return 'warning'
    case 'USED':
      return ''
    case 'OUTOFDATE':
      return 'info'
    case 'CANCELED':
      return 'danger'
    default:
      return 'info'
  }
}

// 开、关 状态颜色
export const onOffColor = (input) => {
  switch (input) {
    case 1:
      return 'success'
    case 0:
      return 'info'
  }
}

// 运行、停止 状态颜色
export const runStopColor = (input) => {
  switch (input) {
    case 1:
      return 'success'
    case 0:
      return 'danger'
  }
}

export const formatTime = (input) => {
  return moment(input).isValid() ? moment(input).format('YYYY-MM-DD HH:mm:ss') : ''
}

export const formatDate = (input) => {
  return moment(input).isValid() ? moment(input).format('YYYY-MM-DD') : ''
}

export const formatIDCard = (input, placeholderText) => {
  if (typeof input !== 'string' || input.length < 7) {
    return placeholderText || ''
  }

  const firstThree = input.substring(0, 3)
  const lastFour = input.substring(input.length - 4)
  const maskedCharacters = '*'.repeat(input.length - 7) // Hides all characters between first three and last four

  const maskedID = `${firstThree}${maskedCharacters}${lastFour}`
  return maskedID
}

// 建行B扫C退款状态
export const b2cRefundStatus = (input) => {
  switch (input) {
    case 'CREATE':
      return '创建'
    case 'NEED_RETRY':
      return '需要重试'
    case 'UNKNOWN':
      return '未知'
    case 'REFUND_SUCCESS':
      return '退款成功'
    case 'SUCCESS':
      return '成功'
    case 'FAILURE':
      return '失败'
    default:
      return '其他'
  }
}

// 建行B扫C退款状态颜色
export const b2cRefundStatusColor = (input) => {
  switch (input) {
    case 'CREATE':
      return 'info'
    case 'NEED_RETRY':
      return 'warning'
    case 'UNKNOWN':
      return 'warning'
    case 'REFUND_SUCCESS':
      return 'success'
    case 'SUCCESS':
      return 'success'
    case 'FAILURE':
      return 'danger'
    default:
      return 'info'
  }
}
