import moment from 'moment-timezone'

export const formatTimezone = (time: string, timezone: string) => {
  if (!time) return '--'
  let formattedTime = ''
  if (time.length > 12) {
    formattedTime = moment(time).format('MMM-DD-YYYY hh:mm A')
    if (!timezone) {
      return formattedTime
    }
    let gmtOffset = ''
    const timeZoneOffset = moment().tz(timezone).format('Z')
    // 替换 "+07:00" 为 "GMT+07"
    gmtOffset = `(GMT${timeZoneOffset.slice(0, 3)})`
    return `${formattedTime} ${gmtOffset}`
  } else {
    formattedTime = moment(time).format('MMM-DD-YYYY')
    return formattedTime
  }
}

export const formatTimezoneByUTCorGMT = (time: string, timezone: string) => {
  if (!time) return '--'
  let formattedTime = ''
  formattedTime = moment(time).format('MMM-DD-YYYY hh:mm A')
  let gmtOffset = ''
  console.log(timezone, formattedTime)
  if (timezone != null) {
    const timeZoneOffset = moment().tz(timezone).format('Z')
    // 替换 "+07:00" 为 "GMT+07"
    if (timezone.includes('Seoul')) {
      gmtOffset = `(UTC${timeZoneOffset.slice(0, 3)})`
    } else {
      gmtOffset = `(GMT${timeZoneOffset.slice(0, 3)})`
    }
    return `${formattedTime} ${gmtOffset}`
  }
}
