// Small reusable bits + icons.

const Icon = {
  Search: () => (
    <svg width="13" height="13" viewBox="0 0 16 16" fill="none">
      <circle cx="7" cy="7" r="4.5" stroke="currentColor" strokeWidth="1.4" />
      <path d="M10.5 10.5L13.5 13.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" />
    </svg>
  ),
  Plus: () => (
    <svg width="12" height="12" viewBox="0 0 16 16" fill="none">
      <path d="M8 3.5V12.5M3.5 8H12.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" />
    </svg>
  ),
  Filter: () => (
    <svg width="12" height="12" viewBox="0 0 16 16" fill="none">
      <path d="M2.5 4.5H13.5M4.5 8H11.5M6.5 11.5H9.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" />
    </svg>
  ),
  Close: () => (
    <svg width="13" height="13" viewBox="0 0 16 16" fill="none">
      <path d="M4 4L12 12M12 4L4 12" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" />
    </svg>
  ),
  Menu: () => (
    <svg width="15" height="15" viewBox="0 0 16 16" fill="none">
      <path d="M2.5 4.5H13.5M2.5 8H13.5M2.5 11.5H13.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" />
    </svg>
  ),
  Sun: () => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none">
      <circle cx="8" cy="8" r="2.7" stroke="currentColor" strokeWidth="1.4" />
      <path d="M8 1.5V3M8 13V14.5M14.5 8H13M3 8H1.5M12.6 3.4L11.5 4.5M4.5 11.5L3.4 12.6M12.6 12.6L11.5 11.5M4.5 4.5L3.4 3.4" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" />
    </svg>
  ),
  Moon: () => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none">
      <path d="M13 9.5A5.5 5.5 0 1 1 6.5 3a4.5 4.5 0 0 0 6.5 6.5Z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round" />
    </svg>
  ),
  Branch: () => (
    <svg width="11" height="11" viewBox="0 0 16 16" fill="none">
      <circle cx="4" cy="3.5" r="1.5" stroke="currentColor" strokeWidth="1.3" />
      <circle cx="4" cy="12.5" r="1.5" stroke="currentColor" strokeWidth="1.3" />
      <circle cx="12" cy="6.5" r="1.5" stroke="currentColor" strokeWidth="1.3" />
      <path d="M4 5V11M4 8.5C4 6.8 5.5 6.5 7 6.5H10.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" />
    </svg>
  ),
  PR: () => (
    <svg width="11" height="11" viewBox="0 0 16 16" fill="none">
      <circle cx="4" cy="3.5" r="1.5" stroke="currentColor" strokeWidth="1.3" />
      <circle cx="4" cy="12.5" r="1.5" stroke="currentColor" strokeWidth="1.3" />
      <circle cx="12" cy="12.5" r="1.5" stroke="currentColor" strokeWidth="1.3" />
      <path d="M4 5V11M12 5.5V11M12 5.5C12 4 11 3 9.5 3H8M8 3L9.5 1.5M8 3L9.5 4.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  ),
  Chevron: ({ open }) => (
    <svg width="10" height="10" viewBox="0 0 16 16" fill="none" style={{ transform: open ? "rotate(90deg)" : "none", transition: "transform 0.15s" }}>
      <path d="M6 4L10 8L6 12" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  ),
  Sparkle: () => (
    <svg width="11" height="11" viewBox="0 0 16 16" fill="none">
      <path d="M8 2L9 6.5L13.5 8L9 9.5L8 14L7 9.5L2.5 8L7 6.5L8 2Z" stroke="currentColor" strokeWidth="1.2" strokeLinejoin="round" />
    </svg>
  ),
  Tool: () => (
    <svg width="9" height="9" viewBox="0 0 16 16" fill="none">
      <path d="M3 3L6 6M6 6L3 9L6 12L9 9M6 6L9 3L12 6L9 9" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  ),
  Dot: () => (
    <svg width="6" height="6" viewBox="0 0 6 6"><circle cx="3" cy="3" r="2" fill="currentColor" /></svg>
  ),
  Output: () => (
    <svg width="9" height="9" viewBox="0 0 16 16" fill="none">
      <path d="M4 4L12 8L4 12V4Z" fill="currentColor" />
    </svg>
  ),
  Wait: () => (
    <svg width="9" height="9" viewBox="0 0 16 16" fill="none">
      <circle cx="8" cy="8" r="6" stroke="currentColor" strokeWidth="1.3" />
      <path d="M8 5V8L10 9.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" />
    </svg>
  ),
  Decision: () => (
    <svg width="9" height="9" viewBox="0 0 16 16" fill="none">
      <path d="M8 2L14 8L8 14L2 8L8 2Z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round" />
    </svg>
  ),
};

function Avatar({ who, size = 20 }) {
  const a = (window.AGENTS || {})[who] || { name: who || "?", kind: "ai", hue: Math.abs((who || "?").charCodeAt(0) || 0) % 360, role: "" };
  const name = a.name || who || "?";
  const initials = String(name).split(" ").map((s) => s[0] || "").join("").slice(0, 2).toUpperCase() || "?";
  const bg = a.kind === "human"
    ? `oklch(56% 0.10 ${a.hue || 260})`
    : `oklch(58% 0.14 ${a.hue || 200})`;
  return (
    <div
      className={"avatar" + (a.kind === "ai" ? " ai" : "")}
      style={{
        background: bg,
        width: size,
        height: size,
        fontSize: size <= 20 ? 9.5 : size * 0.42,
      }}
      title={`${name}${a.role ? " · " + a.role : ""}`}
    >
      {initials}
    </div>
  );
}

window.Icon = Icon;
window.Avatar = Avatar;
