import { computed as h } from "vue";
import { tokenize as N } from "../../node_modules/linkifyjs/dist/linkify.js";
import T from "../../node_modules/linkify-string/dist/linkify-string.js";
import { parseMarkdown as E } from "../../functions/parseMarkdown.js";
function k(e) {
  return e.includes("**") || e.includes("`") || e.includes("~~") || e.includes(`

`) || e.includes(">") && e.trimStart().startsWith(">") || /<\/(u|s|b|i)>|<(u|s|b|i)[\s>]/.test(e);
}
const _ = (e) => ({ linkedHtml: h(() => {
  const t = e();
  if (!t) return "";
  if (!k(t))
    return T(t);
  const r = E(t), i = document.createElement("div");
  i.innerHTML = r;
  const p = (o) => {
    var u;
    const n = o.textContent || "", a = N(n);
    if (a.length === 1 && !a[0].isLink)
      return;
    const l = document.createDocumentFragment();
    a.forEach((s) => {
      if (s.isLink) {
        const c = document.createElement("a");
        c.href = s.toHref(), c.target = "_blank", c.textContent = s.toString(), l.appendChild(c);
      } else
        l.appendChild(document.createTextNode(s.toString()));
    }), (u = o.parentNode) == null || u.replaceChild(l, o);
  }, f = document.createTreeWalker(
    i,
    NodeFilter.SHOW_TEXT,
    {
      acceptNode: (o) => {
        let n = o.parentNode;
        for (; n && n !== i; ) {
          if (n.nodeName === "A")
            return NodeFilter.FILTER_REJECT;
          n = n.parentNode;
        }
        return NodeFilter.FILTER_ACCEPT;
      }
    }
  ), m = [];
  let d;
  for (; d = f.nextNode(); )
    d.nodeType === Node.TEXT_NODE && m.push(d);
  return m.reverse().forEach(p), i.innerHTML;
}), inNewWindow: (t) => {
  t.preventDefault();
  const r = t.target;
  r && "href" in r && r.href && window.open(r.href, "_blank");
} });
export {
  _ as useMessageLinks
};
