import '../styles/globals.css'
import NextProgress from 'next-progress'
import { useRouter } from 'next/router'
import { AnimatePresence } from 'framer-motion'
import { Toaster } from 'react-hot-toast'
import { QueryClient, QueryClientProvider } from 'react-query'
import useDevice from '@/core/hooks/useDevice'

const queryClient = new QueryClient()

function MyApp({ Component, pageProps }) {
  const router = useRouter()
  const { isMobile } = useDevice()

  return (
    <>
      <Toaster
        position='top-center'
        toastOptions={{
          duration: 3000,
          className: 'border border-gray_r-8'
        }}
      />
      <NextProgress color='#F01C21' options={{ showSpinner: false }} />
      <QueryClientProvider client={queryClient}>
        <AnimatePresence
          mode={isMobile ? 'wait' : 'sync'}
          initial={false}
          onExitComplete={() => window.scrollTo(0, 0)}
        >
          <Component {...pageProps} key={router.asPath} />
        </AnimatePresence>
      </QueryClientProvider>
    </>
  )
}

export default MyApp
