export type Locale = 'zh' | 'en'

export const DEFAULT_LOCALE: Locale = 'zh'

export function getLocaleFromPathname(pathname: string): Locale {
  return pathname === '/en' || pathname.startsWith('/en/') ? 'en' : 'zh'
}

export function stripLocalePrefix(pathname: string): string {
  if (pathname === '/en') return '/'
  if (pathname.startsWith('/en/')) return pathname.replace(/^\/en/, '')
  return pathname
}

export function withLocalePath(locale: Locale, path: string): string {
  if (locale === 'en') {
    if (path === '/') return '/en'
    return `/en${path}`
  }

  return path
}

export function toOppositeLocale(locale: Locale): Locale {
  return locale === 'en' ? 'zh' : 'en'
}
