"use client"; import { useRef, useState, useEffect, useCallback } from "react"; /* ────────────────────────────────────────────────────────────────────────── * CanvasHint — the small centred onboarding popup shared by the interactive * product demos (workflow editor, kanban, approval inbox, email builder). It * shows a looping "drag" micro-animation, a title and a one-line subtitle, and * a close button. Designed to sit inside a `position: relative` dotted-grid * canvas container. * * useCanvasHint() drives it: the hint appears once its container scrolls into * view and is dismissed on the first real interaction (or via the X). * ────────────────────────────────────────────────────────────────────────── */ const HINT_CSS = ` @keyframes hint-popup-in{from{opacity:0;transform:scale(0.95)}to{opacity:1;transform:scale(1)}} @keyframes hint-mini-drag{0%,100%{transform:translate(0,0)}20%{transform:translate(0,-4px)}40%{transform:translate(34px,-4px)}60%{transform:translate(34px,0)}80%{transform:translate(0,0)}} @keyframes hint-mini-cursor{0%,15%{transform:translate(38px,24px)}20%{transform:translate(22px,16px)}40%,60%{transform:translate(58px,16px)}65%{transform:translate(60px,24px)}80%,100%{transform:translate(38px,24px)}} .hint-mini-drag{animation:hint-mini-drag 3s ease-in-out infinite} .hint-mini-cursor{animation:hint-mini-cursor 3s ease-in-out infinite} @media (prefers-reduced-motion:reduce){.hint-mini-drag,.hint-mini-cursor{animation:none}} `; export function useCanvasHint() { const ref = useRef(null); const [show, setShow] = useState(false); const dismissed = useRef(false); useEffect(() => { const el = ref.current; if (!el || dismissed.current) return; const obs = new IntersectionObserver( (entries) => entries.forEach((e) => { if (e.isIntersecting && !dismissed.current) setShow(true); }), { threshold: 0.4 } ); obs.observe(el); return () => obs.disconnect(); }, []); const dismiss = useCallback(() => { dismissed.current = true; setShow(false); }, []); return { ref, show, dismiss }; } export default function CanvasHint({ show, onDismiss, title, subtitle, }: { show: boolean; onDismiss: () => void; title: string; subtitle: string; }) { if (!show) return null; // z-[45] sits above canvas content (EmailBuilder reset btn z-40) but below the // navbar (header z-50 / its dropdown), so the hint never floats over the // expanded nav. return (