import { createBrowserHistory } from 'history';
import {
  unstable_HistoryRouter as HistoryRouter,
  Route,
  Routes,
} from 'react-router-dom';

import { AudioPlayer } from '@/components/AudioPlayer';
import { Error404 } from '@/errors';
import { ErrorBoundary } from '@/errors/ErrorBoundary';
import { ArtistRoutes } from '@/scene/artist/ArtistRoutes';
import { HomePage } from '@/scene/home/HomePage';
import { SSORoutes } from '@/scene/sso/SSORoutes';
import { ServiceContextProvider } from '@/service/ServiceContext';

export const App = () => {
  return (
    <ServiceContextProvider>
      <ErrorBoundary>
        <HistoryRouter
          history={createBrowserHistory({ window })}
          basename="/karusic"
        >
          <Routes>
            <Route path="/" element={<HomePage />} />
            <Route path="artist/*" element={<ArtistRoutes />} />
            <Route path="sso/*" element={<SSORoutes />} />
            <Route path="*" element={<Error404 />} />
          </Routes>
        </HistoryRouter>
      </ErrorBoundary>
      <AudioPlayer />
    </ServiceContextProvider>
  );
};
