// import parseTime, formatTime and set to filter
// export { parseTime, formatTime } from '@/utils'

/**
 * Show plural label if time is plural number
 * @param {number} time
 * @param {string} label
 * @return {string}
 */
function pluralize(time, label) {
  if (time === 1) {
    return time + label
  }
  return time + label + 's'
}

/**
 * @param {number} time
 */
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')
  }
}

/**
 * Number formatting
 * like 10000 => 10k
 * @param {number} num
 * @param {number} digits
 */
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).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
    }
  }
  return num.toString()
}

/**
 * 10000 => "10,000"
 * @param {number} num
 */
export function toThousandFilter(num) {
  return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

/**
 * Upper case first char
 * @param {String} string
 */
export function uppercaseFirst(string) {
  return string.charAt(0).toUpperCase() + string.slice(1)
}
/**
 * Number formatting
 * kwh 转化 Mwh
 * @param {number} num
 * @param {number} digits
 */
export function kwhFormat(num, digits) {
  if (!num) {
    return 0
  }
  if (!digits) {
    digits = 2
  }
  if(Number(num) >= 1E7){
    return (Number(num) / 1E6).toFixed(digits) + ''
  }else if (Number(num) >= 1E4) {
    return (Number(num) / 1E3).toFixed(digits) + ''
  }
  return Number(num).toFixed(digits) + ''
}
/**
 * Number formatting
 * kwh 转化 Mwh
 * @param {number} num
 * @param {number} digits
 */
export function kWFormat(num, digits) {
  if (!num) {
    return 0
  }
  if (!digits) {
    digits = 2
  }
  if (Number(num) >= 1E4) {
    return (Number(num) / 1E3).toFixed(digits) + ''
  }
  return Number(num).toFixed(digits) + ''
}
/**
 * unit formatting
 * kwh 转化 Mwh
 * @param {number} num
 * @param {number} digits
 */
export function kwhUnitFormat(num) {
  if (!num) {
    return 'kWh'
  }
  if(Number(num) >= 1E7){
    return 'GWh'
  }else if (Number(num) >= 1E4) {
    return 'MWh'
  }
  
  return 'kWh'
}

/**
 * unit formatting
 * kwh 转化 Mwh
 * @param {number} num
 * @param {number} digits
 */
export function kwpUnitFormat(num) {
  if (!num) {
    return 'kWp'
  }
  if (Number(num) >= 1E4) {
    return 'Mwp'
  }
  return 'kWp'
}
/**
 * unit formatting
 * kwh 转化 Mwh
 * @param {number} num
 * @param {number} digits
 */
export function kwUnitFormat(num) {
  if (!num) {
    return 'kW'
  }
  if (Number(num) >= 1E4) {
    return 'MW'
  }
  return 'kW'
}
/**
 * mone formatting
 * 元 转化 万元
 * @param {number} num
 * @param {number} digits
 */
export function moneyFormat(num, digits) {
  if (!num) {
    return 0
  }
  if (!digits) {
    digits = 2
  }
  if (Number(num) >= 1E4) {
    return (Number(num) / 1E4).toFixed(digits)
  }
  return Number(num).toFixed(digits)
}
/**
 * mone formatting
 * kg 转化 吨
 * @param {number} num
 * @param {number} digits
 */
export function kgFormat(num, digits) {
  if (!num) {
    return 0 + ''
  }
  if (!digits) {
    digits = 2
  }
  if (Number(num) >= 1E3) {
    return (Number(num) / 1E3).toFixed(digits) + ''
  }
  return Number(num).toFixed(digits) + ''
}
/**
 * unit formatting
 * 元 转化 万元
 * @param {number} num
 * @param {number} digits
 */
export function moneyUnitFormat(num) {
  if (!num) {
    return '元'
  }
  if (Number(num) >= 1E4) {
    return '万元'
  }
  return '元'
}
/**
 * unit formatting
 * kg 转化 吨
 * @param {number} num
 * @param {number} digits
 */
export function KgUnitFormat(num) {
  if (!num) {
    return 'kg'
  }
  if (Number(num) >= 1E3) {
    return '吨'
  }
  return 'kg'
}

export function isNull(num){
	if(!num && num !== 0 || num === 'NaN'){
		return ''
	}else{
		return num
	}
}