import clsx from "clsx"; import * as htmlToImage from "html-to-image"; import { useTranslation } from "next-i18next"; import type { PropsWithChildren, ReactNode } from "react"; import React from "react"; import { CgExport } from "react-icons/cg"; import { FaImage } from "react-icons/fa"; import { FiClipboard } from "react-icons/fi"; import type { Message } from "../../types/message"; import Menu from "../Menu"; import Expand from "../motions/expand"; import PopIn from "../motions/popin"; import PDFButton from "../pdf/PDFButton"; import WindowButton from "../WindowButton"; export const messageListId = "chat-window-message-list"; export interface HeaderProps { title?: string | ReactNode; messages: Message[]; } export const MacWindowHeader = (props: HeaderProps) => { const [t] = useTranslation(); const saveElementAsImage = (elementId: string) => { const element = document.getElementById(elementId); if (!element) { return; } htmlToImage .toJpeg(element, { height: element.scrollHeight, style: { overflowY: "visible", maxHeight: "none", border: "none", }, }) .then((dataUrl) => { const link = document.createElement("a"); link.href = dataUrl; link.download = "agent-gpt-output.png"; link.click(); }) .catch(() => alert("Error saving image! Note this doesn't work if the AI generated an image") ); }; const copyElementText = (elementId: string) => { const element = document.getElementById(elementId); if (!element) { return; } const text = element.innerText; if (navigator.clipboard) { void navigator.clipboard.writeText(text); } else { // Fallback to a different method for unsupported browsers const textArea = document.createElement("textarea"); textArea.value = text; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { document.execCommand("copy"); console.log("Text copied to clipboard"); } catch (err) { console.error("Unable to copy text to clipboard", err); } document.body.removeChild(textArea); } }; const exportOptions = [ saveElementAsImage(messageListId)} icon={} text={t("IMAGE", { ns: "common" })} />, copyElementText(messageListId)} icon={} text={t("COPY", { ns: "common" })} />, , ]; return ( {props.title} } items={exportOptions} /> ); }; interface MacWindowInternalProps extends PropsWithChildren { className?: string; } export const MacWindowInternal = (props: MacWindowInternalProps) => { return ( {props.children} ); };