/* SRQ Analytics — icons + shared bits */

const Mark = ({ size = 26 }) => (
  <svg className="mark" width={size} height={size} viewBox="0 0 32 32" fill="none" aria-hidden="true">
    <rect x="1" y="1" width="30" height="30" rx="6" stroke="currentColor" strokeWidth="1.6" opacity="0.32" />
    <path d="M8 21 L13 14 L18 17 L24 9" stroke="var(--teal)" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" />
    <circle cx="24" cy="9" r="2.4" fill="var(--brass)" />
  </svg>
);

const Arrow = () => (
  <svg className="arrow" width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
    <path d="M3 8h9M8.5 4l4 4-4 4" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" />
  </svg>
);

const Ico = {
  cfo: (
    <svg viewBox="0 0 32 32" fill="none" width="40" height="40" aria-hidden="true">
      <path d="M5 27V9l11-5 11 5v18" stroke="currentColor" strokeWidth="1.6" strokeLinejoin="round" />
      <path d="M5 27h22M11 22v-6M16 22v-9M21 22v-4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
    </svg>
  ),
  chart: (
    <svg viewBox="0 0 32 32" fill="none" width="40" height="40" aria-hidden="true">
      <rect x="4" y="4" width="24" height="24" rx="3" stroke="currentColor" strokeWidth="1.6" />
      <path d="M9 21l5-6 4 3 5-7" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" />
      <circle cx="23" cy="11" r="1.6" fill="currentColor" />
    </svg>
  ),
  gears: (
    <svg viewBox="0 0 32 32" fill="none" width="40" height="40" aria-hidden="true">
      <path d="M13 4.5h-2l-.6 2.5-2 .8-2.2-1.3-1.4 1.4 1.3 2.2-.8 2L2.5 13v2l2.5.6.8 2-1.3 2.2 1.4 1.4 2.2-1.3 2 .8.6 2.5h2l.6-2.5 2-.8" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" />
      <circle cx="12" cy="14" r="3.2" stroke="currentColor" strokeWidth="1.5" />
      <circle cx="23" cy="23" r="4.4" stroke="currentColor" strokeWidth="1.5" />
      <path d="M23 17.5v-2M23 30.5v-2M29.5 23h-2M18.5 23h-2" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
    </svg>
  ),
  ai: (
    <svg viewBox="0 0 32 32" fill="none" width="40" height="40" aria-hidden="true">
      <rect x="8" y="10" width="16" height="13" rx="3" stroke="currentColor" strokeWidth="1.6" />
      <path d="M16 10V6M13 6h6" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
      <circle cx="13" cy="16" r="1.4" fill="currentColor" />
      <circle cx="19" cy="16" r="1.4" fill="currentColor" />
      <path d="M13 20h6M4 14v5M28 14v5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
    </svg>
  ),
  mail: (
    <svg viewBox="0 0 20 20" width="17" height="17" fill="none" aria-hidden="true"><rect x="2.5" y="4" width="15" height="12" rx="2" stroke="currentColor" strokeWidth="1.4" /><path d="M3 5.5l7 5 7-5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" /></svg>
  ),
  pin: (
    <svg viewBox="0 0 20 20" width="17" height="17" fill="none" aria-hidden="true"><path d="M10 18s6-5.2 6-10A6 6 0 0 0 4 8c0 4.8 6 10 6 10z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round" /><circle cx="10" cy="8" r="2.2" stroke="currentColor" strokeWidth="1.4" /></svg>
  ),
  link: (
    <svg viewBox="0 0 20 20" width="17" height="17" fill="none" aria-hidden="true"><rect x="3" y="3" width="14" height="14" rx="2.5" stroke="currentColor" strokeWidth="1.4" /><path d="M6.5 8.5v5M6.5 6.2v.1M10 13.5v-5M13.5 13.5v-2.8c0-1.2-.7-1.9-1.7-1.9s-1.8.8-1.8 2" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" /></svg>
  ),
};

function useReveal() {
  React.useEffect(() => {
    const els = [...document.querySelectorAll(".reveal")];
    const hide = (el) => {
      el.style.opacity = "0";
      el.style.transform = "translateY(18px)";
      el.style.transition = "opacity .7s ease, transform .7s ease";
    };
    const show = (el) => { el.style.opacity = "1"; el.style.transform = "none"; };

    const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    if (reduce || !("IntersectionObserver" in window)) return; // leave fully visible

    const vh = window.innerHeight;
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => { if (e.isIntersecting) { show(e.target); io.unobserve(e.target); } });
    }, { threshold: 0.1, rootMargin: "0px 0px -5% 0px" });

    els.forEach((el) => {
      const r = el.getBoundingClientRect();
      if (r.top >= vh) { hide(el); io.observe(el); } // pre-hide only what's below the fold
    });

    // Safety net: never leave anything hidden if the observer misfires.
    const t = setTimeout(() => els.forEach(show), 4000);
    return () => { io.disconnect(); clearTimeout(t); };
  }, []);
}

Object.assign(window, { Mark, Arrow, Ico, useReveal });
