"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const reactJsxParser_min = require("../../_vendor/react-jsx-parser/dist-react-jsx-parser.min.cjs");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
function matchJsxTag(code) {
  if (code.trim() === "") {
    return null;
  }
  const tagRegex = /<\/?([a-zA-Z][a-zA-Z0-9]*)\s*([^>]*?)(\/)?>/;
  const match = code.match(tagRegex);
  if (!match || typeof match.index === "undefined") {
    return null;
  }
  const [fullMatch, tagName, attributes, selfClosing] = match;
  const type = selfClosing ? "self-closing" : fullMatch.startsWith("</") ? "closing" : "opening";
  return {
    tag: fullMatch,
    tagName,
    type,
    attributes: attributes.trim(),
    startIndex: match.index,
    endIndex: match.index + fullMatch.length
  };
}
function completeJsxTag(code) {
  const stack = [];
  let result = "";
  let currentPosition = 0;
  while (currentPosition < code.length) {
    const match = matchJsxTag(code.slice(currentPosition));
    if (!match) break;
    const { tagName, type, endIndex } = match;
    if (type === "opening") {
      stack.push(tagName);
    } else if (type === "closing") {
      stack.pop();
    }
    result += code.slice(currentPosition, currentPosition + endIndex);
    currentPosition += endIndex;
  }
  return result + stack.reverse().map((tag) => `</${tag}>`).join("");
}
function JSXPreview({ jsx: jsx2, isStreaming = false, ...props }) {
  const processedJsx = React__namespace.useMemo(
    () => isStreaming ? completeJsxTag(jsx2) : jsx2,
    [jsx2, isStreaming]
  );
  const Parser = reactJsxParser_min.default;
  return /* @__PURE__ */ jsxRuntime.jsx(
    Parser,
    {
      jsx: processedJsx,
      ...props
    }
  );
}
exports.JSXPreview = JSXPreview;
//# sourceMappingURL=jsx-preview.cjs.map
