import { useState } from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { ErrorBoundary } from "./components/ErrorBoundary";
import HomePage from "./pages/HomePage";
import DealPage from "./pages/DealDetailsPage";
import CreateDealPage from "./pages/CreateDealPage";
import AccountSettingsPage from "./pages/AccountSettingsPage";
import ProfilePage from "./pages/ProfilePage";
import SearchPage from "./pages/SearchPage";
import CategoryPage from "./pages/CategoryPage"; // CategoryPage importu

import LoginModal from "./components/Auth/LoginModal";

export default function App() {
  const [showLoginModal, setShowLoginModal] = useState(false);

  return (
    <ErrorBoundary>
      <BrowserRouter>
        {showLoginModal && (
          <LoginModal
            onClose={() => setShowLoginModal(false)}
          />
        )}

        <Routes>
          {/* HomePage route */}
          <Route 
            path="/" 
            element={<HomePage onRequireLogin={() => setShowLoginModal(true)} />} 
          />

          {/* DealPage route */}
          <Route
            path="/deal/:id"
            element={<DealPage onRequireLogin={() => setShowLoginModal(true)} />}
          />

          {/* SearchPage route */}
          <Route
            path="/search"
            element={<SearchPage onRequireLogin={() => setShowLoginModal(true)} />}
          />

          {/* CategoryPage route */}
          <Route
            path="/category/:categorySlug"
            element={<CategoryPage />}
          />

          {/* CreateDealPage route */}
          <Route
            path="/create-deal"
            element={<CreateDealPage />}
          />

          {/* AccountSettingsPage route */}
          <Route
            path="/account"
            element={<AccountSettingsPage />}
          />

          {/* ProfilePage route */}
          <Route
            path="/user/:userName"
            element={<ProfilePage />}
          />
        </Routes>
      </BrowserRouter>
    </ErrorBoundary>
  );
}
