import '../styles/globals.css'
import type { AppProps } from 'next/app'
import { FC } from 'react'
import Head from 'next/head'
import { useRouter } from 'next/router'
import { IntlProvider } from 'react-intl'
import { useMessages } from '../src/i18n'

const MyApp: FC<AppProps> = ({ Component, pageProps }) => {
  const { basePath, locale: _locale } = useRouter()
  const messages = useMessages()
  const locale = _locale ?? '' in messages ? (_locale as keyof typeof messages) : 'en'
  return (
    <IntlProvider locale={locale} messages={messages[locale]}>
      <Head>
        <link rel='icon' href={`${basePath}/favicon.ico`} />
      </Head>
      <Component {...pageProps} />
    </IntlProvider>
  )
}

export default MyApp
