import { a as attr_class, b as attr, e as ensure_array_like, d as attr_style, s as stringify, n as clsx } from './index2-CzosXNJA.js';
import { g as get, w as writable } from './index-FgxKh3J4.js';
import { I as Icon, L as Link } from './Link-BxAwzNX6.js';
import { X as escape_html } from './context-BZ_07CFR.js';

const PALETTE = [
  "#FB60DF",
  "#EAFF6D",
  "#65E3FF",
  "#FF8165",
  "#826DFF",
  "#FF8C3F",
  "#1269FF",
  "#FFA812",
  "#60FB7C",
  "#3FB2FF"
];
function load() {
  try {
    if (typeof sessionStorage === "undefined") return {};
    const raw = sessionStorage.getItem("agentColors");
    return raw ? JSON.parse(raw) : {};
  } catch {
    return {};
  }
}
const agentColorsStore = writable(load());
agentColorsStore.subscribe((m) => {
  try {
    if (typeof sessionStorage !== "undefined") {
      sessionStorage.setItem("agentColors", JSON.stringify(m));
    }
  } catch {
  }
});
function colorForAgent(agent) {
  const map = get(agentColorsStore);
  if (map[agent]) return map[agent];
  const used = new Set(Object.values(map));
  const available = PALETTE.filter((c) => !used.has(c));
  const pick = available.length > 0 ? available[Math.floor(Math.random() * available.length)] : PALETTE[Math.floor(Math.random() * PALETTE.length)];
  agentColorsStore.set({ ...map, [agent]: pick });
  return pick;
}
function AgentSidebar($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      agents = [],
      currentAgent,
      onSelect,
      onToggle,
      className = "",
      isCollapsed = false,
      showAgents = true,
      onAgentClick,
      onCreateAgent
    } = $$props;
    const agentName = (id) => id.split("/").at(-1) ?? id;
    function getInitial(agentId) {
      const first = agentName(agentId).trim().charAt(0);
      return first ? first.toUpperCase() : "?";
    }
    const hasAgents = showAgents && agents.length > 0;
    const activeInitialsStyle = "background-color: color-mix(in oklch, var(--agent-color) 20%, transparent); color: var(--agent-color);";
    const activeNameStyle = "color: var(--agent-color)";
    $$renderer2.push(`<div${attr_class(`sidebar ${isCollapsed ? "w-16" : "w-52"} ${className}`, "svelte-ubnu4b")}><div class="relative top-2 flex h-14 items-center gap-6 p-4">`);
    if (!isCollapsed) {
      $$renderer2.push("<!--[-->");
      $$renderer2.push(`<a href="/" class="flex cursor-pointer items-center gap-2"><img src="/recombine.svg" alt="Recombine Logo" class="size-6" width="24" height="24"/> <span class="logo__text svelte-ubnu4b">Recombine</span></a>`);
    } else {
      $$renderer2.push("<!--[!-->");
    }
    $$renderer2.push(`<!--]--> <button class="toggle-btn group svelte-ubnu4b"${attr("title", isCollapsed ? "Expand sidebar" : "Collapse sidebar")}${attr("aria-expanded", !isCollapsed)}${attr("aria-label", isCollapsed ? "Expand sidebar" : "Collapse sidebar")}><span class="toggle-btn__front svelte-ubnu4b">`);
    if (isCollapsed) {
      $$renderer2.push("<!--[-->");
      $$renderer2.push(`<img src="/recombine.svg" alt="Recombine Logo" class="size-6" width="24" height="24" decoding="async" loading="eager"/>`);
    } else {
      $$renderer2.push("<!--[!-->");
      Icon($$renderer2, {
        name: "chevron-left",
        width: 24,
        height: 24,
        class: "self-end"
      });
    }
    $$renderer2.push(`<!--]--></span> <span${attr_class(`toggle-btn__back ${isCollapsed ? "group-hover:opacity-100" : ""}`, "svelte-ubnu4b")} aria-hidden="true">`);
    Icon($$renderer2, { name: "chevron-right", width: 24, height: 24 });
    $$renderer2.push(`<!----></span></button></div> <div class="mt-3 flex-1 overflow-y-auto overflow-x-hidden">`);
    if (hasAgents) {
      $$renderer2.push("<!--[-->");
      $$renderer2.push(`<div${attr_class(`flex flex-col`, "svelte-ubnu4b")}><!--[-->`);
      const each_array = ensure_array_like(agents);
      for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
        let agent = each_array[$$index];
        const isActive = agent === currentAgent;
        $$renderer2.push(`<button class="agent-item svelte-ubnu4b"${attr("title", agent)}${attr("aria-current", isActive ? "page" : void 0)}${attr_style(`--agent-color:${stringify(colorForAgent(agent))}`)}><div class="agent-initials svelte-ubnu4b"${attr_style(isActive ? activeInitialsStyle : void 0)}${attr("title", agentName(agent))}>${escape_html(getInitial(agent))}</div> `);
        if (!isCollapsed) {
          $$renderer2.push("<!--[-->");
          $$renderer2.push(`<span class="flex-1 truncate font-semibold"${attr_style(isActive ? activeNameStyle : void 0)}${attr("title", agentName(agent))}>${escape_html(agentName(agent))}</span>`);
        } else {
          $$renderer2.push("<!--[!-->");
        }
        $$renderer2.push(`<!--]--></button>`);
      }
      $$renderer2.push(`<!--]--> <button class="agent-item new-agent svelte-ubnu4b" title="New Agent" aria-label="Create new agent">`);
      if (isCollapsed) {
        $$renderer2.push("<!--[-->");
        $$renderer2.push(`<div class="agent-initials new-agent__initial svelte-ubnu4b"></div>`);
      } else {
        $$renderer2.push("<!--[!-->");
        $$renderer2.push(`<div class="agent-initials new-agent__initial svelte-ubnu4b"></div> <span class="flex-1 truncate font-semibold">New Agent</span>`);
      }
      $$renderer2.push(`<!--]--></button></div>`);
    } else {
      $$renderer2.push("<!--[!-->");
      $$renderer2.push(`<div${attr_class(clsx(isCollapsed ? "px-1 py-2" : "py-2 pl-2 pr-4"))}></div>`);
    }
    $$renderer2.push(`<!--]--></div> <footer${attr_class(`sidebar__footer ${isCollapsed ? "hidden" : "flex"}`, "svelte-ubnu4b")}><div class="footer-links svelte-ubnu4b">`);
    Link($$renderer2, {
      variant: "external",
      href: "https://recombine.ai/policy.html",
      children: ($$renderer3) => {
        $$renderer3.push(`<!---->Privacy Policy`);
      },
      $$slots: { default: true }
    });
    $$renderer2.push(`<!----> `);
    Link($$renderer2, {
      variant: "external",
      href: "https://recombine.ai/terms.html",
      children: ($$renderer3) => {
        $$renderer3.push(`<!---->Terms and Conditions`);
      },
      $$slots: { default: true }
    });
    $$renderer2.push(`<!----></div> <div class="footer-links svelte-ubnu4b"><p class="svelte-ubnu4b">@ Recombine 2025</p> <p class="svelte-ubnu4b">London, UK</p> <p class="svelte-ubnu4b">Budva, Montenegro</p></div></footer></div>`);
  });
}

export { AgentSidebar as A, colorForAgent as c };
//# sourceMappingURL=AgentSidebar-DRTSgEv8.js.map
