"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require$$0 = require("react/jsx-runtime");
const designSystem = require("@choiceform/design-system");
const react = require("../../../_vendor/@legendapp/state/react.cjs");
const React = require("react");
const tv = require("../tv.cjs");
const messageAttachments = require("./messages/message-attachments/message-attachments.cjs");
const messageStore = require("../../../stores/message-store.cjs");
const markdown = require("../../common/markdown/markdown.cjs");
const ResponseContent = react.observer(function ResponseContent2(props) {
  const { response, messageId, hasAvatar, hasActions, hasTimestamp, children, className } = props;
  const id = messageId ?? response?.message?.id;
  const message = react.use$(id ? messageStore.messageComputed$.getMessage(id) : void 0);
  const isStreaming = message?.isStreaming ?? false;
  const resolvedHasAvatar = hasAvatar ?? response?.hasAvatar ?? false;
  const resolvedHasActions = hasActions ?? response?.hasActions ?? false;
  const resolvedHasTimestamp = hasTimestamp ?? response?.hasTimestamp ?? false;
  const isUser = message?.role === "user";
  const content = message?.content ?? "";
  const renderedContent = React.useMemo(() => {
    if (isUser || !content) {
      return content;
    }
    return content + (isStreaming ? "|" : "");
  }, [content, isStreaming, isUser]);
  const tv$1 = tv.responseTv({
    hasAvatar: resolvedHasAvatar,
    hasActions: resolvedHasActions,
    hasTimestamp: resolvedHasTimestamp
  });
  if (!message) return null;
  return /* @__PURE__ */ require$$0.jsxs("div", { className: tv$1.content({ className }), children: [
    renderedContent ? children ?? /* @__PURE__ */ require$$0.jsx(markdown.Markdown, { children: renderedContent }) : /* @__PURE__ */ require$$0.jsx("div", { className: tv$1.loading(), children: /* @__PURE__ */ require$$0.jsx(designSystem.SpinnerBounce, { size: "small" }) }),
    message.attachments && message.attachments.length > 0 && /* @__PURE__ */ require$$0.jsx(messageAttachments.MessageAttachments, { attachments: message.attachments })
  ] });
});
exports.ResponseContent = ResponseContent;
//# sourceMappingURL=response-content.cjs.map
