import './styles/style.css';

import * as React from 'react';
import {
  QueryClient,
  QueryClientProvider,
} from 'react-query';
import {
  Route,
  Routes,
} from 'react-router-dom';

import FeedbackSnackbar from './src/components/error_snackbar/feedback_snackbar';
import { SnackbarContextWrapper } from './src/context/snackbar_context';
import BaseLayout from './src/layouts/base';
import ClusterPage from './src/views/clusters/cluster/cluster_page';
import ClustersPage from './src/views/clusters/clusters_page';
import NotFoundPage from './src/views/errors/not_found_page';
import HelpPage from './src/views/help/help_page';
import HomePage from './src/views/home/home_page';
import NewRulePage from './src/views/new_rule/new_rule';
import Rule from './src/views/rule/rule';
import RulesPage from './src/views/rules/rules_page';
import BugPage from './src/views/bug/bug_page/bug_page';

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

const App = () => {
  return (
    <SnackbarContextWrapper>
      <QueryClientProvider client={queryClient}>
        <Routes>
          <Route path='/' element={<BaseLayout />}>
            <Route index element={<HomePage />} />
            <Route path='help' element={<HelpPage />} />
            <Route path='b/:bugTracker/:id' element={<BugPage />} />
            <Route path='p/:project'>
              <Route path='rules'>
                <Route index element={<RulesPage />} />
                <Route path='new' element={<NewRulePage />} />
                <Route path=':id' element={<Rule />} />
              </Route>
              <Route path='clusters'>
                <Route index element={<ClustersPage />} />
                <Route path=':algorithm/:id' element={<ClusterPage />} />
              </Route>
            </Route>
            <Route path='*' element={<NotFoundPage />} />
          </Route>
        </Routes>
      </QueryClientProvider>
      <FeedbackSnackbar />
    </SnackbarContextWrapper>
  );
};

export default App;
