// File: src/App.jsx
import React from "react";
import { BrowserRouter as Router, Routes, Route, Navigate } from "react-router";
import { ServiceProvider } from "./services/Services";

// Pages
import IndexPage from "./pages/Home/IndexPage";
import Login from "./pages/Auth/Login";
import Register from "./pages/Auth/Register";
import Dashboard from "./pages/Dashboard/Dashboard";
import AddSite from "./pages/Sites/AddSite";
import AddSiteSuccess from "./pages/Sites/AddSiteSuccess";
import SiteDetail from "./pages/Sites/SiteDetail";
import DeleteSite from "./pages/Sites/DeleteSite";
import RotateApiKey from "./pages/Sites/RotateApiKey";

/**
 * App - Main application component
 *
 * Sets up routing and service provider
 */
function App() {
  return (
    <ServiceProvider>
      <Router>
        <div className="min-h-screen">
          <Routes>
            {/* Public routes */}
            <Route path="/" element={<IndexPage />} />
            <Route path="/login" element={<Login />} />
            <Route path="/register" element={<Register />} />

            {/* Protected routes */}
            <Route path="/dashboard" element={<Dashboard />} />
            <Route path="/sites/add" element={<AddSite />} />
            <Route path="/sites/add-success" element={<AddSiteSuccess />} />
            <Route path="/sites/:id" element={<SiteDetail />} />
            <Route path="/sites/:id/delete" element={<DeleteSite />} />
            <Route path="/sites/:id/rotate-key" element={<RotateApiKey />} />

            {/* Redirect unknown routes to home */}
            <Route path="*" element={<Navigate to="/" />} />
          </Routes>
        </div>
      </Router>
    </ServiceProvider>
  );
}

export default App;
