import {
  Markdown
} from "./chunk-MEZ3GLQ5.mjs";
import {
  useChatContext
} from "./chunk-IEMQ2SQW.mjs";

// src/components/chat/messages/AssistantMessage.tsx
import { useState } from "react";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var AssistantMessage = (props) => {
  var _a;
  const { icons, labels } = useChatContext();
  const {
    message,
    isLoading,
    onRegenerate,
    onCopy,
    onThumbsUp,
    onThumbsDown,
    isCurrentMessage,
    markdownTagRenderers
  } = props;
  const [copied, setCopied] = useState(false);
  const handleCopy = () => {
    const content2 = (message == null ? void 0 : message.content) || "";
    if (content2 && onCopy) {
      navigator.clipboard.writeText(content2);
      setCopied(true);
      onCopy(content2);
      setTimeout(() => setCopied(false), 2e3);
    } else if (content2) {
      navigator.clipboard.writeText(content2);
      setCopied(true);
      setTimeout(() => setCopied(false), 2e3);
    }
  };
  const handleRegenerate = () => {
    if (onRegenerate)
      onRegenerate();
  };
  const handleThumbsUp = () => {
    if (onThumbsUp && message)
      onThumbsUp(message);
  };
  const handleThumbsDown = () => {
    if (onThumbsDown && message)
      onThumbsDown(message);
  };
  const LoadingIcon = () => /* @__PURE__ */ jsx("span", { children: icons.activityIcon });
  const content = (message == null ? void 0 : message.content) || "";
  const subComponent = (_a = message == null ? void 0 : message.generativeUI) == null ? void 0 : _a.call(message);
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    content && /* @__PURE__ */ jsxs("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
      content && /* @__PURE__ */ jsx(Markdown, { content, components: markdownTagRenderers }),
      content && !isLoading && /* @__PURE__ */ jsxs(
        "div",
        {
          className: `copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`,
          children: [
            /* @__PURE__ */ jsx(
              "button",
              {
                className: "copilotKitMessageControlButton",
                onClick: handleRegenerate,
                "aria-label": labels.regenerateResponse,
                title: labels.regenerateResponse,
                children: icons.regenerateIcon
              }
            ),
            /* @__PURE__ */ jsx(
              "button",
              {
                className: "copilotKitMessageControlButton",
                onClick: handleCopy,
                "aria-label": labels.copyToClipboard,
                title: labels.copyToClipboard,
                children: copied ? /* @__PURE__ */ jsx("span", { style: { fontSize: "10px", fontWeight: "bold" }, children: "\u2713" }) : icons.copyIcon
              }
            ),
            onThumbsUp && /* @__PURE__ */ jsx(
              "button",
              {
                className: "copilotKitMessageControlButton",
                onClick: handleThumbsUp,
                "aria-label": labels.thumbsUp,
                title: labels.thumbsUp,
                children: icons.thumbsUpIcon
              }
            ),
            onThumbsDown && /* @__PURE__ */ jsx(
              "button",
              {
                className: "copilotKitMessageControlButton",
                onClick: handleThumbsDown,
                "aria-label": labels.thumbsDown,
                title: labels.thumbsDown,
                children: icons.thumbsDownIcon
              }
            )
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsx("div", { style: { marginBottom: "0.5rem" }, children: subComponent }),
    isLoading && /* @__PURE__ */ jsx(LoadingIcon, {})
  ] });
};

export {
  AssistantMessage
};
//# sourceMappingURL=chunk-IG6DNX25.mjs.map