import React from 'react'
import PropTypes from 'prop-types'
import { ToastContainer } from 'react-toastify'
import { createBrowserHistory } from 'history'
import { Router, Redirect, Switch, Route } from 'react-router-dom'
import { BondeSessionProvider, BondeSessionUI } from 'bonde-core-tools'
import { Loading } from 'bonde-components'
// import { ProviderRedux } from './services/redux'
// Routes
// import Dashboard from './scenes/Dashboard'
// import { Root as AuthRoot } from './scenes/Auth'
import HomePage from 'scenes/HomePage'
import CommunityPage from 'scenes/CommunityPage'
// import SettingsPage from './scenes/Dashboard/scenes/Settings'
// import TagsPage from './scenes/Dashboard/scenes/Tags'
// import InvitationsPage from './scenes/Dashboard/scenes/Invitations'
import { NotFound } from 'components'
// Styles
import 'react-toastify/dist/ReactToastify.css'

const TextLoading = ({ fetching }) => {
  const messages = {
    session: 'Carregando sessão...',
    user: 'Carregando usuário...',
    communities: 'Carregando communities...',
    redirect: 'Redirecionando para autenticação...'
  }
  return <Loading fullsize message={messages[fetching]} />
}

TextLoading.propTypes = {
  fetching: PropTypes.string.isRequired
}

BondeSessionProvider.displayName = 'BondeSessionProvider'

const history = createBrowserHistory()

const Root = () => (
  <BondeSessionProvider
    fetchData
    environment={process.env.REACT_APP_ENVIRONMENT || 'development'}
    loading={TextLoading}
  >
    <Router history={history}>
      <BondeSessionUI.Main indexRoute='/'>
        <ToastContainer
          className='BondeToastify'
          hideProgressBar={true}
        />
        <Switch>
          <Route exact path='/' component={HomePage} />
          <Route path='/community' component={CommunityPage} />
          <Redirect from='/admin' to='/' />
          <Route component={NotFound} />
        </Switch>
      </BondeSessionUI.Main>
    </Router>
  </BondeSessionProvider>
)

export default Root

@@ -189,16 +189,29 @@
 h, Route
+, useLocation
  %7D from 
@@ -227,12 +227,8 @@
 uter
--dom
 '%0Aim
@@ -588,16 +588,55 @@
 tyPage'%0A
+import UserPage from 'scenes/UserPage'%0A
 // impor
@@ -916,16 +916,592 @@
 y.css'%0A%0A
+const PagesRoute = () =%3E %7B%0A  const location = useLocation()%0A%0A  return (%0A    %3CBondeSessionUI%0A      indexRoute='/'%0A      disableNavigation=%7Blocation.pathname === '/'%7D%0A    %3E%0A      %3CToastContainer%0A        className='BondeToastify'%0A        hideProgressBar=%7Btrue%7D%0A      /%3E%0A      %3CSwitch%3E%0A        %3CRoute exact path='/' component=%7BHomePage%7D /%3E%0A        %3CRoute path='/community' component=%7BCommunityPage%7D /%3E%0A        %3CRoute path='/user' component=%7BUserPage%7D /%3E%0A        %3CRedirect from='/admin' to='/' /%3E%0A        %3CRoute component=%7BNotFound%7D /%3E%0A      %3C/Switch%3E%0A    %3C/BondeSessionUI%3E%0A  )%0A%7D%0A%0A
 const Te
@@ -2157,415 +2157,20 @@
    %3C
-BondeSessionUI.Main indexRoute='/'%3E%0A        %3CToastContainer%0A          className='BondeToastify'%0A          hideProgressBar=%7Btrue%7D%0A        /%3E%0A        %3CSwitch%3E%0A          %3CRoute exact path='/' component=%7BHomePage%7D /%3E%0A          %3CRoute path='/community' component=%7BCommunityPage%7D /%3E%0A          %3CRedirect from='/admin' to='/' /%3E%0A          %3CRoute component=%7BNotFound%7D /%3E%0A        %3C/Switch%3E%0A      %3C/BondeSessionUI.Main
+PagesRoute /
 %3E%0A  

disable community navigation in home