import { defineTransformer } from "../../core/plugins.js";
const RE_FLEX_CLASS = /\bflex\b/;
const INLINE_ELEMENTS = [
  "span",
  "a",
  "b",
  "i",
  "u",
  "em",
  "strong",
  "code",
  "abbr",
  "del",
  "ins",
  "mark",
  "sub",
  "sup",
  "small",
  "p",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5"
];
export default defineTransformer({
  filter: (node) => [...INLINE_ELEMENTS, "div"].includes(node.type) && (Array.isArray(node.props?.children) && node.props?.children.length >= 1) && !node.props?.class?.includes("hidden"),
  transform: (node) => {
    node.props.style = node.props.style || {};
    if (node.props.style.display) {
      return;
    }
    if (node.type === "div") {
      node.props.style.display = "flex";
      if (!node.props.style.flexDirection && !RE_FLEX_CLASS.test(node.props?.class || "")) {
        node.props.style.flexDirection = "column";
      }
      return;
    }
    node.props.style.display = "flex";
    if (!node.props.style.flexWrap) {
      node.props.style.flexWrap = "wrap";
    }
    if (node.props.style.flexWrap === "wrap" && !node.props.style.gap) {
      node.props.style.gap = "0.2em";
    }
  }
});
