"use client"; import Image from "next/image"; import { useEffect, useRef, useState } from "react"; import { gsap } from "gsap"; import Button from "./Button"; import SmoothScrollLink from "@/components/ui/smooth-scroll-link"; import Link from "next/link"; import { usePageTransition } from "@/layout/Layout"; const Navbar = () => { const navbarRef = useRef(null); const [scrolled, setScrolled] = useState(false); const [showNavbar, setShowNavbar] = useState(true); const { startTransition } = usePageTransition(); const [lastScrollY, setLastScrollY] = useState(0); // ── GSAP: Initial slide-in ───────────────────────────────────── useEffect(() => { const el = navbarRef.current; if (!el) return; // Start off-screen gsap.set(el, { yPercent: -100, opacity: 0 }); // Animate in gsap.to(el, { yPercent: 0, opacity: 1, duration: 1.2, ease: "expo.out", }); }, []); // ── Scroll: Hide/show + background ───────────────────────────── useEffect(() => { const handleScroll = () => { const currentScroll = window.scrollY; // Hide on scroll down if (currentScroll > lastScrollY && currentScroll > 100) { setShowNavbar(false); } else { setShowNavbar(true); } setScrolled(currentScroll > 30); setLastScrollY(currentScroll); }; window.addEventListener("scroll", handleScroll, { passive: true }); return () => window.removeEventListener("scroll", handleScroll); }, [lastScrollY]); const navLinks = [ { label: "Home", href: "#home" }, { label: "About Us", href: "#about" }, { label: "Benefits", href: "#benefits" }, { label: "How it works", href: "/#how-it-works" }, { label: "FAQ", href: "#faq" }, ]; return (
); }; export default Navbar;