"use client"; import { usePathname, useRouter } from 'next/navigation'; import Image from 'next/image'; import { useRef, useEffect, useState } from 'react'; import { useTheme } from './theme-provider'; const examples = [ { name: "Chat", href: "/chat", color: "#25D366" }, // WhatsApp green { name: "Dashboard", href: "/dashboard", color: "#6366F1" }, // Indigo { name: "Mail", href: "/mail", color: "#FFD700" }, // Outlook yellow { name: "Calendar", href: "/calendar", color: "#1DB954" }, // Spotify green { name: "Meet", href: "/meet", color: "#059669" }, // Google Meet green { name: "Drive", href: "/drive", color: "#10B981" }, // Emerald green { name: "Editor", href: "/editor", color: "#2563EB" }, // Word blue { name: "Tables", href: "/tables", color: "#8B5CF6" }, // Purple { name: "Media", href: "/media", color: "Yellow" }, { name: "News", href: "/news", color: "blue" }, { name: "Templates", href: "/templates", color: "#F59E0B" }, // Amber { name: "Settings", href: "/settings", color: "#6B7280" }, // Gray ]; export function Nav() { const pathname = usePathname(); const router = useRouter(); const scrollContainerRef = useRef(null); const navItemsRefs = useRef<(HTMLButtonElement | null)[]>([]); const [isLoggedIn, setIsLoggedIn] = useState(false); const [showLoginMenu, setShowLoginMenu] = useState(false); const [showScrollButtons, setShowScrollButtons] = useState(false); const loginMenuRef = useRef(null); const [showThemeMenu, setShowThemeMenu] = useState(false); const themeMenuRef = useRef(null); const { theme, setTheme, themes } = useTheme(); const isActive = (href: string) => { if (href === '/') return pathname === href; return pathname.startsWith(href); }; const handleLogin = () => { setIsLoggedIn(true); setShowLoginMenu(false); }; const handleLogout = () => { setIsLoggedIn(false); setShowLoginMenu(false); }; const checkScrollNeeded = () => { if (scrollContainerRef.current) { const container = scrollContainerRef.current; const isScrollable = container.scrollWidth > container.clientWidth; setShowScrollButtons(isScrollable); } }; useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (loginMenuRef.current && !loginMenuRef.current.contains(event.target as Node)) { setShowLoginMenu(false); } if (themeMenuRef.current && !themeMenuRef.current.contains(event.target as Node)) { setShowThemeMenu(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); useEffect(() => { checkScrollNeeded(); window.addEventListener('resize', checkScrollNeeded); return () => window.removeEventListener('resize', checkScrollNeeded); }, []); useEffect(() => { const script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js'; script.onload = () => { const gsap = window.gsap; gsap.fromTo('.nav-item', { opacity: 0, y: -10, scale: 0.9 }, { opacity: 1, y: 0, scale: 1, duration: 0.6, stagger: 0.1, ease: "back.out(1.7)" } ); navItemsRefs.current.forEach((item) => { if (item) { item.addEventListener('mouseenter', () => { gsap.to(item, { scale: 1.05, duration: 0.3, ease: "power2.out" }); }); item.addEventListener('mouseleave', () => { gsap.to(item, { scale: 1, duration: 0.3, ease: "power2.out" }); }); item.addEventListener('click', () => { gsap.to(item, { scale: 0.95, duration: 0.1, yoyo: true, repeat: 1, ease: "power2.inOut" }); }); } }); gsap.fromTo('.theme-toggle', { opacity: 0, x: 20, scale: 0.8 }, { opacity: 1, x: 0, scale: 1, duration: 0.8, delay: 0.3, ease: "elastic.out(1, 0.5)" } ); gsap.fromTo('.login-button', { opacity: 0, x: 20, scale: 0.8 }, { opacity: 1, x: 0, scale: 1, duration: 0.8, delay: 0.4, ease: "elastic.out(1, 0.5)" } ); }; document.head.appendChild(script); return () => { if (document.head.contains(script)) { document.head.removeChild(script); } }; }, []); const scrollLeft = () => { scrollContainerRef.current?.scrollBy({ left: -150, behavior: 'smooth' }); }; const scrollRight = () => { scrollContainerRef.current?.scrollBy({ left: 150, behavior: 'smooth' }); }; const getThemeIcon = () => { switch(theme.name) { case 'retrowave': return '🌌'; case 'vapordream': return '🌀'; case 'y2kglow': return 'đŸ’ŋ'; case 'mellowgold': return 'â˜Žī¸'; case 'arcadeflash': return 'đŸ•šī¸'; case 'polaroidmemories': return '📸'; case 'midcenturymod': return 'đŸĒ‘'; case 'grungeera': return '🎸'; case 'discofever': return 'đŸĒŠ'; case 'saturdaycartoons': return 'đŸ“ē'; case 'oldhollywood': return 'đŸŽŦ'; case 'cyberpunk': return '🤖'; case 'seasidepostcard': return 'đŸ–ī¸'; case 'typewriter': return 'âŒ¨ī¸'; case 'jazzage': return '🎷'; default: return '🎨'; } }; return ( <>
Logo
{showScrollButtons && ( )}
{examples.map((example, index) => { const active = isActive(example.href); return ( ); })}
{showScrollButtons && ( )}
{showLoginMenu && (
{!isLoggedIn ? ( ) : ( )}
)}
{showThemeMenu && (
{themes.map((t) => ( ))}
)}
); }