"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import type { LucideIcon } from "lucide-react"; import { ShieldCheck, Menu, X, Crown, GitCompare, LayoutDashboard, ScanText, Settings, LogIn, Zap, Sparkles, CreditCard, UserCircle, LogOut, Users } from "lucide-react"; import { useState, useEffect } from "react"; import { createClient } from "@/lib/supabase/client"; interface NavLink { href: string; label: string; icon?: LucideIcon; } export function Nav() { const [open, setOpen] = useState(false); const [userEmail, setUserEmail] = useState(null); const [userRole, setUserRole] = useState(null); const [userTeam, setUserTeam] = useState(null); const [loaded, setLoaded] = useState(false); const pathname = usePathname(); const isLoggedIn = !!userEmail; const isAdmin = userRole === "admin"; const hasTeam = !!userTeam; useEffect(() => { try { const supabase = createClient(); supabase.auth.getUser().then(async ({ data, error }) => { if (error) { console.error("Auth error:", error); setLoaded(true); return; } const user = data.user; setUserEmail(user?.email || null); if (user) { try { const { data: profile } = await supabase .from("profiles") .select("role, team_id") .eq("id", user.id) .single(); setUserRole(profile?.role || "user"); setUserTeam(profile?.team_id || null); } catch (err) { console.error("Profile error:", err); } } setLoaded(true); }).catch(err => { console.error("Unexpected error:", err); setLoaded(true); }); } catch (err) { console.error("Supabase client init error:", err); // Fallback for when env variables are not found/configured setLoaded(true); } }, []); async function handleSignOut() { const supabase = createClient(); await supabase.auth.signOut(); setUserEmail(null); setUserRole(null); setUserTeam(null); window.location.href = "/"; } // Public links - always visible const mainLinks: NavLink[] = [ { href: "/#features", label: "Features", icon: Sparkles }, { href: "/#pricing", label: "Pricing", icon: CreditCard }, { href: "/dashboard-pages/analyze", label: "Scanner", icon: ScanText }, { href: "/dashboard-pages/compare", label: "Compare", icon: GitCompare }, ]; return ( ); }