// Shared helpers for the website UI kit.

// Reveal-on-scroll wrapper — fades/rises children when they enter the viewport.
function JHReveal({ children, delay = 0, y = 24, as = "div", style, ...rest }) {
  const ref = React.useRef(null);
  const [shown, setShown] = React.useState(false);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const root = el.closest("[data-scroll]") || null;
    const io = new IntersectionObserver(
      (entries) => entries.forEach((e) => { if (e.isIntersecting) { setShown(true); io.disconnect(); } }),
      { root, threshold: 0.12 }
    );
    io.observe(el);
    return () => io.disconnect();
  }, []);
  const Tag = as;
  return (
    <Tag ref={ref} style={{
      opacity: shown ? 1 : 0,
      transform: shown ? "translateY(0)" : `translateY(${y}px)`,
      transition: `opacity var(--dur-reveal) var(--ease-gallery) ${delay}ms, transform var(--dur-reveal) var(--ease-gallery) ${delay}ms`,
      ...style,
    }} {...rest}>{children}</Tag>
  );
}
window.JHReveal = JHReveal;

// Re-render Lucide icons after React commits.
window.JHIcons = () => { try { if (window.lucide) window.lucide.createIcons(); } catch (e) {} };
