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

// Front-facing pages
import IndexPage from "./pages/Anonymous/Index/IndexPage";
import DownloadPage from "./pages/Anonymous/Download/DownloadPage";

// Registration pages
import Register from "./pages/Anonymous/Register/Register";
import RecoveryCode from "./pages/Anonymous/Register/RecoveryCode";
import VerifyEmail from "./pages/Anonymous/Register/VerifyEmail";
import VerifySuccess from "./pages/Anonymous/Register/VerifySuccess";

// Login pages
import RequestOTT from "./pages/Anonymous/Login/RequestOTT";
import VerifyOTT from "./pages/Anonymous/Login/VerifyOTT";
import CompleteLogin from "./pages/Anonymous/Login/CompleteLogin";
import SessionExpired from "./pages/Anonymous/Login/SessionExpired";

// Recovery pages
import InitiateRecovery from "./pages/Anonymous/Recovery/InitiateRecovery";
import VerifyRecovery from "./pages/Anonymous/Recovery/VerifyRecovery";
import CompleteRecovery from "./pages/Anonymous/Recovery/CompleteRecovery";

// User pages
import Dashboard from "./pages/User/Dashboard/Dashboard";
import MeDetail from "./pages/User/Me/Detail";
import DeleteAccount from "./pages/User/Me/DeleteAccount";
import ExportData from "./pages/User/Me/ExportData";
import BlockedUsers from "./pages/User/Me/BlockedUsers";
import Help from "./pages/User/Help/Help";

// Collection & File Manager
import FileManagerIndex from "./pages/User/FileManager/FileManagerIndex";
import CollectionCreate from "./pages/User/FileManager/Collections/CollectionCreate";
import CollectionDetails from "./pages/User/FileManager/Collections/CollectionDetails";
import CollectionShare from "./pages/User/FileManager/Collections/CollectionShare";
import CollectionEdit from "./pages/User/FileManager/Collections/CollectionEdit";
import FileUpload from "./pages/User/FileManager/Files/FileUpload";
import FileDetails from "./pages/User/FileManager/Files/FileDetails";

// Tags
import TagList from "./pages/User/Tags/TagList";
import TagCreate from "./pages/User/Tags/TagCreate";
import TagEdit from "./pages/User/Tags/TagEdit";
import TagDelete from "./pages/User/Tags/TagDelete";
import TagSearch from "./pages/User/Tags/TagSearch";
import TagSearchResults from "./pages/User/Tags/TagSearchResults";

// Styles
const styles = {
  app: {
    minHeight: "100vh",
    backgroundColor: "#f5f5f5",
  },
};

// Main App component
function App() {
  return (
    <ServiceProvider>
      <Router>
        <div style={styles.app}>
          <Routes>
            {/* Front-facing pages */}
            <Route path="/" element={<IndexPage />} />
            <Route path="/download" element={<DownloadPage />} />

            {/* Registration routes */}
            <Route path="/register" element={<Register />} />
            <Route path="/register/recovery" element={<RecoveryCode />} />
            <Route path="/register/verify-email" element={<VerifyEmail />} />
            <Route path="/register/verify-success" element={<VerifySuccess />} />

            {/* Login routes */}
            <Route path="/login" element={<RequestOTT />} />
            <Route path="/login/verify-ott" element={<VerifyOTT />} />
            <Route path="/login/complete" element={<CompleteLogin />} />
            <Route path="/session-expired" element={<SessionExpired />} />

            {/* Recovery routes */}
            <Route path="/recovery" element={<InitiateRecovery />} />
            <Route path="/recovery/initiate" element={<InitiateRecovery />} />
            <Route path="/recovery/verify" element={<VerifyRecovery />} />
            <Route path="/recovery/complete" element={<CompleteRecovery />} />

            {/* User routes */}
            <Route path="/dashboard" element={<Dashboard />} />
            <Route path="/me" element={<MeDetail />} />
            <Route path="/me/delete-account" element={<DeleteAccount />} />
            <Route path="/me/export-data" element={<ExportData />} />
            <Route path="/me/blocked-users" element={<BlockedUsers />} />
            <Route path="/profile" element={<MeDetail />} />
            <Route path="/help" element={<Help />} />

            {/* File Manager Routes */}
            <Route path="/file-manager" element={<FileManagerIndex />} />
            <Route path="/file-manager/collections/create" element={<CollectionCreate />} />
            <Route path="/file-manager/collections/:collectionId" element={<CollectionDetails />} />
            <Route path="/file-manager/collections/:collectionId/share" element={<CollectionShare />} />
            <Route path="/file-manager/collections/:collectionId/edit" element={<CollectionEdit />} />
            <Route path="/file-manager/upload" element={<FileUpload />} />
            <Route path="/file-manager/files/:fileId" element={<FileDetails />} />

            {/* Tag Routes */}
            <Route path="/me/tags" element={<TagList />} />
            <Route path="/me/tags/create" element={<TagCreate />} />
            <Route path="/me/tags/:tagId/edit" element={<TagEdit />} />
            <Route path="/me/tags/:tagId/delete" element={<TagDelete />} />
            <Route path="/me/tags/search" element={<TagSearch />} />
            <Route path="/me/tags/search/results" element={<TagSearchResults />} />

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

export default App;
