import { getToolOrDynamicToolName, isReasoningUIPart, isTextUIPart, isToolOrDynamicToolUIPart } from "../../../../node_modules/ai/dist/index.js";
import { Message, MessageAction, MessageActions, MessageContent, MessageResponse } from "../../../../components/ai-elements/message.js";
import { Reasoning, ReasoningContent, ReasoningTrigger } from "../../../../components/ai-elements/reasoning.js";
import { Source, Sources, SourcesContent, SourcesTrigger } from "../../../../components/ai-elements/sources.js";
import { Tool, ToolContent, ToolHeader, ToolInput, ToolOutput } from "../../../../components/ai-elements/tool.js";
import { c } from "react/compiler-runtime";
import { Fragment } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { CopyIcon } from "lucide-react";
var AiMessage_default = (O) => {
	let k = c(13), { document: A } = O, j = A.content, M, N;
	if (k[0] !== j.id || k[1] !== j.parts || k[2] !== j.role) {
		let n = j.parts?.filter(_temp) ?? [];
		M = Fragment, N = j.role === "assistant" && n.length > 0 && /* @__PURE__ */ jsxs(Sources, { children: [/* @__PURE__ */ jsx(SourcesTrigger, { count: n.length }), n.map((n, T) => /* @__PURE__ */ jsx(SourcesContent, { children: /* @__PURE__ */ jsx(Source, {
			href: n.url,
			title: n.url
		}) }, `${j.id}-source-${T}`))] }), k[0] = j.id, k[1] = j.parts, k[2] = j.role, k[3] = M, k[4] = N;
	} else M = k[3], N = k[4];
	let P;
	k[5] !== j.id || k[6] !== j.parts || k[7] !== j.role ? (P = j.parts?.map((E, D) => {
		if (isTextUIPart(E)) return /* @__PURE__ */ jsxs(Message, {
			from: j.role,
			children: [/* @__PURE__ */ jsx(MessageContent, { children: /* @__PURE__ */ jsx(MessageResponse, { children: E.text }) }), j.role === "assistant" && /* @__PURE__ */ jsx(MessageActions, { children: /* @__PURE__ */ jsx(MessageAction, {
				onClick: () => void navigator.clipboard.writeText(E.text),
				label: "Copy",
				children: /* @__PURE__ */ jsx(CopyIcon, { className: "size-3" })
			}) })]
		}, `${j.id}-${D}`);
		if (isReasoningUIPart(E)) return /* @__PURE__ */ jsxs(Reasoning, {
			className: "w-full",
			isStreaming: !1,
			children: [/* @__PURE__ */ jsx(ReasoningTrigger, {}), /* @__PURE__ */ jsx(ReasoningContent, { children: E.text })]
		}, `${j.id}-${D}`);
		if (isToolOrDynamicToolUIPart(E)) {
			let T = getToolOrDynamicToolName(E);
			return /* @__PURE__ */ jsx(Message, {
				from: j.role,
				children: /* @__PURE__ */ jsxs(Tool, { children: [/* @__PURE__ */ jsx(ToolHeader, {
					state: E.state,
					title: T,
					type: E.type
				}), /* @__PURE__ */ jsxs(ToolContent, { children: [/* @__PURE__ */ jsx(ToolInput, { input: E.input }), /* @__PURE__ */ jsx(ToolOutput, {
					output: E.output,
					errorText: E.errorText ?? ""
				})] })] })
			}, `${j.id}-${D}`);
		}
		return null;
	}), k[5] = j.id, k[6] = j.parts, k[7] = j.role, k[8] = P) : P = k[8];
	let F;
	return k[9] !== M || k[10] !== N || k[11] !== P ? (F = /* @__PURE__ */ jsxs(M, { children: [N, P] }), k[9] = M, k[10] = N, k[11] = P, k[12] = F) : F = k[12], F;
};
function _temp(n) {
	return n.type === "source-url";
}
export { AiMessage_default as default };
