import { stringToNodes } from "./stringToNodes.js";
import { renderTypography } from "../../components/typography/renderTypography.js";
import { Link } from "../../router.js";
import { isClipboardTextFieldNode, isCurrencyAmountNode, isIconNode, isLinkNode, isNextLinkNode, isTextNode } from "./nodes.js";
import { Icon } from "../../components/Icon/Icon.js";
import { CurrencyAmount } from "../../components/CurrencyAmount.js";
import { NextLink } from "../NextLink.js";
import { ClipboardTextField } from "../../components/ClipboardTextField.js";
import { Fragment } from "react";
import { jsx } from "@emotion/react/jsx-runtime";
import { ensureArray } from "@lightsparkdev/core";
//#region src/utils/toReactNodes/toReactNodes.tsx
function toReactNodes(toReactNodesArg) {
	return /* @__PURE__ */ jsx(Fragment, { children: ensureArray(toReactNodesArg).map((node, i) => {
		if (!node) return null;
		else if (typeof node === "string" || isTextNode(node)) {
			const text = typeof node === "string" ? node : node.text;
			let content = text;
			if (isTextNode(node) && node.typography) {
				const { type: typographyType, ...typographyProps } = node.typography;
				content = renderTypography(typographyType, {
					...typographyProps,
					children: text
				});
			} else content = stringToNodes(text);
			return /* @__PURE__ */ jsx(Fragment, { children: content }, `text-${i}-${text.substr(0, 20)}`);
		} else if (isLinkNode(node)) return /* @__PURE__ */ jsx(Link, { ...node.link }, `link-${i}-${node.link.id}`);
		else if (isNextLinkNode(node)) return /* @__PURE__ */ jsx(NextLink, { ...node.nextLink }, `next-link-${i}-${node.nextLink.id}`);
		else if (isIconNode(node)) return /* @__PURE__ */ jsx(Icon, {
			...node.icon,
			width: node.icon.width || 12
		}, `icon-${i}-${node.icon.id}`);
		else if (isCurrencyAmountNode(node)) return /* @__PURE__ */ jsx(CurrencyAmount, { ...node.currencyAmount }, `currency-amount-${i}-${node.currencyAmount.id}`);
		else if (isClipboardTextFieldNode(node)) return /* @__PURE__ */ jsx(ClipboardTextField, { ...node.clipboardTextField }, `clipboard-text-field-${i}-${node.clipboardTextField.id}`);
		return null;
	}) });
}
//#endregion
export { toReactNodes };
