import {
  Text,
  getElementType
} from "./chunk-A66R42LG.js";

// src/components/TextOrHTML/TextOrHTML.tsx
import classNames from "classnames/dedupe";
import { useMemo } from "react";
import { jsx } from "react/jsx-runtime";
var BLOCK_TAG = /<(div|p|ul|ol|li|h[1-6]|table|tr|td|th|blockquote|pre|hr|dl|dt|dd)[\s>/]/i;
var containsBlockHTML = (text) => BLOCK_TAG.test(text);
var containsHTML = (text) => /<[a-z/]/i.test(text) || /&(?:#\d+|#x[\da-f]+|[a-z]\w*);/i.test(text);
var buildTextClasses = (textProps, htmlClassName) => {
  const { variant, elementType, spacing, className } = textProps;
  const variantType = variant || getElementType(variant, elementType);
  return classNames(
    "mobius",
    "mobius-text",
    { [`--is-${variantType}`]: variantType },
    { [`--has-line-height-${spacing}`]: spacing },
    className,
    htmlClassName
  );
};
var TextOrHTML = ({
  ref,
  text,
  htmlClassName,
  htmlElementType,
  textWrapper = false,
  autoDetect = false,
  ...textProps
}) => {
  const hasBlockContent = autoDetect && containsBlockHTML(text);
  const dangerousHTML = useMemo(() => ({ __html: text }), [text]);
  if (autoDetect && !hasBlockContent) {
    const { variant, spacing, elementType, className, ...domProps } = textProps;
    const Element = getElementType(variant, elementType);
    const classes = buildTextClasses(textProps, htmlClassName);
    return containsHTML(text) ? /* @__PURE__ */ jsx(
      Element,
      {
        ref,
        ...domProps,
        className: classes,
        dangerouslySetInnerHTML: dangerousHTML
      }
    ) : /* @__PURE__ */ jsx(Element, { ref, ...domProps, className: classes, children: text });
  }
  const DangerousComponent = htmlElementType ?? (hasBlockContent ? "div" : "span");
  const dangerousElement = /* @__PURE__ */ jsx(
    DangerousComponent,
    {
      className: htmlClassName,
      dangerouslySetInnerHTML: dangerousHTML
    }
  );
  if (textWrapper) {
    return /* @__PURE__ */ jsx(Text, { ref, ...textProps, children: dangerousElement });
  }
  return dangerousElement;
};
TextOrHTML.displayName = "TextOrHTML";

export {
  TextOrHTML
};
//# sourceMappingURL=chunk-KTJCAQT4.js.map
