import { useState, useEffect, useRef } from "react"; import { Home, User, FolderOpen, BookOpen, FileText, Settings } from "lucide-react"; import { SettingsSheet } from "./settings-sheet"; const tabs = [ { href: "/", label: "Home", icon: Home, color: "text-green" }, { href: "/about", label: "About", icon: User, color: "text-yellow" }, { href: "/projects", label: "Projects", icon: FolderOpen, color: "text-blue" }, { href: "/blog", label: "Blog", icon: BookOpen, color: "text-purple" }, { href: "/resume", label: "Resume", icon: FileText, color: "text-aqua" }, ]; export default function MobileNav({ transparent = false }: { transparent?: boolean }) { const [path, setPath] = useState("/"); const [settingsOpen, setSettingsOpen] = useState(false); const [visible, setVisible] = useState(true); const lastScrollY = useRef(0); const lastTime = useRef(Date.now()); useEffect(() => { setPath(window.location.pathname); }, []); useEffect(() => { const handleScroll = () => { const y = document.documentElement.scrollTop; const now = Date.now(); const dt = now - lastTime.current; const dy = lastScrollY.current - y; // positive = scrolling up const velocity = dt > 0 ? dy / dt : 0; // px/ms if (y < 10) { setVisible(true); } else if (dy > 0 && velocity > 1.5) { // Fast upward scroll setVisible(true); } else if (dy < 0) { // Scrolling down setVisible(false); } lastScrollY.current = y; lastTime.current = now; }; document.addEventListener("scroll", handleScroll, { passive: true }); return () => document.removeEventListener("scroll", handleScroll); }, []); const isActive = (href: string) => { if (href === "/") return path === "/"; return path.startsWith(href); }; return ( <> {tabs.map((tab) => { const Icon = tab.icon; const active = isActive(tab.href); return ( {tab.label} ); })} setSettingsOpen(true)} className={`flex flex-col items-center justify-center gap-0.5 flex-1 py-1 ${ settingsOpen ? "text-foreground" : "text-foreground/40" }`} > Settings setSettingsOpen(false)} /> > ); }