import { BrowserRouter, Routes, Route } from 'react-router-dom'
import { AuthProvider } from './context/AuthContext'
import { ToastProvider } from './context/ToastContext'
import { AdminDomainGuard } from './components/AdminDomainGuard'
import { ProtectedRoute } from './components/ProtectedRoute'
import { GuestRoute } from './components/GuestRoute'
import { PageLayout } from './components/PageLayout'
import { HomePage } from './pages/HomePage'
import { BusinessesPage } from './pages/BusinessesPage'
import { UsersPage } from './pages/UsersPage'
import { WebsitesPage } from './pages/WebsitesPage'
import { ProfilePage } from './pages/ProfilePage'
import { LoginPage } from './pages/LoginPage'

function App() {
  return (
    <AdminDomainGuard>
      <BrowserRouter>
        <AuthProvider>
          <ToastProvider>
            <Routes>
              <Route element={<GuestRoute />}>
                <Route path="login" element={<LoginPage />} />
              </Route>

              <Route element={<ProtectedRoute />}>
                <Route element={<PageLayout />}>
                  <Route index element={<HomePage />} />
                  <Route path="businesses" element={<BusinessesPage />} />
                  <Route path="users" element={<UsersPage />} />
                  <Route path="websites" element={<WebsitesPage />} />
                  <Route path="profile" element={<ProfilePage />} />
                </Route>
              </Route>
            </Routes>
          </ToastProvider>
        </AuthProvider>
      </BrowserRouter>
    </AdminDomainGuard>
  )
}

export default App
