// Block catalog for the AI agent workflow editor
const BLOCK_CATALOG = [
  {
    category: "Type Agents",
    accent: "var(--accent-types)",
    blocks: [
      { id: "type_coding", label: "Coding-Logic", kind: "action", params: [] },
      { id: "type_js", label: "Javascript", kind: "action", params: [] },
      { id: "type_python", label: "Python", kind: "action", params: [] },
      { id: "type_math", label: "Math", kind: "action", params: [] },
      { id: "type_science", label: "Science", kind: "action", params: [] },
      { id: "type_it", label: "Letteratura Italiana", kind: "action", params: [] },
      { id: "type_eng", label: "English", kind: "action", params: [] },
      { id: "type_fr", label: "France", kind: "action", params: [] },
      { id: "type_hist", label: "History", kind: "action", params: [] },
    ],
  },
    {
    category: "Socratic Method",
    accent: "var(--accent-events)",
    blocks: [
      { id: "Socratic_Bias", label: "Socratic Bias", kind: "action", params: [{ key: "level", val: "3", type: "slider", min: 1, max: 5 }] },
      { id: "Socratic_Synthesis", label: "Socratic Synthesis", kind: "action", params: [{ key: "depth", val: "2", type: "slider", min: 1, max: 5 }] },
      { id: "Socratic_Suggestion", label: "Socratic Suggestion", kind: "action", params: [{ key: "hint_level", val: "4", type: "slider", min: 1, max: 5 }] },
      { id: "Socratic_Solution", label: "Socratic Solution", kind: "end", params: [{ key: "status", val: "ok" }] },
    ],
  },
  {
    category: "Type Conversation",
    accent: "var(--accent-events)",
    blocks: [
      { id: "Formale  ", label: "Formale", kind: "start", params: [{ key: "source", val: "webhook" }] },
      { id: "Informale", label: "Informal", kind: "start", params: [{ key: "cron", val: "0 9 * * *" }] },
      { id: "Amichevole", label: "Friendly", kind: "start", params: [{ key: "channel", val: "#general" }] },
      { id: "Kids", label: "Kids", kind: "end", params: [{ key: "status", val: "ok" }] },
      { id: "Teenager", label: "Teenager", kind: "end", params: [{ key: "status", val: "ok" }] },
      { id: "Adult", label: "Adult", kind: "end", params: [{ key: "status", val: "ok" }] },
    ],
  }, 
  {
    category: "Languages",
    accent: "var(--accent-events)",
    blocks: [
      { id: "Italiano", label: "Italiano", kind: "start", params: [{ key: "source", val: "webhook" }] },
      { id: "English", label: "English", kind: "start", params: [{ key: "cron", val: "0 9 * * *" }] },
      { id: "French", label: "French", kind: "start", params: [{ key: "channel", val: "#general" }] },
      { id: "Spanish", label: "Spanish", kind: "end", params: [{ key: "status", val: "ok" }] },
    ],
  },
  {
    category: "Events",
    accent: "var(--accent-events)",
    blocks: [
      { id: "on_trigger", label: "When triggered", kind: "start", params: [{ key: "source", val: "webhook" }] },
      { id: "on_schedule", label: "On schedule", kind: "start", params: [{ key: "cron", val: "0 9 * * *" }] },
      { id: "on_message", label: "On new message", kind: "start", params: [{ key: "channel", val: "#general" }] },
      { id: "end", label: "End flow", kind: "end", params: [{ key: "status", val: "ok" }] },
    ],
  },
  {
    category: "Models",
    accent: "var(--accent-models)",
    blocks: [
      { id: "llm_call", label: "Call LLM", kind: "action", params: [{ key: "model", val: "claude-opus-4" }, { key: "temp", val: "0.7" }] },
      { id: "embed", label: "Embed text", kind: "action", params: [{ key: "model", val: "text-embed-3" }] },
      { id: "classify", label: "Classify", kind: "action", params: [{ key: "labels", val: "urgent, normal" }] },
    ],
  },
  {
    category: "Tools",
    accent: "var(--accent-tools)",
    blocks: [
      { id: "search_web", label: "Search web", kind: "action", params: [{ key: "query", val: "{{input}}" }] },
      { id: "read_file", label: "Read file", kind: "action", params: [{ key: "path", val: "notes.md" }] },
      { id: "http_request", label: "HTTP request", kind: "action", params: [{ key: "method", val: "GET" }, { key: "url", val: "/api/data" }] },
      { id: "run_code", label: "Run code", kind: "action", params: [{ key: "lang", val: "python" }] },
    ],
  },
  {
    category: "Logic",
    accent: "var(--accent-logic)",
    blocks: [
      { id: "if", label: "If condition", kind: "branch", params: [{ key: "check", val: "score > 0.8" }] },
      { id: "loop", label: "For each", kind: "branch", params: [{ key: "items", val: "results" }] },
      { id: "wait", label: "Wait", kind: "action", params: [{ key: "seconds", val: "5" }] },
    ],
  },
  {
    category: "Memory",
    accent: "var(--accent-memory)",
    blocks: [
      { id: "set_var", label: "Set variable", kind: "action", params: [{ key: "name", val: "result" }, { key: "value", val: "{{output}}" }] },
      { id: "recall", label: "Recall context", kind: "action", params: [{ key: "key", val: "user_history" }] },
    ],
  },
  {
    category: "Output",
    accent: "var(--accent-output)",
    blocks: [
      { id: "send_msg", label: "Send message", kind: "action", params: [{ key: "to", val: "user" }] },
      { id: "write_log", label: "Write to log", kind: "action", params: [{ key: "level", val: "info" }] },
      { id: "return", label: "Return result", kind: "action", params: [{ key: "value", val: "{{output}}" }] },
    ],
  },
];

// Kind glyphs — simple typographic markers, not SVG illustrations
const KIND_GLYPH = {
  start: "▸",
  end: "■",
  action: "·",
  branch: "◇",
};

// Example prefilled flow — uses catalog block ids

const EXAMPLE_FLOW = [
];

// Helper: look up catalog entry by block id
function findBlock(blockId) {
  for (const cat of BLOCK_CATALOG) {
    const b = cat.blocks.find((x) => x.id === blockId);
    if (b) return { ...b, category: cat.category, accent: cat.accent };
  }
  return null;
}

Object.assign(window, { BLOCK_CATALOG, KIND_GLYPH, EXAMPLE_FLOW, findBlock });
