import { createI18n } from 'vue-i18n'
import en from './locales/en.json'
import es from './locales/es.json'

const messages = { en, es }

function getBrowserLocale(): string {
  const nav = navigator as Navigator & { userLanguage?: string }
  const locale = nav.language || nav.userLanguage || 'en'
  return locale.split('-')[0]
}

export const i18n = createI18n({
  legacy: false,
  locale: getBrowserLocale(),
  fallbackLocale: 'en',
  messages,
})

export default i18n