// SOFIA AI Assistant — slide-over chat panel. LIGHT theme. const { useState: usA, useEffect: ueA, useRef: urA } = React; function AssistantPanel({ open, onClose, onNavigate, onOpenCandidate }) { const [messages, setMessages] = usA([ { role: 'assistant', text: '¡Hola Marisol! Soy SOFIA, tu copiloto de Recruitment. Puedo buscar candidatos, agendar screenings con SOFIA Call, redactar mensajes para SOFIA Chat o resumir vacantes. Prueba con uno de los ejemplos.', time: 'ahora', }, ]); const [running, setRunning] = usA(false); const [input, setInput] = usA(''); const endRef = urA(null); ueA(() => { if (endRef.current) endRef.current.scrollIntoView({ behavior: 'smooth', block: 'end' }); }, [messages, running]); const runScript = (key) => { if (running) return; const script = DATA.ASSISTANT_SCRIPTS[key]; if (!script) return; setMessages((m) => [...m, { role: 'user', text: script.user, time: 'ahora' }]); setRunning(true); let idx = 0; const toolMsgId = 'tool-' + Date.now(); setMessages((m) => [...m, { id: toolMsgId, role: 'tool', steps: [], time: 'ahora' }]); const stepNext = () => { if (idx >= script.steps.length) { setTimeout(() => { setMessages((m) => [ ...m, { role: 'assistant', text: script.summary, candidates: script.candidates, time: 'ahora' }, ]); setRunning(false); }, 400); return; } setMessages((m) => m.map((msg) => msg.id === toolMsgId ? { ...msg, steps: [...msg.steps, { ...script.steps[idx], status: 'running' }] } : msg ) ); setTimeout(() => { setMessages((m) => m.map((msg) => msg.id === toolMsgId ? { ...msg, steps: msg.steps.map((s, i) => (i === idx ? { ...s, status: 'done' } : s)) } : msg ) ); idx++; stepNext(); }, 750); }; stepNext(); }; const submit = () => { if (!input.trim()) return; setMessages((m) => [...m, { role: 'user', text: input, time: 'ahora' }]); const lower = input.toLowerCase(); setInput(''); setRunning(true); setTimeout(() => { if (lower.includes('acme') || lower.includes('cobranza')) { runScript('bilingual'); return; } if (lower.includes('helix') || lower.includes('b2b')) { runScript('summary'); return; } if (lower.includes('whatsapp') || lower.includes('redacta') || lower.includes('mensaje')) { runScript('draft'); return; } setMessages((m) => [...m, { role: 'assistant', text: 'Buen punto. Para esta demo, los flujos completos están disponibles en los 3 ejemplos pre-cargados — pruébalos para ver a SOFIA orquestar SOFIA Chat y SOFIA Call como herramientas MCP.', time: 'ahora' }]); setRunning(false); }, 500); }; if (!open) return null; const examples = [ { key: 'bilingual', icon: , text: 'Encuéntrame 5 bilingües en San Salvador disponibles' }, { key: 'summary', icon: , text: 'Resume los 3 mejores candidatos para Helix Energy' }, { key: 'draft', icon: , text: 'Redacta WhatsApp invitando a Ana García el viernes' }, ]; return (