"use client"; import { usePathname, useRouter } from 'next/navigation'; import { Button } from '../src/components/ui/button'; import Image from 'next/image'; import { useRef, useEffect } from 'react'; const examples = [ { name: "Chat", href: "/chat" }, { name: "Dashboard", href: "/dashboard" }, { name: "Mail", href: "/mail" }, { name: "Tree", href: "/tree" }, { name: "Editor", href: "/editor" }, { name: "Tables", href: "/table" }, { name: "Meet", href: "/meet" }, { name: "Videos", href: "/videos" }, { name: "Music", href: "/music" }, { name: "Templates", href: "/templates" }, { name: "Settings", href: "/settings" }, ]; export function Nav() { const pathname = usePathname(); const router = useRouter(); const scrollContainerRef = useRef(null); const navItemsRefs = useRef<(HTMLButtonElement | null)[]>([]); // Enhanced URL matching to handle sub-routes const isActive = (href: string) => { if (href === '/') return pathname === href; return pathname.startsWith(href); }; useEffect(() => { // Load GSAP from CDN 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; // Animate navigation items on mount 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)" } ); // Add hover animations navItemsRefs.current.forEach((item, index) => { 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" }); }); } }); // Animate logo gsap.fromTo('.logo', { opacity: 0, x: -20, rotate: -10 }, { opacity: 1, x: 0, rotate: 0, duration: 0.8, ease: "elastic.out(1, 0.5)" } ); }; document.head.appendChild(script); return () => { if (document.head.contains(script)) { document.head.removeChild(script); } }; }, []); // Smooth scroll functions for mobile const scrollLeft = () => { if (scrollContainerRef.current) { scrollContainerRef.current.scrollBy({ left: -150, behavior: 'smooth' }); } }; const scrollRight = () => { if (scrollContainerRef.current) { scrollContainerRef.current.scrollBy({ left: 150, behavior: 'smooth' }); } }; return ( <>
Logo
{examples.map((example, index) => { const active = isActive(example.href); return ( ); })}
); }