import {
  toReactNodes
} from "./chunk-OYIPFTQC.js";
import {
  isClipboardTextFieldNode,
  isCurrencyAmountNode,
  isIconNode,
  isLinkNode,
  isNextLinkNode,
  isTextNode
} from "./chunk-FZUV52PP.js";
import {
  isString
} from "./chunk-HAC5YAGQ.js";
import {
  __spreadProps,
  __spreadValues
} from "./chunk-W7FAWX6T.js";

// src/utils/toReactNodes/setReactNodesTypography.tsx
import { ensureArray } from "@lightsparkdev/core";
function isNonTypographicReactNode(node) {
  return typeof node === "undefined" || node === null || isIconNode(node);
}
function setReactNodesTypography(nodesArg, typography, replaceExistingTypography = true) {
  const nodes = ensureArray(nodesArg);
  const typographyMap = {
    link: typography.link || typography.default,
    text: typography.text || typography.default,
    nextLink: typography.nextLink || typography.default,
    currencyAmount: typography.currencyAmount || typography.default,
    clipboardTextField: typography.clipboardTextField || typography.default
  };
  const nodesWithTypography = nodes.map((node) => {
    if (isNonTypographicReactNode(node)) {
      return node;
    } else if (isLinkNode(node) && typographyMap.link) {
      return {
        link: __spreadProps(__spreadValues({}, node.link), {
          typography: replaceExistingTypography ? typographyMap.link : node.link.typography || typographyMap.link
        })
      };
    } else if (isNextLinkNode(node) && typographyMap.nextLink) {
      return {
        nextLink: __spreadProps(__spreadValues({}, node.nextLink), {
          typography: replaceExistingTypography ? typographyMap.nextLink : node.nextLink.typography || typographyMap.nextLink
        })
      };
    } else if (isCurrencyAmountNode(node) && typographyMap.currencyAmount) {
      return {
        currencyAmount: __spreadProps(__spreadValues({}, node.currencyAmount), {
          typography: typographyMap.currencyAmount
        })
      };
    } else if (isClipboardTextFieldNode(node) && typographyMap.clipboardTextField) {
      return {
        clipboardTextField: __spreadProps(__spreadValues({}, node.clipboardTextField), {
          typography: typographyMap.clipboardTextField
        })
      };
    } else if ((isTextNode(node) || isString(node)) && typographyMap.text) {
      return setTextNodeTypography(
        node,
        typographyMap.text,
        replaceExistingTypography
      );
    }
    return node;
  });
  return nodesWithTypography;
}
function setTextNodeTypography(node, typography, replaceExistingTypography = true) {
  if (isString(node)) {
    return {
      text: node,
      typography
    };
  }
  const useExistingTypography = !replaceExistingTypography && "typography" in node ? node.typography : void 0;
  return __spreadProps(__spreadValues({}, node), {
    typography: useExistingTypography || typography
  });
}
function toReactNodesWithTypographyMap(nodesArg, nodesTypographyMap, replaceExistingTypography = true) {
  if (!nodesArg) {
    return null;
  }
  const nodesWithTypography = setReactNodesTypography(
    nodesArg,
    nodesTypographyMap,
    replaceExistingTypography
  );
  const nodes = toReactNodes(nodesWithTypography);
  return nodes;
}
function setDefaultReactNodesTypography(nodesArg, setDefaultReactNodesTypographyArg) {
  return setReactNodesTypography(
    nodesArg,
    setDefaultReactNodesTypographyArg,
    false
  );
}

export {
  isNonTypographicReactNode,
  setReactNodesTypography,
  toReactNodesWithTypographyMap,
  setDefaultReactNodesTypography
};
