import { jsxs as n, Fragment as I, jsx as e } from "react/jsx-runtime";
import ce from "../../components/Suggestion.es.js";
import de from "../../components/threads/ThreadHistory.es.js";
import { useFileProvider as fe } from "../../providers/FileProvider.es.js";
import { useStreamContext as me } from "../../providers/Stream.es.js";
import { useThread as ue } from "../../providers/Thread.es.js";
import { logger as U } from "../../utils/logger.es.js";
import { buildContentBlocks as he, readFilesAsBase64 as pe } from "../../utils/submitUtils.es.js";
import { AnimatePresence as O, motion as v } from "framer-motion";
import { EyeOff as be, ScanEye as ge, PanelLeft as ve, X as xe } from "lucide-react";
import { useState as l, useRef as F, useEffect as Y } from "react";
import we from "../../components/ChatBody.es.js";
import ye from "../../components/ChatButton.es.js";
import Ne from "../../components/sidebar/ChatInput.es.js";
import Se from "../../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/v4.es.js";
function Ve(_) {
  const { handleFileSelect: q, callThisOnSubmit: M, enableToolCallIndicator: G, header: r, inputFileAccept: J, filePreview: K, s3_upload: Q, preventSubmit: A, leftPanelContent: k, leftPanelOpen: X, setLeftPanelOpen: Z, chatBodyProps: ee, supportChatHistory: x = !1, textToSpeechVoice: te, leftPanelInitialWidth: ne = 30, leftPanelClassName: H } = _, [R, w] = l(!1), [f, y] = l(""), [ie, se] = l(!1), [m, E] = l(!1), { fileInput: u, setFileInput: h } = fe(), [T, le] = l(ne), [N, ae] = l(30), [S, V] = l(!1), [P, B] = l(!1), D = F(null), p = F(0), b = F(0);
  Y(() => {
    const t = (a) => {
      if (S) {
        const c = (p.current - a.clientX) / window.innerWidth * 100, d = b.current + c, C = Math.max(30, Math.min(40, d));
        le(C);
      } else if (P && D.current) {
        const c = (p.current - a.clientX) / window.innerWidth * 100, d = b.current + c, C = Math.max(30, Math.min(50, d));
        ae(C);
      }
    }, s = () => {
      V(!1), B(!1), document.body.style.cursor = "default", document.body.style.userSelect = "auto";
    };
    if (S || P)
      return document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", t), document.addEventListener("mouseup", s), () => {
        document.removeEventListener("mousemove", t), document.removeEventListener("mouseup", s);
      };
  }, [S, P]);
  const g = X !== void 0 ? X : ie, $ = Z || se, L = me(), j = L.isLoading, { setMode: z } = ue();
  Y(() => {
    z(x ? "multi" : "single");
  }, [z, x]);
  const oe = async (t) => {
    if (t.preventDefault(), A || f.trim().length === 0 && u.length === 0 || j)
      return;
    let s = u, a;
    if (M) {
      const i = await M();
      Array.isArray(i?.files) && i.files.length > 0 && (s = i.files), i && i?.contextValues && (a = i.contextValues);
    }
    U.debug("Using files for submission:", s);
    const o = he(f, s, Q);
    U.debug("Constructed content blocks:", o);
    const c = {
      id: Se(),
      type: "human",
      content: o
    }, d = f, W = u;
    y(""), h([]);
    try {
      await L.submitMessage(c, { contextValues: a });
    } catch (i) {
      throw y(d), h(W), i;
    }
  }, re = q || (async (t) => {
    const s = t.target.files;
    if (!s) return;
    const a = await pe(s);
    h((o) => [...o, ...a]);
  });
  return /* @__PURE__ */ n(I, { children: [
    /* @__PURE__ */ e(O, { children: R && /* @__PURE__ */ n(I, { children: [
      /* @__PURE__ */ e(
        v.div,
        {
          className: "fixed inset-0 z-40 bg-black/30",
          onClick: () => w(!1),
          initial: { opacity: 0 },
          animate: { opacity: 1 },
          exit: { opacity: 0 }
        }
      ),
      /* @__PURE__ */ n(
        v.aside,
        {
          ref: D,
          className: "fixed right-0 top-0 z-50 h-screen flex bg-[#0f0f0f] text-white/70",
          style: { width: m ? `calc(${N}vw + 280px)` : `${N}vw` },
          initial: { x: "100%" },
          animate: { x: 0 },
          exit: { x: "100%" },
          transition: { type: "spring", stiffness: 260, damping: 30 },
          children: [
            /* @__PURE__ */ e(O, { children: g && /* @__PURE__ */ n(
              v.div,
              {
                className: "absolute right-full top-0 h-full bg-[#0a0a0a] border-r border-zinc-700",
                style: { width: `${T}vw` },
                initial: { x: "0" },
                animate: { x: 0 },
                exit: { x: "0%" },
                transition: { type: "spring", stiffness: 400, damping: 40 },
                children: [
                  /* @__PURE__ */ e("div", { className: `h-full overflow-auto relative${H ? ` ${H}` : ""}`, children: k || /* @__PURE__ */ n(I, { children: [
                    /* @__PURE__ */ e("h3", { className: "text-lg font-semibold mb-4 text-white p-4", children: "Left Panel" }),
                    /* @__PURE__ */ e("p", { className: "text-zinc-300 p-4", children: "This is the left extension panel. You can add any content here." })
                  ] }) }),
                  /* @__PURE__ */ e(
                    "div",
                    {
                      onMouseDown: (t) => {
                        t.preventDefault(), t.stopPropagation(), p.current = t.clientX, b.current = T, V(!0);
                      },
                      className: "absolute left-0 top-0 w-1.5 h-full bg-zinc-700/50 cursor-col-resize transition-colors z-[60] hover:w-2 group",
                      style: { touchAction: "none" },
                      children: /* @__PURE__ */ n("div", { className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col gap-1 opacity-60 group-hover:opacity-100", children: [
                        /* @__PURE__ */ e("div", { className: "w-1 h-1 rounded-full bg-white" }),
                        /* @__PURE__ */ e("div", { className: "w-1 h-1 rounded-full bg-white" }),
                        /* @__PURE__ */ e("div", { className: "w-1 h-1 rounded-full bg-white" })
                      ] })
                    }
                  )
                ]
              }
            ) }),
            /* @__PURE__ */ e(
              "div",
              {
                onMouseDown: (t) => {
                  t.preventDefault(), t.stopPropagation(), p.current = t.clientX, b.current = N, B(!0);
                },
                className: "absolute left-0 top-0 w-1.5 h-full bg-zinc-700/50 cursor-col-resize transition-colors z-[60] hover:w-2 group",
                style: { touchAction: "none" },
                children: /* @__PURE__ */ n("div", { className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col gap-1 opacity-60 group-hover:opacity-100", children: [
                  /* @__PURE__ */ e("div", { className: "w-1 h-1 rounded-full bg-white" }),
                  /* @__PURE__ */ e("div", { className: "w-1 h-1 rounded-full bg-white" }),
                  /* @__PURE__ */ e("div", { className: "w-1 h-1 rounded-full bg-white" })
                ] })
              }
            ),
            /* @__PURE__ */ n("div", { className: "flex h-full flex-col flex-1", children: [
              /* @__PURE__ */ n("div", { className: "flex py-3 px-6 justify-between items-center border-b border-zinc-700/30", children: [
                /* @__PURE__ */ n("div", { className: "flex items-center gap-3", children: [
                  k && /* @__PURE__ */ e("div", { className: "flex items-start gap-3", children: g ? /* @__PURE__ */ e(
                    be,
                    {
                      className: "cursor-pointer transition-transform h-5",
                      onClick: () => $(!g)
                    }
                  ) : /* @__PURE__ */ e(
                    ge,
                    {
                      className: "cursor-pointer transition-transform h-5",
                      onClick: () => $(!g)
                    }
                  ) }),
                  r?.logoUrl && /* @__PURE__ */ e(
                    "img",
                    {
                      src: r?.logoUrl,
                      alt: r?.title ? `${r.title} logo` : "AI Assistant logo",
                      className: "h-8 w-8 object-contain rounded-sm"
                    }
                  ),
                  /* @__PURE__ */ e("div", { className: "text-start text-xl font-bold", children: r?.title || "AI Assistant" })
                ] }),
                /* @__PURE__ */ n("div", { className: "flex items-end gap-3", children: [
                  x && !m && /* @__PURE__ */ e(
                    ve,
                    {
                      className: "h-5 text-zinc-400 cursor-pointer hover:text-zinc-200 transition-colors",
                      onClick: () => E(!m)
                    }
                  ),
                  /* @__PURE__ */ e(
                    xe,
                    {
                      className: "text-zinc-400 cursor-pointer",
                      onClick: () => w(!1)
                    }
                  )
                ] })
              ] }),
              /* @__PURE__ */ n("div", { className: "flex-1 relative", children: [
                /* @__PURE__ */ e("div", { className: "absolute inset-0 overflow-auto scrollbar-none", children: /* @__PURE__ */ e("div", { className: "pb-20 p-2", children: /* @__PURE__ */ e(we, { enableToolCallIndicator: G, chatBodyProps: ee }) }) }),
                /* @__PURE__ */ e("div", { className: "absolute bottom-0 left-0 right-0 bg-transparent px-4 pointer-events-none z-10", children: /* @__PURE__ */ e("div", { className: "pointer-events-auto", children: /* @__PURE__ */ e(ce, {}) }) })
              ] }),
              /* @__PURE__ */ e("div", { className: "sticky bottom-0", children: /* @__PURE__ */ e(
                Ne,
                {
                  input: f,
                  inputFileAccept: J,
                  setInput: y,
                  textToSpeechVoice: te,
                  handleSubmit: oe,
                  isLoading: j || !!A,
                  fileInput: u,
                  handleFileSelect: re,
                  setFileInput: h,
                  onCancel: () => L.stop?.(),
                  filePreview: K
                }
              ) })
            ] }),
            /* @__PURE__ */ e(O, { children: m && /* @__PURE__ */ e(
              v.div,
              {
                className: "h-full w-[280px] shadow-2xl border-l border-white/10",
                initial: { width: 0, opacity: 0 },
                animate: { width: 280, opacity: 1 },
                exit: { width: 0, opacity: 0 },
                transition: { type: "spring", stiffness: 300, damping: 30 },
                children: /* @__PURE__ */ e(de, { isSidebar: !0, header: { title: "Sessions" }, onClose: () => E(!1) })
              }
            ) })
          ]
        }
      )
    ] }) }),
    /* @__PURE__ */ e(ye, { isVisible: !R, setOpen: w })
  ] });
}
export {
  Ve as default
};
//# sourceMappingURL=sidebar.es.js.map
