// Deezer-aware Nav with auto-inverting color (floating pill). // Detects which section is currently behind the nav and inverts colors. function NavDeezer() { const [open, setOpen] = React.useState(false); const [overDark, setOverDark] = React.useState(false); const navRef = React.useRef(null); const isHome = React.useMemo(() => { if (typeof window === 'undefined') return true; const p = window.location.pathname; return p.endsWith('/index.html') || p.endsWith('/e-commerce/') || p.endsWith('/'); }, []); const base = isHome ? '' : '../e-commerce/index.html'; const link = (hash) => base + hash; React.useEffect(() => { const close = () => setOpen(false); const onResize = () => { if (window.innerWidth > 880) setOpen(false); }; window.addEventListener('hashchange', close); window.addEventListener('resize', onResize); return () => { window.removeEventListener('hashchange', close); window.removeEventListener('resize', onResize); }; }, []); React.useEffect(() => { document.body.style.overflow = open ? 'hidden' : ''; return () => { document.body.style.overflow = ''; }; }, [open]); React.useEffect(() => { if (window.lucide) lucide.createIcons(); }, [open, overDark]); // ── Color-invert behaviour: detect which section sits behind the nav ──────── React.useEffect(() => { if (typeof window === 'undefined') return; // selectors that produce dark surfaces in our Deezer theme const darkSel = [ '.is-dark', '#dlakogo', '#problemy', '#opinie', '#proces', '#faq', '.g-footer', '.cs-cta-card', '.sb-section', '.g-contact-form' ].join(','); let nodes = Array.from(document.querySelectorAll(darkSel)); // Re-scan once the page has fully hydrated (React mounts components asynchronously) const rescan = () => { nodes = Array.from(document.querySelectorAll(darkSel)); check(); }; const check = () => { const navEl = navRef.current; if (!navEl) return; const navRect = navEl.getBoundingClientRect(); const probeY = navRect.top + navRect.height / 2; let hit = false; for (const el of nodes) { const r = el.getBoundingClientRect(); if (r.top <= probeY && r.bottom > probeY) { hit = true; break; } } setOverDark(hit); }; // initial + delayed (give other components time to mount) check(); const t1 = setTimeout(rescan, 50); const t2 = setTimeout(rescan, 400); let raf = 0; const onScroll = () => { if (raf) return; raf = requestAnimationFrame(() => { raf = 0; check(); }); }; window.addEventListener('scroll', onScroll, { passive: true }); window.addEventListener('resize', onScroll); return () => { clearTimeout(t1); clearTimeout(t2); if (raf) cancelAnimationFrame(raf); window.removeEventListener('scroll', onScroll); window.removeEventListener('resize', onScroll); }; }, []); const items = [ { href: link('#problemy'), label: 'Dla kogo' }, { href: link('#pomagam'), label: 'Jak pomagam' }, { href: link('#portfolio'), label: 'Portfolio' }, { href: link('#proces'), label: 'Współpraca' }, { href: link('#omnie'), label: 'O mnie' }, { href: link('#faq'), label: 'FAQ' }, ]; return (
setOpen(false)}>
{items.map((it) => ( setOpen(false)}>{it.label} ))}
setOpen(false)}> Umów darmowy audyt
); } window.NavDeezer = NavDeezer;