import moment from 'moment'
export { parseTime } from '@/utils'

export function serviceStatus (input) {
  console.log(input)
  return [1, 2, 3]
}

function pluralize (time, label) {
  if (time === 1) {
    return time + label
  }
  return time + label + 's'
}

export function timeAgo (time) {
  const between = Date.now() / 1000 - Number(time)
  if (between < 3600) {
    return pluralize(~~(between / 60), ' minute')
  } else if (between < 86400) {
    return pluralize(~~(between / 3600), ' hour')
  } else {
    return pluralize(~~(between / 86400), ' day')
  }
}
// 性别
export function sexFilter (num) {
  if (num === 0) {
    return '不限'
  } else if (num === 1) {
    return '男'
  } else if (num === 2) {
    return '女'
  } else {
    return ''
  }
}

/* 数字 格式化 */
export function numberFormatter (num, digits) {
  const si = [
    { value: 1E18, symbol: 'E' },
    { value: 1E15, symbol: 'P' },
    { value: 1E12, symbol: 'T' },
    { value: 1E9, symbol: 'G' },
    { value: 1E6, symbol: 'M' },
    { value: 1E3, symbol: 'k' }
  ]
  for (let i = 0; i < si.length; i++) {
    if (num >= si[i].value) {
      return (num / si[i].value + 0.1).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
    }
  }
  return num.toString()
}

export function toThousandslsFilter (num) {
  return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

export function yesOrNo (num) {
  return num === 1 ? '是' : '否'
}

export function scenicsArray (arr) {
  let names = arr.map(item => {
    return item.name
  })
  return names.join(',')
}

export function checkTypeName (num) {
  switch (num - 0) {
    case 1:
      return '单人按次'
    case 2:
      return '按有效期'
    case 3:
      return '多人按次'
    case 4:
      return '按金额-储值卡'
    case 5:
      return '管理卡'
  }
}

export function idTypeName (num) {
  switch (num - 0) {
    case 1:
      return '身份证'
    case 2:
      return '护照'
    case 3:
      return '港澳居民来往内地通行证'
    case 4:
      return '台胞证'
  }
}

export function sellChannelName (num) {
  switch (num - 0) {
    case 1:
      return '线下'
    case 2:
      return 'OTA'
    case 3:
      return '线下和OTA'
  }
}

export function formatTime (input) {
  return moment(input).format('YYYY-MM-DD HH:mm:ss')
}

export function formatDate (input) {
  return moment(input).format('YYYY-MM-DD')
}
