// frontend/src/App.jsx
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import { Toaster } from 'react-hot-toast';
import { AuthProvider } from './context/AuthContext.jsx';
import AppShell from './components/layout/AppShell.jsx';
import { LoginPage, RegisterPage } from './pages/Auth.jsx';
import Dashboard from './pages/Dashboard.jsx';
import Settings from './pages/Settings.jsx';
import AdminDashboard from './pages/AdminDashboard.jsx';
import ContentLibrary from './pages/ContentLibrary.jsx';
import PipelineHistory from './pages/PipelineHistory.jsx';
import BillingPage from './pages/BillingPage.jsx';
import NicheBuilder from './pages/NicheBuilder.jsx';

export default function App() {
  return (
    <AuthProvider>
      <BrowserRouter>
        <Toaster position="top-right" toastOptions={{ duration: 4000, style: { borderRadius: '10px', fontSize: '14px' } }} />
        <Routes>
          {/* Public */}
          <Route path="/login" element={<LoginPage />} />
          <Route path="/register" element={<RegisterPage />} />
          <Route path="/" element={<Navigate to="/dashboard" replace />} />

          {/* Protected - Client dashboard */}
          <Route path="/dashboard" element={<AppShell><Dashboard /></AppShell>} />
          <Route path="/dashboard/niche" element={<AppShell><NicheBuilder /></AppShell>} />
          <Route path="/dashboard/content" element={<AppShell><ContentLibrary /></AppShell>} />
          <Route path="/dashboard/content/:id" element={<AppShell><ContentLibrary /></AppShell>} />
          <Route path="/dashboard/pipeline" element={<AppShell><PipelineHistory /></AppShell>} />
          <Route path="/dashboard/settings" element={<AppShell><Settings /></AppShell>} />
          <Route path="/dashboard/billing" element={<AppShell><BillingPage /></AppShell>} />

          {/* SuperAdmin */}
          <Route path="/admin" element={<AppShell><AdminDashboard /></AppShell>} />

          {/* Catch all */}
          <Route path="*" element={<Navigate to="/dashboard" replace />} />
        </Routes>
      </BrowserRouter>
    </AuthProvider>
  );
}
