// Site-wide sticky CTA. Accepts {label, href} — same visuals, per-page action.
function StickyCTA({ label = 'Book a 30-min pilot call', href = 'https://calendly.com/peyton-cohesionauth/30min' }) {
  const [visible, setVisible] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setVisible(window.scrollY > 800);
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const onClick = (e) => {
    // In-page anchors scroll smoothly; external URLs follow their href
    if (href.startsWith('#') || (href.includes('#') && !href.startsWith('http'))) {
      e.preventDefault();
      const id = href.split('#')[1];
      const el = document.getElementById(id);
      if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
    }
  };

  return (
    <a
      href={href}
      onClick={onClick}
      className={`sticky-cta btn btn-primary btn-shimmer ${visible ? 'visible' : ''}`}
      aria-label={label}
    >
      {label}
    </a>
  );
}
window.StickyCTA = StickyCTA;
