import { useState, useEffect, useRef } from "react"; import { Links } from "@/components/header/links"; export default function Header({ transparent = false }: { transparent?: boolean }) { const [isClient, setIsClient] = useState(false); const [visible, setVisible] = useState(true); const [lastScrollY, setLastScrollY] = useState(0); const [currentPath, setCurrentPath] = useState(""); const [shouldAnimate, setShouldAnimate] = useState(false); useEffect(() => { setIsClient(true); setCurrentPath(document.location.pathname); setTimeout(() => setShouldAnimate(true), 50); }, []); useEffect(() => { if (!isClient) return; const handleScroll = () => { const currentScrollY = document.documentElement.scrollTop; setVisible(currentScrollY < lastScrollY || currentScrollY < 10); setLastScrollY(currentScrollY); }; document.addEventListener("scroll", handleScroll); return () => document.removeEventListener("scroll", handleScroll); }, [lastScrollY, isClient]); const checkIsActive = (linkHref: string): boolean => { if (!isClient) return false; const path = document.location.pathname; if (linkHref === "/") return path === "/"; return linkHref !== "/" && path.startsWith(linkHref); }; const isIndexPage = transparent || checkIsActive("/"); const headerLinks = Links.map((link) => { const isActive = checkIsActive(link.href); return (
); }); return (