import { useMemo as i } from "react";
import { getNodeText as s } from "../get-node-text.js";
import { SHIKI_CLASSNAME as n } from "./constants.js";
function r(t) {
  if (!t || typeof t != "object")
    return !1;
  if (Array.isArray(t)) {
    for (const o of t)
      if (r(o))
        return !0;
  }
  if ("props" in t && t.props && typeof t.props == "object") {
    if ("className" in t.props && typeof t.props.className == "string" && t.props.className.includes(n))
      return !0;
    if ("children" in t.props)
      return r(t.props.children);
  }
  return !1;
}
function C(t, o, e = !1) {
  return ((o == null ? void 0 : o.includes(n)) || r(t)) && !e ? "" : s(t);
}
function p(t) {
  if (!t || typeof t != "string")
    return 0;
  const o = t.match(/<span class="line/g);
  return o ? o.length : 0;
}
function g(t, o) {
  return i(() => o !== void 0 ? o : t ? p(t) : void 0, [t, o]);
}
export {
  p as calculateCodeLinesFromHtml,
  C as getCodeString,
  g as useCalculateCodeLines
};
