"use client"; import { useState } from "react"; /* ───────────────────────────────────────────────────────── * APPROVAL CARD (human-in-the-loop) * One question at a time; elongated pills show progress; * the circular arrow up top advances (↑ sends on the last). * Choices, paging, and submission are directly controlled. * ───────────────────────────────────────────────────────── */ const QUESTIONS = [ { q: "How many flavors should we launch?", type: "radio" as const, options: ["Three (core line)", "Five (full case)", "Just one hero"], }, { q: "Which mix-ins should we stock?", type: "check" as const, options: ["Chocolate chips", "Waffle bits", "Sprinkles"], }, { q: "Which market do we enter first?", type: "radio" as const, options: ["Food trucks", "Grocery freezers", "Scoop shops"], }, ]; export default function ApprovalCard() { const [qi, setQi] = useState(0); const [answers, setAnswers] = useState>({}); const [custom, setCustom] = useState>({}); const [sent, setSent] = useState(false); const [open, setOpen] = useState(true); const question = QUESTIONS[qi]; const last = qi === QUESTIONS.length - 1; const selected = answers[qi] ?? []; const hasAnswer = selected.length > 0 || Boolean(custom[qi]?.trim()); const toggle = (index: number) => { setAnswers((current) => { const picked = current[qi] ?? []; const next = question.type === "radio" ? [index] : picked.includes(index) ? picked.filter((item) => item !== index) : [...picked, index]; return { ...current, [qi]: next }; }); if (question.type === "radio") { setCustom((current) => ({ ...current, [qi]: "" })); // single-choice auto-advances window.setTimeout(() => { if (qi === QUESTIONS.length - 1) setSent(true); else setQi((current) => Math.min(QUESTIONS.length - 1, current + 1)); }, 480); } }; const reset = () => { setQi(0); setAnswers({}); setCustom({}); setSent(false); setOpen(true); }; if (!open) { return ( ); } return (
{sent ? (
Answers sent
) : (
{question.q}
{question.options.map((option, i) => { const on = selected.includes(i); return ( ); })}
)} {/* footer — ring-dot pager + send arrow */}
{QUESTIONS.map((_, i) => ( {!sent && ( )}
); }