import { Navigate, Route, Routes } from 'react-router-dom'
import { Layout } from './components/Layout'
import { ProtectedRoute } from './components/ProtectedRoute'
import { Login } from './pages/Login'
import { Dashboard } from './pages/Dashboard'
import { JobList } from './pages/Jobs/JobList'
import { JobCreate } from './pages/Jobs/JobCreate'
import { JobEdit } from './pages/Jobs/JobEdit'
import { History } from './pages/History'
import { RunDetail } from './pages/RunDetail'
import { Storages } from './pages/Storages'
import { Restore } from './pages/Restore'
import { Settings } from './pages/Settings'

export function AppRouter() {
  return (
    <Routes>
      <Route path="/login" element={<Login />} />
      <Route
        path="/"
        element={
          <ProtectedRoute>
            <Layout />
          </ProtectedRoute>
        }
      >
        <Route index element={<Navigate to="/dashboard" replace />} />
        <Route path="dashboard" element={<Dashboard />} />
        <Route path="jobs" element={<JobList />} />
        <Route path="jobs/new" element={<JobCreate />} />
        <Route path="jobs/:id/edit" element={<JobEdit />} />
        <Route path="history" element={<History />} />
        <Route path="runs/:id" element={<RunDetail />} />
        <Route path="storages" element={<Storages />} />
        <Route path="restore" element={<Restore />} />
        <Route path="settings" element={<Settings />} />
      </Route>
      <Route path="*" element={<Navigate to="/" replace />} />
    </Routes>
  )
}
