/* global React, Icon */ const { useState, useRef, useEffect } = React; function AIChat() { const [open, setOpen] = useState(false); const [messages, setMessages] = useState([ { role: "assistant", content: "¡Hola! Soy el agente AI de Contarte. Puedo ayudarte con dudas de contabilidad, CFDI, SAT o sobre nuestros planes. ¿En qué te ayudo?" } ]); const [input, setInput] = useState(""); const [busy, setBusy] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight; }, [messages, busy]); const send = async (text) => { const q = (text ?? input).trim(); if (!q || busy) return; const next = [...messages, { role: "user", content: q }]; setMessages(next); setInput(""); setBusy(true); try { const res = await fetch("/api/chat", { method: "POST", headers: { "Content-Type": "application/json" }, credentials: "same-origin", body: JSON.stringify({ message: q }) }); if (!res.ok) throw new Error("HTTP " + res.status); const data = await res.json(); const reply = (data && data.reply ? String(data.reply) : "").trim(); if (!reply) throw new Error("empty reply"); setMessages([...next, { role: "assistant", content: reply }]); } catch (e) { setMessages([...next, { role: "assistant", content: "Ups, tuve un problema al responder. Intenta de nuevo en un momento." }]); } finally { setBusy(false); } }; const suggestions = [ "¿Qué plan me conviene?", "¿Qué es CFDI 4.0?", "¿Cómo conecto el SAT?" ]; return ( <> {/* CTA section — lives between Trust and Pricing */}
Agente AI · nuevo

Chatea con nuestro agente AI sobre contarte.mx o tu contabilidad.

Resuelve dudas de CFDI, SAT, cobros o planes en segundos. 100% gratis, sin registro — responde en español, al instante.

{suggestions.map(s => ( ))}
{/* Floating launcher (always visible) */} {!open && ( )} {/* Chat window */} {open && (
Agente AI · Contarte En línea · responde al instante
{messages.map((m, i) => (
{m.role === "assistant" &&
}
{m.content}
))} {busy && (
)}
{ e.preventDefault(); send(); }}> setInput(e.target.value)} placeholder="Escribe tu pregunta…" disabled={busy} autoFocus />
)} ); } function AIPreview() { return (
Agente AI · Contarte En línea
¿Qué plan me conviene si facturo 200 CFDI al mes?
Con 200 CFDI/mes te recomiendo Profesional ($3,600/año). Incluye 500 CFDI, cobros en línea y colaboración con tu contador.
¿Y si mi contador trabaja desde otra ciudad?
Sin problema — ambos entran al mismo expediente en vivo. Tu contador ve lo mismo que tú.
); } window.AIChat = AIChat;