import { SitLang, StandardStatus, RoomType, OrderType } from './../@types/index';
import { i18n } from '../boot/i18n'
const {t} =i18n.global
/**
 * @description 按照需要写入 必要可以注入全局
 */

interface enumObj {
  key: string
  value: number
}

export interface DateType{
  id:number,
  bg:string,
  color:string,
  text:string
}

/**
 * @description 将枚举转为数组
 * @param objEnum 枚举对象
 * @returns 转化后的数组
 */
export function formatEnum(objEnum: any): Array<enumObj> {
  const array: Array<enumObj> = new Array<enumObj>()
  for (const key in objEnum) {
    if (!isNaNModified(key)) continue
    const tempEnumObj: enumObj = {
      key,
      value: objEnum[key] as number
    }
    array.push(tempEnumObj)
  }
  return array
}

export function isNaNModified(inputStr: string) {
  const numericRepr = parseFloat(inputStr)
  return isNaN(numericRepr) || numericRepr.toString().length != inputStr.length
}

export function getDayOfWeek(day:number){
  let weekLang=[t('dayOfWeek.mon'),t('dayOfWeek.tues'),t('dayOfWeek.wed'),t('dayOfWeek.thur'),t('dayOfWeek.fri'),t('dayOfWeek.sat'),t('dayOfWeek.sun')]
  return weekLang[day-1]
}

export function getHotelOrderStatus():Array<StandardStatus>{
  let status=[] as Array<StandardStatus>
  let text = [t('hotelorder.orderStatus.normal'),t('hotelorder.orderStatus.apply'),t('hotelorder.orderStatus.check'),t('hotelorder.orderStatus.cancel'),t('hotelorder.orderStatus.sun')]
  let color = ['','positive','dark','orange','negative']
  let icons = ['','update','done','offline_bolt','cached']
  text.forEach((x,i:number)=>{
    status.push({
      StatusId:i,
      StatusName:x,
      Icon:icons[i],
      Color:`text-${color[i]}`
    })
  })
  

  return status
}

export function getDateType(){
  let types=[] as Array<DateType>
  types.push({
    id:1,
    text:t('hotel.datetype.red'),
    color:'text-white',
    bg:'bg-red-9'
  })
  types.push({
    id:2,
    text:t('hotel.datetype.pink'),
    color:'text-white',
    bg:'bg-pink-4'
  })
  types.push({
    id:3,
    text:t('hotel.datetype.avg'),
    color:'text-white',
    bg:'bg-indigo-6'
  })
  types.push({
    id:4,
    text:t('hotel.datetype.dan'),
    color:'text-dark',
    bg:'bg-grey-3'
  })
  types.push({
    id:5,
    text:t('hotel.datetype.spe'),
    color:'text-white',
    bg:'bg-green'
  })
  types.push({
    id:6,
    text:t('hotel.datetype.xing'),
    color:'text-white',
    bg:'bg-brown'
  })

  return types
}

export function getHotelRoomType(getNormal:boolean = false):Array<RoomType>{
  let rooms = [] as Array<RoomType>
  if(getNormal){
    rooms.push({
      TypeId:0,
      TypeName:t('hotel.rooms.default')
    })
  }
  let roomLangs=[t('hotel.rooms.normal'),t('hotel.rooms.big'),t('hotel.rooms.sing'),t('hotel.rooms.three'),t('hotel.rooms.driver')]
  roomLangs.forEach((x:string,i:number)=>{
    rooms.push({
      TypeId:(i+1),
      TypeName:x
    })
  })
  return rooms
}

export function getHotelOrderType(getNormal:boolean = false):Array<OrderType>{
  let types = [] as Array<OrderType>
  if(getNormal){
    types.push({
      TypeId:0,
      TypeName:t('hotelorder.orderType.default')
    })
  }
  let typeLangs=[t('hotelorder.orderType.guest'),t('hotelorder.orderType.tour')]
  typeLangs.forEach((x:string,i:number)=>{
    types.push({
      TypeId:(i+1),
      TypeName:x
    })
  })
  return types
}

export function getLangs() {
  const zhTw:SitLang={
    langLocale:"zh-TW",
    langName:"中文繁体"
  }
  const zhSw:SitLang={
    langLocale:"zh-SW",
    langName:"中文简体"
  }
  const enUs:SitLang={
    langLocale:"en-US",
    langName:"English"
  }
  let langs:SitLang[]=[]
  langs.push(zhTw,zhSw,enUs);
  return langs
}
