"use client"; import { useState } from "react"; import Link from "next/link"; import { ArrowLeft, ArrowRight, Lock } from "lucide-react"; import { accountRequest } from "@/lib/account-client"; import { AI_YEARS, CODING, DAILY_HOURS, DEPTHS, ROLES, TOOLS, USES, parseSurvey, type AiSurvey, } from "@/lib/ai-survey"; import type { Option } from "@/lib/onboarding"; import { OptionButton } from "./option-button"; type ManyKey = "uses" | "tools"; type OneKey = "role" | "dailyHours" | "aiYears" | "depth" | "coding"; const STEPS: { key: ManyKey | OneKey; title: string; note: string; options: Option[]; multi: boolean }[] = [ { key: "role", title: "What best describes you?", note: "Pick the closest fit.", options: ROLES, multi: false }, { key: "uses", title: "What do you use AI for?", note: "Pick everything that applies.", options: USES, multi: true }, { key: "tools", title: "Which AI tools do you use?", note: "Pick everything you've used in the last month.", options: TOOLS, multi: true }, { key: "dailyHours", title: "How much do you use AI on a typical day?", note: "A rough guess is fine.", options: DAILY_HOURS, multi: false }, { key: "aiYears", title: "How long have you been using AI tools?", note: "Since your first real use.", options: AI_YEARS, multi: false }, { key: "depth", title: "What's the most advanced thing you've done with AI?", note: "Pick the deepest one.", options: DEPTHS, multi: false }, { key: "coding", title: "How much coding experience do you have?", note: "Last one.", options: CODING, multi: false }, ]; // The optional questions about how someone uses AI, saved to their account. Every step can be skipped. export function AiSurveySteps({ initial, onDone }: { initial: AiSurvey | null; onDone: () => void }) { const [answers, setAnswers] = useState(initial ?? { uses: [], tools: [] }); const [step, setStep] = useState(0); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const current = STEPS[step]; const last = step === STEPS.length - 1; const finish = async (final: AiSurvey) => { const survey = parseSurvey(final); // Nothing answered and nothing saved before: no row to write if (!survey && !initial) return onDone(); setSaving(true); const { error: saveError } = await accountRequest("survey", { survey }); setSaving(false); if (saveError) return setError(`Couldn't save your answers: ${saveError}`); onDone(); }; const advance = (updated: AiSurvey) => { if (last) void finish(updated); else setStep(step + 1); }; const pick = (key: OneKey, id: string) => { const updated = { ...answers, [key]: id }; setAnswers(updated); setTimeout(() => advance(updated), 220); }; const toggle = (key: ManyKey, id: string) => { const list = answers[key]; setAnswers({ ...answers, [key]: list.includes(id) ? list.filter((x) => x !== id) : [...list, id] }); }; const hasAnswer = current.multi ? answers[current.key as ManyKey].length > 0 : !!answers[current.key as OneKey]; const long = current.options.length > 10; return (

About your AI use · optional

{step + 1} / {STEPS.length}
{step === 0 && (

Seven quick questions so we know who we're making tutorials for. Your answers stay between you and AI Resource Pro. We never sell or share them.{" "} Privacy policy

)}

{current.title}

{current.note}

{current.options.map((o) => current.multi ? ( toggle(current.key as ManyKey, o.id)} /> ) : ( pick(current.key as OneKey, o.id)} /> ) )}
{current.key === "uses" && answers.uses.includes("other") && ( )}
{error &&

{error}

}
{step > 0 && ( )}
); }