import {
  Markdown
} from "../../../chunk-SNFHUE5S.mjs";
import {
  useChatContext
} from "../../../chunk-IEMQ2SQW.mjs";
import "../../../chunk-B5IFB5YJ.mjs";
import "../../../chunk-XWG3L6QC.mjs";
import "../../../chunk-54JAUBUJ.mjs";
import "../../../chunk-MRXNTQOX.mjs";

// src/components/chat/messages/ErrorMessage.tsx
import { useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var ErrorMessage = (props) => {
  const { icons, labels } = useChatContext();
  const { error, onRegenerate, onCopy, isCurrentMessage } = props;
  const [copied, setCopied] = useState(false);
  const handleCopy = () => {
    const content = error.message;
    if (content && onCopy) {
      navigator.clipboard.writeText(content);
      setCopied(true);
      onCopy(content);
      setTimeout(() => setCopied(false), 2e3);
    } else if (content) {
      navigator.clipboard.writeText(content);
      setCopied(true);
      setTimeout(() => setCopied(false), 2e3);
    }
  };
  const handleRegenerate = () => {
    if (onRegenerate)
      onRegenerate();
  };
  console.log(error);
  return /* @__PURE__ */ jsxs("div", { className: "copilotKitMessage copilotKitAssistantMessage", children: [
    /* @__PURE__ */ jsx(Markdown, { content: error.message }),
    /* @__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
        }
      )
    ] })
  ] });
};
export {
  ErrorMessage
};
//# sourceMappingURL=ErrorMessage.mjs.map