"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { type KeyboardEvent, useEffect, useRef, useState } from "react"; import { NAVIGATION_ITEMS } from "@/lib/site-navigation"; import { isServiceOrCasePath, type WhatsAppContexts, whatsAppSubjectForPath, } from "@/lib/whatsapp"; import HoverPrefetchLink from "./HoverPrefetchLink"; import { Logo } from "./Logo"; import WhatsAppLink from "./WhatsAppLink"; const MENU_ID = "site-navigation-menu"; const CTA_LABEL = "Falar sobre meu projeto"; /** * Botão de contato do cabeçalho. Nas páginas de serviço e de case ele abre o WhatsApp já com o assunto da página; * nas demais leva ao formulário da home. */ function ContactCta({ className, placement, viaWhatsApp, subject, onNavigate, }: { className: string; placement: string; viaWhatsApp: boolean; subject?: string; onNavigate?: () => void; }) { if (viaWhatsApp) { return ( {CTA_LABEL} ); } return ( {CTA_LABEL} ); } export function Header({ whatsAppContexts, }: { /** Nomes dos serviços e dos cases, montados no servidor (app/layout.tsx), para o WhatsApp falar da página aberta. */ whatsAppContexts?: WhatsAppContexts; }) { const pathname = usePathname(); const viaWhatsApp = isServiceOrCasePath(pathname); const subject = whatsAppSubjectForPath(pathname, whatsAppContexts); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [scrolled, setScrolled] = useState(false); const menuButtonRef = useRef(null); useEffect(() => { let wasScrolled = false; const updateScrolled = () => { const nextScrolled = window.scrollY > 0; if (nextScrolled === wasScrolled) return; wasScrolled = nextScrolled; setScrolled(nextScrolled); }; updateScrolled(); window.addEventListener("scroll", updateScrolled, { passive: true }); return () => window.removeEventListener("scroll", updateScrolled); }, []); const closeMobileMenu = () => setMobileMenuOpen(false); const handleMenuKeyDown = (event: KeyboardEvent) => { if (event.key !== "Escape") return; event.preventDefault(); closeMobileMenu(); menuButtonRef.current?.focus(); }; return (
{mobileMenuOpen ? ( // Tela cheia abaixo da barra, com fundo opaco: o conteúdo da página não aparece por trás dos links.
) : null}
); }