import { useEffect, useLayoutEffect, useState } from 'react'; import { ArrowLeft, ArrowRight, CheckCircle2, LayoutDashboard, Sparkles } from 'lucide-react'; import Modal from './ui/Modal'; const TOUR = [ { target: '[data-tutorial="nav-clips"]', title: 'Clip Generator', body: 'This is the tool people come for. A long video in, vertical shorts out. The other menu items stay locked until you finish one run.', }, { target: '[data-tutorial="source-tabs"]', title: 'Upload or paste a link', body: 'Drop an MP4, or switch to Video URL and paste YouTube, TikTok, Instagram…', }, { target: '[data-tutorial="drop-zone"]', title: 'Your video', body: 'Click the box or paste the link here. Keep files under 500MB.', }, { target: '[data-tutorial="output-format"]', title: 'Output format', body: '9:16 is TikTok, Reels and Shorts. Leave it unless you need a square feed post or landscape.', }, { target: '[data-tutorial="generate"]', title: 'Generate', body: 'Tick that you have the rights, then generate. That is the whole first run.', }, ]; function visibleTarget(selector) { return [...document.querySelectorAll(selector)].find((el) => { const r = el.getBoundingClientRect(); return r.width > 2 && r.height > 2; }) || null; } function placeTip(rect, tipW, tipH, vw, vh) { const m = 12; const gap = 12; const mobile = vw < 640; if (mobile) { return { top: Math.max(m, vh - tipH - m - 8), left: m, width: vw - m * 2, }; } let top = rect.bottom + gap; if (top + tipH > vh - m) top = rect.top - gap - tipH; if (top < m) top = m; let left = rect.left + rect.width / 2 - tipW / 2; left = Math.max(m, Math.min(left, vw - m - tipW)); return { top, left, width: tipW }; } /** * First-login Clip Generator tutorial. * - intro: blocking modal * - coach: Next/Back spotlight on each Clip Generator control * - celebrate: modal after the first successful job * * QA: #app?tutorial=1 */ export default function ClipTutorial({ phase, jobStatus, onStart, onSkip, onDismissCelebrate }) { const [step, setStep] = useState(0); const [spot, setSpot] = useState(null); useEffect(() => { if (phase === 'coach') setStep(0); }, [phase]); useLayoutEffect(() => { if (phase !== 'coach' || jobStatus === 'processing' || jobStatus === 'error') { setSpot(null); return; } const measure = () => { const spec = TOUR[step]; if (!spec) { setSpot(null); return; } const el = visibleTarget(spec.target); if (el) el.scrollIntoView({ block: 'nearest', inline: 'nearest' }); const rect = el ? el.getBoundingClientRect() : null; const vw = window.innerWidth; const vh = window.innerHeight; const r = (n) => Math.round(n); const mobile = vw < 640; const tipW = Math.min(360, vw - 24); const tipH = 220; const hole = rect ? { top: r(rect.top - 6), left: r(rect.left - 6), width: r(rect.width + 12), height: r(rect.height + 12) } : null; const rawTip = hole ? placeTip({ top: hole.top, bottom: hole.top + hole.height, left: hole.left, width: hole.width }, tipW, tipH, vw, vh) : { top: mobile ? vh - 240 : vh / 2 - 80, left: 12, width: vw - 24 }; const tip = { top: r(rawTip.top), left: r(rawTip.left), width: r(rawTip.width) }; setSpot((prev) => { const next = { hole, tip, mobile }; try { if (prev && JSON.stringify(prev) === JSON.stringify(next)) return prev; } catch (_) { /* ignore */ } return next; }); }; measure(); window.addEventListener('resize', measure); window.addEventListener('scroll', measure, true); return () => { window.removeEventListener('resize', measure); window.removeEventListener('scroll', measure, true); }; }, [phase, step, jobStatus]); if (phase === 'intro') { return (

People come here for Clip Generator: a long video in, vertical shorts out. We will walk the screen, then you run one video.

); } if (phase === 'coach' && (jobStatus === 'processing' || jobStatus === 'error')) { return (

First clips

{jobStatus === 'error' ? 'That run failed. Try another video — other tools stay locked until one job finishes.' : 'Hang on — Clip Generator is finding the moments and cutting vertical shorts.'}

); } if (phase === 'coach') { const last = step >= TOUR.length - 1; const spec = TOUR[step] || TOUR[0]; const onLast = () => setStep(TOUR.length); if (step >= TOUR.length) { return (

Your turn — add a video and generate.

); } const hole = spot?.hole; const tip = spot?.tip; return (
{!hole &&
} {hole && (
)}

{String(step + 1).padStart(2, '0')} / {String(TOUR.length).padStart(2, '0')}

{spec.title}

{spec.body}

{step > 0 && ( )}
); } if (phase === 'celebrate') { return (

That is the whole product, on one video.

The other tools are unlocked. Come back to Clip Generator whenever you have another long video.

); } return null; }