import React, { Fragment } from 'react'
import {
  Route,
  Redirect,
  Switch,
} from 'react-router-dom'

import { PAGES } from 'config'
import { publicLexics } from 'config/lexics/public'

import { Login } from 'features/Login'
import { Register } from 'features/Register'
import { LanguageSelect } from 'features/LanguageSelect'
import { useLexicsConfig } from 'features/LexicsStore'

export const UnauthenticatedApp = () => {
  useLexicsConfig(publicLexics)
  return (
    <Fragment>
      <LanguageSelect />
      <Switch>
        <Route path={PAGES.login}>
          <Login />
        </Route>

        <Route path={PAGES.register}>
          <Register />
        </Route>

        <Redirect to={PAGES.login} />
      </Switch>
    </Fragment>
  )
}
