import { Routes, Route, Navigate } from 'react-router-dom'
import { useAuthStore } from './stores/auth'
import Login from './pages/Login/Login'
import Dashboard from './pages/Dashboard/Dashboard'
import Users from './pages/Users/Users'
import DataSources from './pages/DataSources/DataSources'
import DataList from './pages/DataList/DataList'
import Earth from './pages/Earth/Earth'

function App() {
  const { token } = useAuthStore()
  const isEarthPage = window.location.pathname === '/earth'

  if (!token && !isEarthPage) {
    return <Login />
  }

  return (
    <Routes>
      <Route path="/" element={<Dashboard />} />
      <Route path="/admin" element={<Dashboard />} />
      <Route path="/earth" element={<Earth />} />
      <Route path="/users" element={<Users />} />
      <Route path="/datasources" element={<DataSources />} />
      <Route path="/data" element={<DataList />} />
      <Route path="*" element={<Navigate to="/" replace />} />
    </Routes>
  )
}

export default App
