import { jsx as t, jsxs as s } from "react/jsx-runtime";
import { useStreamContext as w } from "../../providers/Stream.es.js";
import { FileIcon as v, X as y, Send as z, Pencil as N, Copy as k } from "lucide-react";
import S, { useState as h } from "react";
function C({ message: a, fontSize: r }) {
  const [p, c] = h(!1), [l, d] = h(""), f = w(), x = f.getMessagesMetadata(a), b = x?.firstSeenState?.parent_checkpoint, i = a.content;
  let n = "", m = [];
  typeof i == "string" ? n = i : Array.isArray(i) && (n = i.filter((e) => e.type === "text").map((e) => e.type === "text" ? e.text : "").join(""), m = i.filter((e) => e.type === "document") ?? []);
  const g = () => {
    if (!l.trim())
      return;
    c(!1);
    const e = { type: "human", content: l };
    f.submit(
      { messages: [e] },
      {
        checkpoint: b,
        streamMode: ["values"],
        streamSubgraphs: !0,
        streamResumable: !0,
        optimisticValues: (o) => {
          const u = x?.firstSeenState?.values;
          return u ? {
            ...u,
            messages: [...u.messages ?? [], e]
          } : o;
        }
      }
    );
  };
  return /* @__PURE__ */ t("div", { className: "flex flex-col gap-1 w-full group my-1", children: /* @__PURE__ */ s("div", { className: "flex flex-1 flex-col gap-2 items-end min-w-0 mr-4", children: [
    m.length > 0 && /* @__PURE__ */ t("div", { className: "flex flex-col gap-2 max-w-[90%]", children: m.map((e, o) => /* @__PURE__ */ s(
      "div",
      {
        className: "flex items-center gap-3 bg-linear-to-br from-zinc-800/90 to-zinc-900/90 backdrop-blur-sm px-4 py-1 rounded-xl border border-zinc-700/50 shadow-md hover:border-blue-500/40 hover:shadow-lg hover:shadow-blue-500/10 transition-all duration-200 cursor-pointer group/file",
        children: [
          /* @__PURE__ */ t("div", { className: "p-1.5 bg-blue-500/10 rounded-lg border border-blue-500/20 group-hover/file:bg-blue-500/20 transition-colors", children: /* @__PURE__ */ t(v, { size: 16, className: "text-blue-400 shrink-0" }) }),
          /* @__PURE__ */ t("span", { className: "text-sm text-zinc-200 truncate font-medium", children: e.source?.filename || `Document ${o + 1}` })
        ]
      },
      `${a.id}-doc-${o}`
    )) }),
    n && /* @__PURE__ */ s("div", { className: "flex flex-col items-end gap-1", children: [
      /* @__PURE__ */ t("div", { className: "relative flex-1 w-full flex justify-end", children: p ? /* @__PURE__ */ s("div", { className: "flex flex-col gap-2 w-full", children: [
        /* @__PURE__ */ t(
          "textarea",
          {
            value: l,
            onChange: (e) => d(e.target.value),
            onKeyDown: (e) => {
              e.key === "Enter" && (e.preventDefault(), g());
            },
            className: "font-normal leading-relaxed rounded-2xl px-5 bg-zinc-900 border border-zinc-800 text-white shadow-lg wrap-break-word overflow-wrap-anywhere resize-none focus:outline-none min-h-15",
            style: r ? { fontSize: r } : { fontSize: "15px" },
            autoFocus: !0
          }
        ),
        /* @__PURE__ */ s("div", { className: "flex items-center justify-end gap-2", children: [
          /* @__PURE__ */ t(
            "button",
            {
              onClick: () => {
                c(!1), d("");
              },
              className: "flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-zinc-800 hover:bg-zinc-700 text-zinc-300 text-sm transition-colors",
              children: /* @__PURE__ */ t(y, { size: 16 })
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: g,
              disabled: !l.trim(),
              className: "flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-white text-black text-sm transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
              children: /* @__PURE__ */ t(z, { size: 16 })
            }
          )
        ] })
      ] }) : /* @__PURE__ */ t("div", { className: "font-normal leading-relaxed rounded-xl py-2 px-4 bg-[#242322] text-white shadow-lg max-w-full break-words overflow-wrap-anywhere", style: r ? { fontSize: r } : { fontSize: "15px" }, children: n }) }),
      !p && /* @__PURE__ */ s("div", { className: "flex items-center gap-4 opacity-0 group-hover:opacity-100 transition-opacity duration-300", children: [
        /* @__PURE__ */ t(
          N,
          {
            size: 16,
            className: "text-zinc-500 cursor-pointer hover:text-white",
            onClick: () => {
              c(!0), d(n);
            }
          }
        ),
        /* @__PURE__ */ t(
          k,
          {
            size: 16,
            className: "text-zinc-500 cursor-pointer hover:text-white",
            onClick: () => {
              navigator.clipboard.writeText(n);
            }
          }
        )
      ] })
    ] })
  ] }) });
}
const D = S.memo(C, (a, r) => a.message.id === r.message.id && a.fontSize === r.fontSize);
export {
  D as default
};
//# sourceMappingURL=HumanMessage.es.js.map
