import { Routes, Route, Link, useLocation, Navigate } from "react-router-dom";
import Home from "./pages/Home";
import AgentCreator from "./pages/AgentCreator";
import ChatToAgent from "./pages/ChatToAgent";
import AgentGallery from "./pages/AgentGallery";
import { usePrivy, useSolanaWallets } from '@privy-io/react-auth';
import "./App.css";

// Protected Route wrapper component
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
  const { authenticated } = usePrivy();
  const { wallets } =  useSolanaWallets()
  console.log(wallets[0]);
  if (!authenticated && wallets.length===0) {
    return <Navigate to="/" replace />;
  }
  
  return <>{children}</>;
};

function App() {
  const location = useLocation();
  const { authenticated } = usePrivy();
  
  // Helper function to determine if link is active
  const isActive = (path: string) => location.pathname === path;

  return (
    <div id="root" className="min-h-screen font-roboto">
      <main>
        <Routes>
          {/* Public route */}
          <Route path="/" element={<Home />} />
          
          {/* Protected routes */}
          <Route 
            path="/create-agent" 
            element={
              <ProtectedRoute>
                <AgentCreator />
              </ProtectedRoute>
            } 
          />
          <Route 
            path="/browse-agents" 
            element={
              <ProtectedRoute>
                <AgentGallery />
              </ProtectedRoute>
            } 
          />
          <Route 
            path="/chat" 
            element={
              <ProtectedRoute>
                <ChatToAgent />
              </ProtectedRoute>
            } 
          />
        </Routes>
      </main>
    </div>
  );
}

export default App;