(function (global) { const { useState, useRef, useEffect, useCallback } = React; function SocialIcon({ id }) { if (id === 'facebook') { return ( ); } if (id === 'instagram') { return ( ); } return ( ); } function Header() { const navConfig = global.SHIELD_POINT_NAV; const { ServicesMegaMenu, MobileNavDrawer } = global.ShieldPointComponents; const [megaMenuOpen, setMegaMenuOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [headerHidden, setHeaderHidden] = useState(false); const [showScrollTop, setShowScrollTop] = useState(false); const [theme, setTheme] = useState(() => { if (typeof window !== 'undefined') { const saved = localStorage.getItem('sp_theme'); if (saved === 'dark' || saved === 'light') return saved; } return 'light'; }); const [activeLink, setActiveLink] = useState(() => { if (typeof window !== 'undefined') { const path = window.location.pathname.replace(/\/+$/, '') || '/'; if (path === '/about' || path.endsWith('/about.html')) return 'about'; if (path === '/contact' || path === '/contact-us' || path.endsWith('/contact.html')) return 'contact'; if ( path === '/blog' || path.endsWith('/blog.html') || path.endsWith('/blog-post.html') ) { return 'blog'; } if (path.includes('/services/')) return 'services'; } return 'home'; }); useEffect(() => { if (typeof document !== 'undefined') { document.documentElement.setAttribute('data-theme', theme); localStorage.setItem('sp_theme', theme); } }, [theme]); const toggleTheme = () => { setTheme((prev) => (prev === 'dark' ? 'light' : 'dark')); }; const headerRef = useRef(null); const servicesTriggerRef = useRef(null); const hoverTimeoutRef = useRef(null); const lastScrollYRef = useRef(0); useEffect(() => { const handleScroll = () => { const currentY = window.scrollY || window.pageYOffset || 0; setShowScrollTop(currentY > 320); if (megaMenuOpen || mobileMenuOpen || currentY < 100) { setHeaderHidden(false); lastScrollYRef.current = currentY; return; } const delta = currentY - lastScrollYRef.current; if (delta > 8) { setHeaderHidden(true); lastScrollYRef.current = currentY; } else if (delta < -8) { setHeaderHidden(false); lastScrollYRef.current = currentY; } }; window.addEventListener('scroll', handleScroll, { passive: true }); return () => window.removeEventListener('scroll', handleScroll); }, [megaMenuOpen, mobileMenuOpen]); const scrollToTop = () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }; const clearHoverTimeout = useCallback(() => { if (hoverTimeoutRef.current) { clearTimeout(hoverTimeoutRef.current); hoverTimeoutRef.current = null; } }, []); const openMegaMenu = useCallback(() => { clearHoverTimeout(); setMegaMenuOpen(true); }, [clearHoverTimeout]); const scheduleCloseMegaMenu = useCallback(() => { clearHoverTimeout(); hoverTimeoutRef.current = setTimeout(() => { setMegaMenuOpen(false); }, 150); }, [clearHoverTimeout]); const closeMegaMenuImmediately = useCallback(() => { clearHoverTimeout(); setMegaMenuOpen(false); }, [clearHoverTimeout]); useEffect(() => { const handleClickOutside = (event) => { if (headerRef.current && !headerRef.current.contains(event.target)) { closeMegaMenuImmediately(); } }; const handleKeyDown = (event) => { if (event.key === 'Escape' && megaMenuOpen) { closeMegaMenuImmediately(); if (servicesTriggerRef.current) { servicesTriggerRef.current.focus(); } } }; document.addEventListener('mousedown', handleClickOutside); document.addEventListener('keydown', handleKeyDown); return () => { document.removeEventListener('mousedown', handleClickOutside); document.removeEventListener('keydown', handleKeyDown); clearHoverTimeout(); }; }, [megaMenuOpen, closeMegaMenuImmediately, clearHoverTimeout]); const handleServicesKeyDown = (event) => { if (event.key === 'ArrowDown') { event.preventDefault(); openMegaMenu(); } else if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); setMegaMenuOpen((prev) => !prev); } }; return ( Skip to main content {/* Top Utility & Social Bar */} {navConfig.topBar.location} {navConfig.topBar.phoneDisplay} Follow Us: {navConfig.topBar.socials.map((social) => ( ))} {/* Left Side: Official Brand Logo */} { setActiveLink('home'); closeMegaMenuImmediately(); }} > {navConfig.brand.name} {navConfig.brand.tagline} {/* Center Navigation */} {navConfig.links.map((item) => { if (item.hasMegaMenu) { return ( setMegaMenuOpen((prev) => !prev)} onKeyDown={handleServicesKeyDown} > {item.label} ); } return ( { setActiveLink(item.id); closeMegaMenuImmediately(); }} > {item.label} ); })} {/* Right Side: Day/Night Toggle + Request Appointment WhatsApp CTA + Mobile Hamburger */} {theme === 'dark' ? ( ) : ( )} {navConfig.cta.label} setMobileMenuOpen(true)} > {/* Services Mega Dropdown Menu */} {/* Mobile / Tablet Navigation Drawer */} setMobileMenuOpen(false)} /> {/* Global Floating Bottom-Right Actions (Go To Top above WhatsApp) */} ); } global.ShieldPointComponents = global.ShieldPointComponents || {}; global.ShieldPointComponents.Header = Header; })(window);