"use client"; import { useState, useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Menu, X, Mail } from "lucide-react"; import { SiGithub, SiLinkedin } from "react-icons/si"; import Link from "next/link"; import { useLocale, useTranslations } from "next-intl"; import { usePathname, useRouter } from "next/navigation"; const Header = () => { const [isOpen, setIsOpen] = useState(false); const [scrolled, setScrolled] = useState(false); const locale = useLocale(); const pathname = usePathname(); const router = useRouter(); const t = useTranslations("nav"); const isHome = pathname === `/${locale}` || pathname === `/${locale}/`; useEffect(() => { const handleScroll = () => { setScrolled(window.scrollY > 50); }; window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); }, []); const navItems = [ { name: t("home"), href: `/${locale}` }, { name: t("about"), href: isHome ? "#about" : `/${locale}#about` }, { name: t("projects"), href: isHome ? "#projects" : `/${locale}/projects` }, { name: t("contact"), href: isHome ? "#contact" : `/${locale}#contact` }, ]; const socialLinks = [ { icon: SiGithub, href: "https://github.com/Denshooter", label: "GitHub" }, { icon: SiLinkedin, href: "https://linkedin.com/in/dkonkol", label: "LinkedIn", }, { icon: Mail, href: "mailto:contact@dk0.dev", label: "Email" }, ]; const switchLocale = (nextLocale: string) => { try { const pathWithoutLocale = pathname.replace(new RegExp(`^/${locale}`), "") || ""; const hash = typeof window !== "undefined" ? window.location.hash : ""; router.push(`/${nextLocale}${pathWithoutLocale}${hash}`); document.cookie = `NEXT_LOCALE=${nextLocale}; path=/`; } catch { // ignore } }; // Always render to prevent flash, but use opacity transition return ( <>
dk0
{socialLinks.map((social) => ( ))}
setIsOpen(!isOpen)} className="md:hidden p-2 rounded-full bg-white/40 hover:bg-white/60 text-stone-800 transition-colors liquid-hover" aria-label={isOpen ? "Close menu" : "Open menu"} > {isOpen ? : }
{isOpen && ( <> setIsOpen(false)} />
{navItems.map((item, index) => ( { setIsOpen(false); if (item.href.startsWith("#")) { e.preventDefault(); setTimeout(() => { const element = document.querySelector(item.href); if (element) { element.scrollIntoView({ behavior: "smooth", block: "start", }); } }, 100); } }} className="block text-stone-600 hover:text-stone-900 hover:bg-white/50 transition-all font-medium py-3 px-4 rounded-xl" > {item.name} ))}
{socialLinks.map((social, index) => ( ))}
)}
); }; export default Header;