import MainRouter from './router/Main'
import i18next from 'i18next'
import { I18nextProvider } from 'react-i18next'
import { BrowserRouter, Routes, Route } from 'react-router-dom'
import 'swiper/swiper-bundle.css';
import FaJson from './langs/fa.json'
import AuthRouter from './router/Auth';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import ToastContainer from './components/Toast';
import { ChatbotButton } from './chatbot';

i18next.init({
  interpolation: { escapeValue: false },
  lng: 'fa',
  resources: {
    fa: {
      global: FaJson
    }
  }
})

declare global {
  interface Window {
    isRefreshingToken?: boolean;
  }
}

function App() {
  const queryClient = new QueryClient({
    defaultOptions: {
      queries: {
        refetchOnWindowFocus: false,
        retry: false
      }
    }
  });

  return (
    <>
      <BrowserRouter>
        <QueryClientProvider client={queryClient}>
          <I18nextProvider i18n={i18next}>
            <Routes>
              <Route path="/:slug/auth/*" element={<AuthRouter />} />
              <Route path="/:slug/*" element={<MainRouter />} />
            </Routes>
            <ToastContainer />
            <ChatbotButton />
          </I18nextProvider>
        </QueryClientProvider>
      </BrowserRouter>
    </>
  )
}

export default App
