// Klyvio — Questionnaire interactif (dark theme Klyvio) function Questionnaire({ answers, setAnswers, onFinish, onExit, company }) { const questions = window.KLYVIO_QUESTIONS; const dims = window.KLYVIO_DIMENSIONS; const [idx, setIdx] = useState(0); const [paused, setPaused] = useState(false); const [savedAt, setSavedAt] = useState(null); const [elapsed, setElapsed] = useState(0); const startRef = useRef(Date.now()); const q = questions[idx]; const dim = dims.find(d => d.id === q.dim); const currentAnswer = answers[q.id]; useEffect(() => { if (paused) return; const interval = setInterval(() => setElapsed(Math.floor((Date.now() - startRef.current) / 1000)), 1000); return () => clearInterval(interval); }, [paused]); useEffect(() => { setSavedAt(Date.now()); const t = setTimeout(() => setSavedAt(null), 2000); return () => clearTimeout(t); }, [answers]); const answer = (val) => setAnswers({ ...answers, [q.id]: val }); const pct = Math.round(((idx + 1) / questions.length) * 100); const remaining = Math.max(0, Math.round((questions.length - idx - 1) * 0.5)); const canNext = q.optional || (currentAnswer !== undefined && currentAnswer !== null && currentAnswer !== "" && !(Array.isArray(currentAnswer) && currentAnswer.length === 0)); const next = () => { if (idx < questions.length - 1) setIdx(idx + 1); else onFinish(); }; const prev = () => { if (idx > 0) setIdx(idx - 1); }; useEffect(() => { const handler = (e) => { if (paused) return; if (e.key === "ArrowRight" && canNext) next(); else if (e.key === "ArrowLeft") prev(); else if (e.key >= "1" && e.key <= "9" && (q.type === "scale" || q.type === "single")) { const n = parseInt(e.key, 10) - 1; const opts = q.type === "scale" ? q.scale : q.options; if (opts && n < opts.length) answer(n); } }; window.addEventListener("keydown", handler); return () => window.removeEventListener("keydown", handler); }, [idx, currentAnswer, paused]); return (