import {
  isClipboardTextFieldNode,
  isCurrencyAmountNode,
  isIconNode,
  isLinkNode,
  isNextLinkNode,
  isTextNode
} from "./chunk-FZUV52PP.js";
import {
  NextLink
} from "./chunk-NBYTATDG.js";
import {
  ClipboardTextField
} from "./chunk-ZOIGYYOQ.js";
import {
  CurrencyAmount
} from "./chunk-MK67FJ2M.js";
import {
  Icon
} from "./chunk-DMPXNHDT.js";
import {
  Link
} from "./chunk-SWMGDTQN.js";
import {
  renderTypography
} from "./chunk-KAMBSKAE.js";
import {
  stringToNodes
} from "./chunk-2466FZJC.js";
import {
  __objRest,
  __spreadProps,
  __spreadValues
} from "./chunk-W7FAWX6T.js";

// src/utils/toReactNodes/toReactNodes.tsx
import { ensureArray } from "@lightsparkdev/core";
import { Fragment } from "react";
import { jsx } from "@emotion/react/jsx-runtime";
function toReactNodes(toReactNodesArg) {
  const toReactNodesArray = ensureArray(toReactNodesArg);
  const reactNodes = toReactNodesArray.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 _a = node.typography, { type: typographyType } = _a, typographyProps = __objRest(_a, ["type"]);
        content = renderTypography(typographyType, __spreadProps(__spreadValues({}, typographyProps), {
          children: text
        }));
      } else {
        content = stringToNodes(text);
      }
      return (
        /* text property is a sufficient key for both strings and text nodes due to minimal impl */
        /* @__PURE__ */ jsx(Fragment, { children: content }, `text-${i}-${text.substr(0, 20)}`)
      );
    } else if (isLinkNode(node)) {
      return /* @__PURE__ */ jsx(Link, __spreadValues({}, node.link), `link-${i}-${node.link.id}`);
    } else if (isNextLinkNode(node)) {
      return /* @__PURE__ */ jsx(
        NextLink,
        __spreadValues({}, node.nextLink),
        `next-link-${i}-${node.nextLink.id}`
      );
    } else if (isIconNode(node)) {
      return /* @__PURE__ */ jsx(
        Icon,
        __spreadProps(__spreadValues({}, node.icon), {
          width: node.icon.width || 12
        }),
        `icon-${i}-${node.icon.id}`
      );
    } else if (isCurrencyAmountNode(node)) {
      return /* @__PURE__ */ jsx(
        CurrencyAmount,
        __spreadValues({}, node.currencyAmount),
        `currency-amount-${i}-${node.currencyAmount.id}`
      );
    } else if (isClipboardTextFieldNode(node)) {
      return /* @__PURE__ */ jsx(
        ClipboardTextField,
        __spreadValues({}, node.clipboardTextField),
        `clipboard-text-field-${i}-${node.clipboardTextField.id}`
      );
    }
    return null;
  });
  return /* @__PURE__ */ jsx(Fragment, { children: reactNodes });
}

export {
  toReactNodes
};
