/* interview-prep.jsx — AI-generated interview questions from resume */ function InterviewPrepDrawer({ data, onClose }) { const { useState: S, useEffect: E } = React; const [stage, setStage] = S("idle"); // idle | loading | done | error const [groups, setGroups] = S([]); const [openQ, setOpenQ] = S({}); const [errMsg, setErrMsg] = S(""); const [limitHit, setLimitHit] = S(false); E(() => { const onKey = (e) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, []); const generate = async () => { if (!window.groqStream) { setErrMsg("AI not available."); setStage("error"); return; } setStage("loading"); setGroups([]); setErrMsg(""); const ctx = window.buildResumeCtx ? window.buildResumeCtx(data) : JSON.stringify(data).slice(0, 4000); let raw = ""; await window.groqStream({ messages: [ { role: "system", content: window.GROQ_SYSTEM || "" }, { role: "user", content: `Based on this resume, generate 12 realistic interview questions a hiring manager would ask. Return ONLY a JSON array of objects with this structure: [ { "category": "Behavioral", "q": "Tell me about a time you led a team under pressure.", "hint": "Use STAR method — Situation, Task, Action, Result." }, ... ] Use 3 categories: "Behavioral" (4 questions), "Technical / Role-specific" (4 questions), "Career & Motivation" (4 questions). Base questions directly on the candidate's specific experience, skills, and companies — not generic ones. Resume: ${ctx}` }, ], maxTokens: 1800, onChunk: (_, full) => { raw = full; }, onDone: () => { try { let s = raw.trim().replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/\s*```$/i,""); const arr = JSON.parse(s.match(/\[[\s\S]*\]/)?.[0] || s); // Group by category const map = {}; arr.forEach(item => { const cat = item.category || "General"; if (!map[cat]) map[cat] = []; map[cat].push(item); }); setGroups(Object.entries(map).map(([cat, qs]) => ({ cat, qs }))); setStage("done"); } catch(_) { setErrMsg("Could not parse AI response. Try again."); setStage("error"); } }, onError: (e) => { if (e === "free_limit_reached") { setLimitHit(true); } else { setErrMsg(typeof e === "string" ? e : "AI error."); } setStage("error"); }, }); }; const toggleQ = (key) => setOpenQ(o => ({ ...o, [key]: !o[key] })); const CATEGORY_COLORS = { "Behavioral": { bg: "rgba(28,155,230,.08)", color: "var(--brand-blue)" }, "Technical / Role-specific":{ bg: "rgba(109,90,224,.08)", color: "#6D5AE0" }, "Career & Motivation": { bg: "rgba(22,163,107,.08)", color: "var(--good)" }, }; return ( <>
AI questions tailored to your resume
AI analyzes your resume and generates 12 realistic questions across behavioral, technical, and motivation categories.
Analyzing your resume…
{errMsg}