import { Node_Type } from "./../ricos-schema/legacy/wix/rich_content/v1/index.js";
const ensureCardsWrap = (content) => {
  if (!content?.nodes?.length) {
    return content;
  }
  const isAlreadyWrapped = content.nodes.every((node) => node.type === Node_Type.CARD);
  if (isAlreadyWrapped) {
    return content;
  }
  const wrappedNodes = [];
  let pendingNodes = [];
  const flushPending = () => {
    if (pendingNodes.length > 0) {
      wrappedNodes.push({
        type: Node_Type.CARD,
        nodes: pendingNodes,
        cardData: {}
      });
      pendingNodes = [];
    }
  };
  for (const node of content.nodes) {
    if (node.type === Node_Type.CARD) {
      flushPending();
      wrappedNodes.push(node);
    } else {
      pendingNodes.push(node);
    }
  }
  flushPending();
  return {
    ...content,
    nodes: wrappedNodes
  };
};
export {
  ensureCardsWrap
};
//# sourceMappingURL=ensure-cards-wrap.js.map
