// Simulated AI + template questions.

const TEMPLATE_QUESTIONS = [
  { q: "What have you built?",   tag: "projects" },
  { q: "Who are you?",           tag: "about" },
  { q: "What's your stack?",     tag: "stack" },
  { q: "How do I reach you?",    tag: "contact" },
];

const CANNED = {
  projects: "Retrieval pipelines for a legal-tech startup, a realtime agent framework used by ~2k devs, and an eval harness that caught a 9% regression in production. Ask me about any.",
  about:    "An AI engineer. I build things that listen, think, and respond — systems that feel alive. I care about latency, evals, and the texture of how models feel to talk to.",
  stack:    "Python, TypeScript, PyTorch. Modal and vLLM for serving, DSPy and custom harnesses for evals, Postgres + pgvector when I don't need more.",
  contact:  "Email, or this chat. Links up top. I usually respond within a day.",
  default:  "Try a project question, or ask about my stack or how to reach me.",
};

function pickCanned(text) {
  const t = text.toLowerCase();
  if (/(project|built|ship|work|case)/.test(t)) return CANNED.projects;
  if (/(who|about|bio|you)/.test(t)) return CANNED.about;
  if (/(stack|tech|tool|python|model)/.test(t)) return CANNED.stack;
  if (/(contact|reach|email|hire|dm)/.test(t)) return CANNED.contact;
  return CANNED.default;
}

async function askAI(text) {
  try {
    if (window.claude && window.claude.complete) {
      const resp = await window.claude.complete({
        messages: [
          { role: 'user', content:
            `You are the AI voice of an engineer's portfolio site — a composition of sensory organs in a Bauhaus-style poster. Speak as the page itself. Keep answers under 50 words, warm but precise, no bullets, no markdown. User: "${text}"` },
        ],
      });
      return (resp || '').trim() || pickCanned(text);
    }
  } catch (e) {}
  return pickCanned(text);
}

window.AI = { askAI, TEMPLATE_QUESTIONS };
