import { b as attr_class, a as attr, e as ensure_array_like, c as attr_style, f as clsx, d as attributes } from './index2-BpEbpEAf.js';
import { g as get, w as writable } from './index-BSa6KzSq.js';
import { I as Icon } from './Icon-SOvOgynh.js';
import { X as escape_html } from './context-B0vutJuA.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 Link($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      href = "",
      variant = "default",
      children,
      class: className = "",
      target: targetProp,
      rel: relProp,
      $$slots,
      $$events,
      ...rest
    } = $$props;
    const linkClasses = `link ${className}`.trim();
    const isExternal = variant === "external";
    const target = targetProp ?? (isExternal ? "_blank" : void 0);
    const rel = relProp ?? (target === "_blank" ? "noopener noreferrer" : void 0);
    $$renderer2.push(`<a${attributes({ href, class: clsx(linkClasses), target, rel, ...rest }, "svelte-1jt144g")}>`);
    children($$renderer2);
    $$renderer2.push(`<!----></a>`);
  });
}
function AgentSidebar($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      agents = [],
      currentAgent,
      onSelect,
      onToggle,
      className = "",
      showAgents = true,
      onAgentClick,
      onCreateAgent,
      showAllAgentsOption = false,
      onAllAgentsClick,
      initiallyCollapsed = true,
      hoverCollapse = true
    } = $$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: var(--agent-color); color: black;";
    const isAllAgentsActive = showAllAgentsOption && !currentAgent;
    $$renderer2.push(`<div${attr_class(`sidebar border-r border-r-gray-700/50 ${"sidebar--collapsed w-16"} ${className}`, "svelte-ubnu4b")}><div class="relative top-2 flex h-14 items-center gap-5 py-4 pl-5 pr-3">`);
    {
      $$renderer2.push("<!--[!-->");
    }
    $$renderer2.push(`<!--]--> <button class="toggle-btn svelte-ubnu4b"${attr("title", "Expand sidebar")}${attr("aria-expanded", false)}${attr("aria-label", "Expand sidebar")}><span class="toggle-btn__front svelte-ubnu4b">`);
    {
      $$renderer2.push("<!--[-->");
      $$renderer2.push(`<img src="/recombine.svg" alt="Recombine Logo" class="size-6" width="24" height="24" decoding="async" loading="eager"/>`);
    }
    $$renderer2.push(`<!--]--></span> <span class="toggle-btn__back svelte-ubnu4b" aria-hidden="true">`);
    Icon($$renderer2, { name: "chevron-right", width: 24, height: 24 });
    $$renderer2.push(`<!----></span></button></div> <div class="mt-3 min-h-0 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: ${colorForAgent(agent)}`)}><div class="agent-initials svelte-ubnu4b"${attr_style(isActive ? activeInitialsStyle : void 0)}${attr("title", agentName(agent))}>${escape_html(getInitial(agent))}</div> `);
        {
          $$renderer2.push("<!--[!-->");
        }
        $$renderer2.push(`<!--]--></button>`);
      }
      $$renderer2.push(`<!--]--> `);
      if (showAllAgentsOption) {
        $$renderer2.push("<!--[-->");
        $$renderer2.push(`<button class="agent-item svelte-ubnu4b" title="All agents" aria-label="All agents"${attr("aria-current", isAllAgentsActive ? "page" : void 0)}><span class="agent-initials svelte-ubnu4b" aria-hidden="true"${attr_style(isAllAgentsActive ? activeInitialsStyle : void 0)}>*</span></button>`);
      } else {
        $$renderer2.push("<!--[!-->");
      }
      $$renderer2.push(`<!--]--> `);
      if (onCreateAgent) {
        $$renderer2.push("<!--[-->");
        $$renderer2.push(`<button class="agent-item new-agent svelte-ubnu4b" title="New Agent" aria-label="Create new agent">`);
        {
          $$renderer2.push("<!--[-->");
          $$renderer2.push(`<div class="agent-initials new-agent__initial w-full svelte-ubnu4b"></div>`);
        }
        $$renderer2.push(`<!--]--></button>`);
      } else {
        $$renderer2.push("<!--[!-->");
      }
      $$renderer2.push(`<!--]--></div>`);
    } else {
      $$renderer2.push("<!--[!-->");
      $$renderer2.push(`<div${attr_class(clsx("px-1 py-2"))}></div>`);
    }
    $$renderer2.push(`<!--]--></div> <footer${attr_class(`sidebar__footer ${"hidden"}`, "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-DqMxRWln.js.map
