import { jsxs as l, jsx as e } from "react/jsx-runtime";
import E from "../../components/ChatBody.es.js";
import F from "../../components/sidebar/ChatInput.es.js";
import P from "../../components/Suggestion.es.js";
import R from "../../components/threads/ThreadHistory.es.js";
import { useChatRuntime as _ } from "../../providers/ChatRuntime.es.js";
import { useFileProvider as $ } from "../../providers/FileProvider.es.js";
import { useStreamContext as C } from "../../providers/Stream.es.js";
import { useThread as q } from "../../providers/Thread.es.js";
import { readFilesAsBase64 as G, buildContentBlocks as J } from "../../utils/submitUtils.es.js";
import { useState as u, useEffect as x } from "react";
import K from "../../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/v4.es.js";
function oe(p) {
  const { callThisOnSubmit: g, handleFileSelect: k, enableToolCallIndicator: B, chatBodyProps: D, textToSpeechVoice: b } = p || {}, [j, h] = u(!0), [r, f] = u(""), [w, v] = u(!1), { fileInput: a, setFileInput: o } = $(), [L, T] = u([]), { fetchCatalog: y } = C(), d = C(), { assistantId: H, setAssistantId: M } = _(), z = d.isLoading, { setMode: N, threadId: I } = q();
  x(() => {
    (async () => {
      const t = await y(), m = (Array.isArray(t?.agents) ? t.agents : []).map((i) => i?.graph_id).filter((i) => typeof i == "string" && i.length > 0);
      T(m);
    })();
  }, [y]);
  const V = (s) => {
    const t = s.target.innerText;
    M(t), v(!1);
  };
  x(() => {
    N("multi");
  }, [N]), x(() => {
    d.messages && d.messages.length > 0 ? h(!1) : I || h(!0);
  }, [I, d.messages]);
  const S = async (s) => {
    if (s.preventDefault(), r.trim().length === 0 && a.length === 0 || z)
      return;
    let t = a, c;
    if (g) {
      const n = await g();
      Array.isArray(n?.files) && n.files.length > 0 && (t = n.files), n && n?.contextValues && (c = n.contextValues);
    }
    const m = J(r, t), i = {
      id: K(),
      type: "human",
      content: m
    };
    h(!1);
    const O = r, W = a;
    f(""), o([]);
    try {
      await d.submitMessage(i, { contextValues: c });
    } catch (n) {
      throw f(O), o(W), n;
    }
  }, A = k || (async (s) => {
    const t = s.target.files;
    if (!t) return;
    const c = await G(t);
    o((m) => [...m, ...c]);
  });
  return /* @__PURE__ */ l("div", { className: "flex h-screen w-screen bg-[#0f0f0f] text-white", children: [
    /* @__PURE__ */ e(R, { header: p?.header || { title: "AI Assistant" } }),
    /* @__PURE__ */ l("main", { className: "flex flex-1 flex-col", children: [
      /* @__PURE__ */ l("header", { className: "flex h-14 items-center justify-between border-b border-white/10 px-6", children: [
        /* @__PURE__ */ l(
          "button",
          {
            id: "dropdownDividerButton",
            onClick: () => v(!w),
            className: "inline-flex items-center justify-center text-white bg-brand box-border border rounded-2xl border-transparent hover:bg-brand-strong font-medium leading-5 rounded-base text-sm px-4 py-2.5 bg-zinc-800",
            type: "button",
            children: [
              H,
              /* @__PURE__ */ e("svg", { className: "w-4 h-4 ms-1.5 -me-0.5", "aria-hidden": "true", xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", fill: "none", viewBox: "0 0 24 24", children: /* @__PURE__ */ e("path", { stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "m19 9-7 7-7-7" }) })
            ]
          }
        ),
        /* @__PURE__ */ e("div", { id: "dropdownDivider", className: `z-10 absolute top-14 bg-neutral-primary-medium bg-zinc-800 rounded-2xl  divide-y divide-default-medium w-44 ${w ? "" : "hidden"}`, children: /* @__PURE__ */ e("ul", { className: "p-2 text-sm text-body font-medium", "aria-labelledby": "dropdownDividerButton", children: L.map((s) => /* @__PURE__ */ e("li", { className: "hover:bg-zinc-700 hover:rounded-2xl", onClick: V, children: /* @__PURE__ */ e("span", { className: "inline-flex items-center w-full p-2 hover:bg-neutral-tertiary-medium hover:text-heading rounded", children: s }) }, s)) }) })
      ] }),
      /* @__PURE__ */ e("div", { className: "relative flex flex-1 overflow-hidden", children: j ? /* @__PURE__ */ l("div", { className: "flex flex-1 flex-col items-center justify-center", children: [
        /* @__PURE__ */ e("h1", { className: "mb-8 text-2xl font-medium text-white/80", children: "What are you working on?" }),
        /* @__PURE__ */ e("div", { className: "w-full max-w-2xl px-4", children: /* @__PURE__ */ e(F, { input: r, setInput: f, textToSpeechVoice: b, handleSubmit: S, fileInput: a, setFileInput: o, handleFileSelect: A }) })
      ] }) : (
        // =========================
        // CHAT STATE (after message)
        // =========================
        /* @__PURE__ */ l("div", { className: "flex h-full w-full flex-col", children: [
          /* @__PURE__ */ e("div", { className: "flex-1 overflow-y-auto scrollbar-none [&::-webkit-scrollbar]:hidden", children: /* @__PURE__ */ e("div", { className: "mx-auto max-w-3xl px-4 py-6", children: /* @__PURE__ */ e(E, { setIsFirstMessage: h, enableToolCallIndicator: B, chatBodyProps: D }) }) }),
          /* @__PURE__ */ e("div", { className: "mx-auto", children: /* @__PURE__ */ e(P, {}) }),
          /* @__PURE__ */ e("div", { className: "border-t border-white/10 p-1", children: /* @__PURE__ */ e("div", { className: "mx-auto max-w-3xl", children: /* @__PURE__ */ e(F, { input: r, setInput: f, textToSpeechVoice: b, handleSubmit: S, fileInput: a, setFileInput: o, handleFileSelect: A }) }) })
        ] })
      ) })
    ] })
  ] });
}
export {
  oe as Chat
};
//# sourceMappingURL=Chat.es.js.map
