import { jsx as nn } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import tn from "classnames";
import { useRef as rn, useState as ln, useEffect as on } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
try {
  let e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, n = new e.Error().stack;
  n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "50cc5ea9-10c4-463a-8fb3-5d082e5db070", e._sentryDebugIdIdentifier = "sentry-dbid-50cc5ea9-10c4-463a-8fb3-5d082e5db070");
} catch {
}
var K, h, Le, P, pe, Pe, He, Ae, ce, te, re, Ie, W = {}, Ue = [], _n = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, Q = Array.isArray;
function N(e, n) {
  for (var t in n) e[t] = n[t];
  return e;
}
function se(e) {
  e && e.parentNode && e.parentNode.removeChild(e);
}
function $e(e, n, t) {
  var r, o, l, i = {};
  for (l in n) l == "key" ? r = n[l] : l == "ref" ? o = n[l] : i[l] = n[l];
  if (arguments.length > 2 && (i.children = arguments.length > 3 ? K.call(arguments, 2) : t), typeof e == "function" && e.defaultProps != null) for (l in e.defaultProps) i[l] === void 0 && (i[l] = e.defaultProps[l]);
  return j(e, i, r, o, null);
}
function j(e, n, t, r, o) {
  var l = { type: e, props: n, key: t, ref: r, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: o ?? ++Le, __i: -1, __u: 0 };
  return o == null && h.vnode != null && h.vnode(l), l;
}
function X(e) {
  return e.children;
}
function q(e, n) {
  this.props = e, this.context = n;
}
function U(e, n) {
  if (n == null) return e.__ ? U(e.__, e.__i + 1) : null;
  for (var t; n < e.__k.length; n++) if ((t = e.__k[n]) != null && t.__e != null) return t.__e;
  return typeof e.type == "function" ? U(e) : null;
}
function De(e) {
  var n, t;
  if ((e = e.__) != null && e.__c != null) {
    for (e.__e = e.__c.base = null, n = 0; n < e.__k.length; n++) if ((t = e.__k[n]) != null && t.__e != null) {
      e.__e = e.__c.base = t.__e;
      break;
    }
    return De(e);
  }
}
function le(e) {
  (!e.__d && (e.__d = !0) && P.push(e) && !Y.__r++ || pe != h.debounceRendering) && ((pe = h.debounceRendering) || Pe)(Y);
}
function Y() {
  for (var e, n, t, r, o, l, i, c = 1; P.length; ) P.length > c && P.sort(He), e = P.shift(), c = P.length, e.__d && (t = void 0, r = void 0, o = (r = (n = e).__v).__e, l = [], i = [], n.__P && ((t = N({}, r)).__v = r.__v + 1, h.vnode && h.vnode(t), ue(n.__P, t, r, n.__n, n.__P.namespaceURI, 32 & r.__u ? [o] : null, l, o ?? U(r), !!(32 & r.__u), i), t.__v = r.__v, t.__.__k[t.__i] = t, We(l, t, i), r.__e = r.__ = null, t.__e != o && De(t)));
  Y.__r = 0;
}
function Me(e, n, t, r, o, l, i, c, a, s, d) {
  var _, p, f, g, k, w, v, m = r && r.__k || Ue, T = n.length;
  for (a = cn(t, n, m, a, T), _ = 0; _ < T; _++) (f = t.__k[_]) != null && (p = f.__i == -1 ? W : m[f.__i] || W, f.__i = _, w = ue(e, f, p, o, l, i, c, a, s, d), g = f.__e, f.ref && p.ref != f.ref && (p.ref && ae(p.ref, null, f), d.push(f.ref, f.__c || g, f)), k == null && g != null && (k = g), (v = !!(4 & f.__u)) || p.__k === f.__k ? a = Re(f, a, e, v) : typeof f.type == "function" && w !== void 0 ? a = w : g && (a = g.nextSibling), f.__u &= -7);
  return t.__e = k, a;
}
function cn(e, n, t, r, o) {
  var l, i, c, a, s, d = t.length, _ = d, p = 0;
  for (e.__k = new Array(o), l = 0; l < o; l++) (i = n[l]) != null && typeof i != "boolean" && typeof i != "function" ? (typeof i == "string" || typeof i == "number" || typeof i == "bigint" || i.constructor == String ? i = e.__k[l] = j(null, i, null, null, null) : Q(i) ? i = e.__k[l] = j(X, { children: i }, null, null, null) : i.constructor == null && i.__b > 0 ? i = e.__k[l] = j(i.type, i.props, i.key, i.ref ? i.ref : null, i.__v) : e.__k[l] = i, a = l + p, i.__ = e, i.__b = e.__b + 1, (s = i.__i = sn(i, t, a, _)) != -1 && (_--, (c = t[s]) && (c.__u |= 2)), c == null || c.__v == null ? (s == -1 && (o > d ? p-- : o < d && p++), typeof i.type != "function" && (i.__u |= 4)) : s != a && (s == a - 1 ? p-- : s == a + 1 ? p++ : (s > a ? p-- : p++, i.__u |= 4))) : e.__k[l] = null;
  if (_) for (l = 0; l < d; l++) (c = t[l]) != null && (2 & c.__u) == 0 && (c.__e == r && (r = U(c)), Fe(c, c));
  return r;
}
function Re(e, n, t, r) {
  var o, l;
  if (typeof e.type == "function") {
    for (o = e.__k, l = 0; o && l < o.length; l++) o[l] && (o[l].__ = e, n = Re(o[l], n, t, r));
    return n;
  }
  e.__e != n && (r && (n && e.type && !n.parentNode && (n = U(e)), t.insertBefore(e.__e, n || null)), n = e.__e);
  do
    n = n && n.nextSibling;
  while (n != null && n.nodeType == 8);
  return n;
}
function sn(e, n, t, r) {
  var o, l, i, c = e.key, a = e.type, s = n[t], d = s != null && (2 & s.__u) == 0;
  if (s === null && c == null || d && c == s.key && a == s.type) return t;
  if (r > (d ? 1 : 0)) {
    for (o = t - 1, l = t + 1; o >= 0 || l < n.length; ) if ((s = n[i = o >= 0 ? o-- : l++]) != null && (2 & s.__u) == 0 && c == s.key && a == s.type) return i;
  }
  return -1;
}
function he(e, n, t) {
  n[0] == "-" ? e.setProperty(n, t ?? "") : e[n] = t == null ? "" : typeof t != "number" || _n.test(n) ? t : t + "px";
}
function B(e, n, t, r, o) {
  var l, i;
  e: if (n == "style") if (typeof t == "string") e.style.cssText = t;
  else {
    if (typeof r == "string" && (e.style.cssText = r = ""), r) for (n in r) t && n in t || he(e.style, n, "");
    if (t) for (n in t) r && t[n] == r[n] || he(e.style, n, t[n]);
  }
  else if (n[0] == "o" && n[1] == "n") l = n != (n = n.replace(Ae, "$1")), i = n.toLowerCase(), n = i in e || n == "onFocusOut" || n == "onFocusIn" ? i.slice(2) : n.slice(2), e.l || (e.l = {}), e.l[n + l] = t, t ? r ? t.u = r.u : (t.u = ce, e.addEventListener(n, l ? re : te, l)) : e.removeEventListener(n, l ? re : te, l);
  else {
    if (o == "http://www.w3.org/2000/svg") n = n.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
    else if (n != "width" && n != "height" && n != "href" && n != "list" && n != "form" && n != "tabIndex" && n != "download" && n != "rowSpan" && n != "colSpan" && n != "role" && n != "popover" && n in e) try {
      e[n] = t ?? "";
      break e;
    } catch {
    }
    typeof t == "function" || (t == null || t === !1 && n[4] != "-" ? e.removeAttribute(n) : e.setAttribute(n, n == "popover" && t == 1 ? "" : t));
  }
}
function me(e) {
  return function(n) {
    if (this.l) {
      var t = this.l[n.type + e];
      if (n.t == null) n.t = ce++;
      else if (n.t < t.u) return;
      return t(h.event ? h.event(n) : n);
    }
  };
}
function ue(e, n, t, r, o, l, i, c, a, s) {
  var d, _, p, f, g, k, w, v, m, T, L, O, M, de, F, R, ee, E = n.type;
  if (n.constructor != null) return null;
  128 & t.__u && (a = !!(32 & t.__u), l = [c = n.__e = t.__e]), (d = h.__b) && d(n);
  e: if (typeof E == "function") try {
    if (v = n.props, m = "prototype" in E && E.prototype.render, T = (d = E.contextType) && r[d.__c], L = d ? T ? T.props.value : d.__ : r, t.__c ? w = (_ = n.__c = t.__c).__ = _.__E : (m ? n.__c = _ = new E(v, L) : (n.__c = _ = new q(v, L), _.constructor = E, _.render = an), T && T.sub(_), _.state || (_.state = {}), _.__n = r, p = _.__d = !0, _.__h = [], _._sb = []), m && _.__s == null && (_.__s = _.state), m && E.getDerivedStateFromProps != null && (_.__s == _.state && (_.__s = N({}, _.__s)), N(_.__s, E.getDerivedStateFromProps(v, _.__s))), f = _.props, g = _.state, _.__v = n, p) m && E.getDerivedStateFromProps == null && _.componentWillMount != null && _.componentWillMount(), m && _.componentDidMount != null && _.__h.push(_.componentDidMount);
    else {
      if (m && E.getDerivedStateFromProps == null && v !== f && _.componentWillReceiveProps != null && _.componentWillReceiveProps(v, L), n.__v == t.__v || !_.__e && _.shouldComponentUpdate != null && _.shouldComponentUpdate(v, _.__s, L) === !1) {
        for (n.__v != t.__v && (_.props = v, _.state = _.__s, _.__d = !1), n.__e = t.__e, n.__k = t.__k, n.__k.some(function(A) {
          A && (A.__ = n);
        }), O = 0; O < _._sb.length; O++) _.__h.push(_._sb[O]);
        _._sb = [], _.__h.length && i.push(_);
        break e;
      }
      _.componentWillUpdate != null && _.componentWillUpdate(v, _.__s, L), m && _.componentDidUpdate != null && _.__h.push(function() {
        _.componentDidUpdate(f, g, k);
      });
    }
    if (_.context = L, _.props = v, _.__P = e, _.__e = !1, M = h.__r, de = 0, m) {
      for (_.state = _.__s, _.__d = !1, M && M(n), d = _.render(_.props, _.state, _.context), F = 0; F < _._sb.length; F++) _.__h.push(_._sb[F]);
      _._sb = [];
    } else do
      _.__d = !1, M && M(n), d = _.render(_.props, _.state, _.context), _.state = _.__s;
    while (_.__d && ++de < 25);
    _.state = _.__s, _.getChildContext != null && (r = N(N({}, r), _.getChildContext())), m && !p && _.getSnapshotBeforeUpdate != null && (k = _.getSnapshotBeforeUpdate(f, g)), R = d, d != null && d.type === X && d.key == null && (R = Oe(d.props.children)), c = Me(e, Q(R) ? R : [R], n, t, r, o, l, i, c, a, s), _.base = n.__e, n.__u &= -161, _.__h.length && i.push(_), w && (_.__E = _.__ = null);
  } catch (A) {
    if (n.__v = null, a || l != null) if (A.then) {
      for (n.__u |= a ? 160 : 128; c && c.nodeType == 8 && c.nextSibling; ) c = c.nextSibling;
      l[l.indexOf(c)] = null, n.__e = c;
    } else {
      for (ee = l.length; ee--; ) se(l[ee]);
      oe(n);
    }
    else n.__e = t.__e, n.__k = t.__k, A.then || oe(n);
    h.__e(A, n, t);
  }
  else l == null && n.__v == t.__v ? (n.__k = t.__k, n.__e = t.__e) : c = n.__e = un(t.__e, n, t, r, o, l, i, a, s);
  return (d = h.diffed) && d(n), 128 & n.__u ? void 0 : c;
}
function oe(e) {
  e && e.__c && (e.__c.__e = !0), e && e.__k && e.__k.forEach(oe);
}
function We(e, n, t) {
  for (var r = 0; r < t.length; r++) ae(t[r], t[++r], t[++r]);
  h.__c && h.__c(n, e), e.some(function(o) {
    try {
      e = o.__h, o.__h = [], e.some(function(l) {
        l.call(o);
      });
    } catch (l) {
      h.__e(l, o.__v);
    }
  });
}
function Oe(e) {
  return typeof e != "object" || e == null || e.__b && e.__b > 0 ? e : Q(e) ? e.map(Oe) : N({}, e);
}
function un(e, n, t, r, o, l, i, c, a) {
  var s, d, _, p, f, g, k, w = t.props || W, v = n.props, m = n.type;
  if (m == "svg" ? o = "http://www.w3.org/2000/svg" : m == "math" ? o = "http://www.w3.org/1998/Math/MathML" : o || (o = "http://www.w3.org/1999/xhtml"), l != null) {
    for (s = 0; s < l.length; s++) if ((f = l[s]) && "setAttribute" in f == !!m && (m ? f.localName == m : f.nodeType == 3)) {
      e = f, l[s] = null;
      break;
    }
  }
  if (e == null) {
    if (m == null) return document.createTextNode(v);
    e = document.createElementNS(o, m, v.is && v), c && (h.__m && h.__m(n, l), c = !1), l = null;
  }
  if (m == null) w === v || c && e.data == v || (e.data = v);
  else {
    if (l = l && K.call(e.childNodes), !c && l != null) for (w = {}, s = 0; s < e.attributes.length; s++) w[(f = e.attributes[s]).name] = f.value;
    for (s in w) if (f = w[s], s != "children") {
      if (s == "dangerouslySetInnerHTML") _ = f;
      else if (!(s in v)) {
        if (s == "value" && "defaultValue" in v || s == "checked" && "defaultChecked" in v) continue;
        B(e, s, null, f, o);
      }
    }
    for (s in v) f = v[s], s == "children" ? p = f : s == "dangerouslySetInnerHTML" ? d = f : s == "value" ? g = f : s == "checked" ? k = f : c && typeof f != "function" || w[s] === f || B(e, s, f, w[s], o);
    if (d) c || _ && (d.__html == _.__html || d.__html == e.innerHTML) || (e.innerHTML = d.__html), n.__k = [];
    else if (_ && (e.innerHTML = ""), Me(n.type == "template" ? e.content : e, Q(p) ? p : [p], n, t, r, m == "foreignObject" ? "http://www.w3.org/1999/xhtml" : o, l, i, l ? l[0] : t.__k && U(t, 0), c, a), l != null) for (s = l.length; s--; ) se(l[s]);
    c || (s = "value", m == "progress" && g == null ? e.removeAttribute("value") : g != null && (g !== e[s] || m == "progress" && !g || m == "option" && g != w[s]) && B(e, s, g, w[s], o), s = "checked", k != null && k != e[s] && B(e, s, k, w[s], o));
  }
  return e;
}
function ae(e, n, t) {
  try {
    if (typeof e == "function") {
      var r = typeof e.__u == "function";
      r && e.__u(), r && n == null || (e.__u = e(n));
    } else e.current = n;
  } catch (o) {
    h.__e(o, t);
  }
}
function Fe(e, n, t) {
  var r, o;
  if (h.unmount && h.unmount(e), (r = e.ref) && (r.current && r.current != e.__e || ae(r, null, n)), (r = e.__c) != null) {
    if (r.componentWillUnmount) try {
      r.componentWillUnmount();
    } catch (l) {
      h.__e(l, n);
    }
    r.base = r.__P = null;
  }
  if (r = e.__k) for (o = 0; o < r.length; o++) r[o] && Fe(r[o], n, t || typeof e.type != "function");
  t || se(e.__e), e.__c = e.__ = e.__e = void 0;
}
function an(e, n, t) {
  return this.constructor(e, t);
}
function fn(e, n, t) {
  var r, o, l, i;
  n == document && (n = document.documentElement), h.__ && h.__(e, n), o = (r = !1) ? null : n.__k, l = [], i = [], ue(n, e = n.__k = $e(X, null, [e]), o || W, W, n.namespaceURI, o ? null : n.firstChild ? K.call(n.childNodes) : null, l, o ? o.__e : n.firstChild, r, i), We(l, e, i);
}
function Be(e) {
  function n(t) {
    var r, o;
    return this.getChildContext || (r = /* @__PURE__ */ new Set(), (o = {})[n.__c] = this, this.getChildContext = function() {
      return o;
    }, this.componentWillUnmount = function() {
      r = null;
    }, this.shouldComponentUpdate = function(l) {
      this.props.value != l.value && r.forEach(function(i) {
        i.__e = !0, le(i);
      });
    }, this.sub = function(l) {
      r.add(l);
      var i = l.componentWillUnmount;
      l.componentWillUnmount = function() {
        r && r.delete(l), i && i.call(l);
      };
    }), t.children;
  }
  return n.__c = "__cC" + Ie++, n.__ = e, n.Provider = n.__l = (n.Consumer = function(t, r) {
    return t.children(r);
  }).contextType = n, n;
}
K = Ue.slice, h = { __e: function(e, n, t, r) {
  for (var o, l, i; n = n.__; ) if ((o = n.__c) && !o.__) try {
    if ((l = o.constructor) && l.getDerivedStateFromError != null && (o.setState(l.getDerivedStateFromError(e)), i = o.__d), o.componentDidCatch != null && (o.componentDidCatch(e, r || {}), i = o.__d), i) return o.__E = o;
  } catch (c) {
    e = c;
  }
  throw e;
} }, Le = 0, q.prototype.setState = function(e, n) {
  var t;
  t = this.__s != null && this.__s != this.state ? this.__s : this.__s = N({}, this.state), typeof e == "function" && (e = e(N({}, t), this.props)), e && N(t, e), e != null && this.__v && (n && this._sb.push(n), le(this));
}, q.prototype.forceUpdate = function(e) {
  this.__v && (this.__e = !0, e && this.__h.push(e), le(this));
}, q.prototype.render = X, P = [], Pe = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, He = function(e, n) {
  return e.__v.__b - n.__v.__b;
}, Y.__r = 0, Ae = /(PointerCapture)$|Capture$/i, ce = 0, te = me(!1), re = me(!0), Ie = 0;
var dn = 0;
function u(e, n, t, r, o, l) {
  n || (n = {});
  var i, c, a = n;
  if ("ref" in a) for (c in a = {}, n) c == "ref" ? i = n[c] : a[c] = n[c];
  var s = { type: e, props: a, key: t, ref: i, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --dn, __i: -1, __u: 0, __source: o, __self: l };
  if (typeof e == "function" && (i = e.defaultProps)) for (c in i) a[c] === void 0 && (a[c] = i[c]);
  return h.vnode && h.vnode(s), s;
}
function pn(e) {
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
var ve = { exports: {} }, ye;
function hn() {
  return ye || (ye = 1, (function(e) {
    (function() {
      var n = {}.hasOwnProperty;
      function t() {
        for (var l = "", i = 0; i < arguments.length; i++) {
          var c = arguments[i];
          c && (l = o(l, r(c)));
        }
        return l;
      }
      function r(l) {
        if (typeof l == "string" || typeof l == "number")
          return l;
        if (typeof l != "object")
          return "";
        if (Array.isArray(l))
          return t.apply(null, l);
        if (l.toString !== Object.prototype.toString && !l.toString.toString().includes("[native code]"))
          return l.toString();
        var i = "";
        for (var c in l)
          n.call(l, c) && l[c] && (i = o(i, c));
        return i;
      }
      function o(l, i) {
        return i ? l ? l + " " + i : l + i : l;
      }
      e.exports ? (t.default = t, e.exports = t) : window.classNames = t;
    })();
  })(ve)), ve.exports;
}
var mn = hn();
const S = /* @__PURE__ */ pn(mn);
var x = /* @__PURE__ */ ((e) => (e.Chapter = "chapter", e.Section = "section", e.Paragraph = "paragraph", e.Text = "text", e.Weblink = "weblink", e.List = "list", e.Table = "table", e.InternalReference = "internalReference", e.Bigskip = "bigskip", e))(x || {}), ie = /* @__PURE__ */ ((e) => (e.Bold = "BOLD", e.Italic = "ITALIC", e))(ie || {});
let ge = Date.now();
const je = (e = "id") => (ge += 1, `${e}-${ge}`);
var $, y, ne, be, G = 0, qe = [], b = h, we = b.__b, ke = b.__r, xe = b.diffed, Ee = b.__c, Ne = b.unmount, Se = b.__;
function Z(e, n) {
  b.__h && b.__h(y, e, G || n), G = 0;
  var t = y.__H || (y.__H = { __: [], __h: [] });
  return e >= t.__.length && t.__.push({}), t.__[e];
}
function D(e) {
  return G = 1, vn(Ge, e);
}
function vn(e, n, t) {
  var r = Z($++, 2);
  if (r.t = e, !r.__c && (r.__ = [Ge(void 0, n), function(c) {
    var a = r.__N ? r.__N[0] : r.__[0], s = r.t(a, c);
    a !== s && (r.__N = [s, r.__[1]], r.__c.setState({}));
  }], r.__c = y, !y.__f)) {
    var o = function(c, a, s) {
      if (!r.__c.__H) return !0;
      var d = r.__c.__H.__.filter(function(p) {
        return !!p.__c;
      });
      if (d.every(function(p) {
        return !p.__N;
      })) return !l || l.call(this, c, a, s);
      var _ = r.__c.props !== c;
      return d.forEach(function(p) {
        if (p.__N) {
          var f = p.__[0];
          p.__ = p.__N, p.__N = void 0, f !== p.__[0] && (_ = !0);
        }
      }), l && l.call(this, c, a, s) || _;
    };
    y.__f = !0;
    var l = y.shouldComponentUpdate, i = y.componentWillUpdate;
    y.componentWillUpdate = function(c, a, s) {
      if (this.__e) {
        var d = l;
        l = void 0, o(c, a, s), l = d;
      }
      i && i.call(this, c, a, s);
    }, y.shouldComponentUpdate = o;
  }
  return r.__N || r.__;
}
function I(e, n) {
  var t = Z($++, 3);
  !b.__s && Ye(t.__H, n) && (t.__ = e, t.u = n, y.__H.__h.push(t));
}
function yn(e) {
  return G = 5, Ve(function() {
    return { current: e };
  }, []);
}
function Ve(e, n) {
  var t = Z($++, 7);
  return Ye(t.__H, n) && (t.__ = e(), t.__H = n, t.__h = e), t.__;
}
function ze(e) {
  var n = y.context[e.__c], t = Z($++, 9);
  return t.c = e, n ? (t.__ == null && (t.__ = !0, n.sub(y)), n.props.value) : e.__;
}
function gn() {
  for (var e; e = qe.shift(); ) if (e.__P && e.__H) try {
    e.__H.__h.forEach(V), e.__H.__h.forEach(_e), e.__H.__h = [];
  } catch (n) {
    e.__H.__h = [], b.__e(n, e.__v);
  }
}
b.__b = function(e) {
  y = null, we && we(e);
}, b.__ = function(e, n) {
  e && n.__k && n.__k.__m && (e.__m = n.__k.__m), Se && Se(e, n);
}, b.__r = function(e) {
  ke && ke(e), $ = 0;
  var n = (y = e.__c).__H;
  n && (ne === y ? (n.__h = [], y.__h = [], n.__.forEach(function(t) {
    t.__N && (t.__ = t.__N), t.u = t.__N = void 0;
  })) : (n.__h.forEach(V), n.__h.forEach(_e), n.__h = [], $ = 0)), ne = y;
}, b.diffed = function(e) {
  xe && xe(e);
  var n = e.__c;
  n && n.__H && (n.__H.__h.length && (qe.push(n) !== 1 && be === b.requestAnimationFrame || ((be = b.requestAnimationFrame) || bn)(gn)), n.__H.__.forEach(function(t) {
    t.u && (t.__H = t.u), t.u = void 0;
  })), ne = y = null;
}, b.__c = function(e, n) {
  n.some(function(t) {
    try {
      t.__h.forEach(V), t.__h = t.__h.filter(function(r) {
        return !r.__ || _e(r);
      });
    } catch (r) {
      n.some(function(o) {
        o.__h && (o.__h = []);
      }), n = [], b.__e(r, t.__v);
    }
  }), Ee && Ee(e, n);
}, b.unmount = function(e) {
  Ne && Ne(e);
  var n, t = e.__c;
  t && t.__H && (t.__H.__.forEach(function(r) {
    try {
      V(r);
    } catch (o) {
      n = o;
    }
  }), t.__H = void 0, n && b.__e(n, t.__v));
};
var Te = typeof requestAnimationFrame == "function";
function bn(e) {
  var n, t = function() {
    clearTimeout(r), Te && cancelAnimationFrame(n), setTimeout(e);
  }, r = setTimeout(t, 35);
  Te && (n = requestAnimationFrame(t));
}
function V(e) {
  var n = y, t = e.__c;
  typeof t == "function" && (e.__c = void 0, t()), y = n;
}
function _e(e) {
  var n = y;
  e.__c = e.__(), y = n;
}
function Ye(e, n) {
  return !e || e.length !== n.length || n.some(function(t, r) {
    return t !== e[r];
  });
}
function Ge(e, n) {
  return typeof n == "function" ? n(e) : n;
}
const Je = Be(null);
function wn({
  children: e,
  className: n,
  expand: t = !1,
  type: r,
  onExpandSection: o
}) {
  const [l, i] = D([]), c = S("adv-accordion", n, {
    "adv-accordion--container": r === "container"
  });
  return /* @__PURE__ */ u(Je.Provider, { value: { expand: t, items: l, setItems: i, onExpandSection: o }, children: /* @__PURE__ */ u("div", { className: c, children: e }) });
}
function kn() {
  return /* @__PURE__ */ u("div", { className: "adv-bigskip" });
}
const Ce = {
  1: "h1",
  2: "h2"
};
function fe({ className: e, level: n, children: t }) {
  const r = Ce[n] || Ce[1], o = S("adv-heading", `adv-heading--${n}`, e);
  return $e(r, { className: o }, t);
}
function H({ content: e, styles: n }) {
  const t = S({
    "adv-u-font-weight-semi-bold": n?.includes(ie.Bold),
    "adv-u-font-italic": n?.includes(ie.Italic)
  });
  return /* @__PURE__ */ u("span", { className: t, children: e });
}
function xn({ title: e, contentElements: n }) {
  return /* @__PURE__ */ u("section", { className: "adv-u-margin-bottom-48", children: [
    /* @__PURE__ */ u(fe, { level: 2, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ u(H, { content: e.content, styles: e.styles }) }),
    /* @__PURE__ */ u(C, { contentElements: n, isTopLevel: !0 })
  ] });
}
const Ke = Be({
  references: {},
  addReference: () => {
  }
});
function Qe() {
  const e = ze(Ke);
  if (e === void 0)
    throw new Error("useReferenceContext must be used within a ReferenceProvider");
  return e;
}
const En = (e) => new Promise((n) => {
  setTimeout(n, e);
}), J = (e) => e ? `adyen-document-viewer-${e.replace(/[^\w-]/g, "").slice(0, 32)}` : void 0, Xe = (e) => {
  if (!e) return null;
  const n = e instanceof HTMLElement, t = n && window.getComputedStyle(e).overflowY;
  return n && t !== "visible" && t !== "hidden" ? e : Xe(e.parentNode) ?? document.body;
}, Nn = ({ onClick: e, label: n }) => /* @__PURE__ */ u("button", { className: "adv-link", type: "button", onClick: e, title: n, children: n });
function Sn({
  referencedLabel: e,
  displayText: n
}) {
  const t = n ? n.content : e, r = J(e) ?? "", { references: o } = Qe();
  return /* @__PURE__ */ u(Nn, { onClick: async () => {
    o && r && o[r] && (o[r].openSection(), await En(150)), Xe(document.getElementById(r))?.querySelector(`#${r}`)?.scrollIntoView({ behavior: "smooth" });
  }, label: t });
}
function Tn({ className: e, nested: n, ordered: t, noMarkers: r, children: o }) {
  const l = S([
    "adv-list",
    n && "adv-list--nested",
    t && "adv-list--ordered",
    r && "adv-list--no-markers",
    e
  ]);
  return /* @__PURE__ */ u("ul", { className: l, children: o });
}
function Cn({ className: e, children: n, noMarkers: t }) {
  const r = S(["adv-list__item", t && "adv-list__item--no-markers", e]);
  return /* @__PURE__ */ u("li", { className: r, children: n });
}
function Ze({ items: e, style: n }) {
  return /* @__PURE__ */ u(Tn, { ordered: n.ordered, children: e.map((t, r) => /* @__PURE__ */ u(Cn, { children: [
    /* @__PURE__ */ u(C, { contentElements: t.content }),
    t.subList && /* @__PURE__ */ u(Ze, { style: t.subList.style, items: t.subList.items })
  ] }, r)) });
}
function Ln({ isTopLevel: e, contentElements: n }) {
  const t = S("adv-paragraph", {
    "adv-u-margin-bottom-16": e
  });
  return /* @__PURE__ */ u("p", { className: t, children: /* @__PURE__ */ u(C, { contentElements: n }) });
}
function Pn({
  children: e,
  collapsed: n = !1
}) {
  const t = yn(null), [r, o] = D(n ? 0 : void 0);
  return I(() => {
    o(n ? 0 : t.current?.scrollHeight);
  }, [n]), /* @__PURE__ */ u(
    "div",
    {
      className: "adv-collapsible-container",
      "aria-hidden": n,
      ref: t,
      style: { height: r },
      children: e
    }
  );
}
const Hn = ({ className: e = "", name: n }) => {
  const t = {
    "chevron-up": /* @__PURE__ */ u("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 15 15", width: "15", height: "15", children: /* @__PURE__ */ u(
      "path",
      {
        fillRule: "evenodd",
        d: "M13 10a1 1 0 0 1-1.743.669L7.5 6.495 3.743 10.67a1 1 0 0 1-1.486-1.338l4.5-5a1 1 0 0 1 1.486 0l4.5 5a.998.998 0 0 1 .257.67z"
      }
    ) }),
    "chevron-down": /* @__PURE__ */ u("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 15 15", width: "15", height: "15", children: /* @__PURE__ */ u(
      "path",
      {
        fillRule: "evenodd",
        d: "M2 5a1 1 0 0 1 1.743-.669L7.5 8.505l3.757-4.174a1 1 0 0 1 1.486 1.338l-4.5 5a1 1 0 0 1-1.486 0l-4.5-5A.998.998 0 0 1 2 4.999z"
      }
    ) })
  };
  return /* @__PURE__ */ u("i", { className: S("adv-icon", e), role: "img", "aria-hidden": !0, children: t[n] });
};
function An() {
  return ze(Je);
}
function In({
  children: e,
  open: n = !1,
  title: t = "",
  onOpen: r = () => {
  },
  onClose: o = () => {
  }
}) {
  const { expand: l, items: i, setItems: c, onExpandSection: a } = An(), [s, d] = D(n), [_] = D(je), p = () => {
    const f = !s, g = [...i];
    l ? (g.find((k) => k.id === _).isOpen = f, c(g)) : c(g.map((k) => ({ ...k, isOpen: k.id === _ ? f : !1 })));
  };
  return I(() => {
    c((f) => [...f, { id: _, isOpen: s }]);
  }, []), I(() => {
    d(n);
  }, [n]), I(() => {
    d(i.find((f) => f.id === _)?.isOpen ?? !1);
  }, [i]), I(() => {
    s ? (a?.(t), r()) : o();
  }, [s]), /* @__PURE__ */ u("div", { className: "adv-accordion__item", children: [
    /* @__PURE__ */ u("div", { role: "button", className: "adv-accordion__header", tabIndex: 0, onClick: p, children: [
      /* @__PURE__ */ u(Hn, { name: s ? "chevron-up" : "chevron-down", className: "adv-accordion__toggle" }),
      /* @__PURE__ */ u("div", { className: "adv-accordion__title-wrapper", children: /* @__PURE__ */ u("div", { className: "adv-accordion__title", children: t }) })
    ] }),
    /* @__PURE__ */ u(Pn, { collapsed: !s, children: /* @__PURE__ */ u("div", { className: "adv-accordion__content", children: e }) })
  ] });
}
const en = (e) => {
  if (typeof e != "object" || e === null) return [];
  const n = [];
  "label" in e && typeof e.label == "string" && e.label !== "" && n.push(e.label);
  for (const t in e) {
    const r = e[t];
    (Array.isArray(r) || typeof r == "object" && r !== null) && n.push(...en(r));
  }
  return n;
};
function Un({
  title: e,
  label: n,
  isTopLevel: t,
  contentElements: r
}) {
  const [o, l] = D(!1), { addReference: i } = Qe(), c = J(n);
  return I(() => {
    if (t) {
      const a = en(r).map(J);
      c && a.push(c), a.length && a.forEach((s) => {
        i({ [s]: { openSection: () => l(!0) } });
      });
    }
  }, []), t ? /* @__PURE__ */ u(
    In,
    {
      title: e.content,
      open: o,
      onOpen: () => {
        l(!0);
      },
      onClose: () => {
        l(!1);
      },
      children: /* @__PURE__ */ u("section", { className: "adv-section-box", id: c, children: /* @__PURE__ */ u(C, { contentElements: r }) })
    }
  ) : /* @__PURE__ */ u("section", { id: c, children: [
    /* @__PURE__ */ u(fe, { level: 2, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ u(H, { content: e.content, styles: e.styles }) }),
    /* @__PURE__ */ u(C, { contentElements: r })
  ] });
}
function $n({
  rows: e,
  label: n,
  captions: t,
  titlePrefix: r,
  title: o
}) {
  const l = J(n);
  return /* @__PURE__ */ u("div", { id: l, children: [
    /* @__PURE__ */ u("div", { className: "adv-u-margin-y-8 adv-u-text-align-center", children: [
      r && /* @__PURE__ */ u(H, { ...r }),
      r && o && " ",
      o && /* @__PURE__ */ u(H, { ...o })
    ] }),
    /* @__PURE__ */ u("table", { className: "adv-table adv-table--condensed", children: [
      t && /* @__PURE__ */ u("caption", { children: /* @__PURE__ */ u(C, { contentElements: t }) }),
      /* @__PURE__ */ u("tbody", { className: "adv-table__body", children: e.map((i, c) => /* @__PURE__ */ u("tr", { className: "adv-table__row", children: i.map((a, s) => /* @__PURE__ */ u("td", { className: "adv-table__cell", children: /* @__PURE__ */ u(C, { contentElements: a.elements }) }, s)) }, c)) })
    ] })
  ] });
}
const Dn = ({
  className: e,
  children: n,
  href: t,
  underline: r,
  inheritStyles: o,
  onClick: l
}) => {
  const i = S("adv-link", e, {
    "adv-link--underline": r,
    "adv-link--inherit": o
  });
  return /* @__PURE__ */ u(
    "a",
    {
      href: t,
      className: i,
      target: "_blank",
      rel: "noopener noreferrer",
      onClick: l,
      children: /* @__PURE__ */ u("span", { className: "adv-link__text", children: n })
    }
  );
}, Mn = ({ url: e, displayText: n }) => /* @__PURE__ */ u(Dn, { href: e, children: n ? /* @__PURE__ */ u(H, { ...n }) : e }), Rn = {
  chapter: xn,
  section: Un,
  paragraph: Ln,
  text: H,
  weblink: Mn,
  list: Ze,
  table: $n,
  internalReference: Sn,
  breakline: "br",
  bigskip: kn
}, Wn = (e) => `key-${e}-${je()}`, On = (e, n) => {
  if (!("type" in e)) return null;
  switch (e.type) {
    case x.Chapter:
      return {
        title: e.title,
        contentElements: e.contentElements
      };
    case x.Section:
      return {
        isTopLevel: n,
        title: e.title,
        label: e.label,
        contentElements: e.contentElements
      };
    case x.Paragraph:
      return {
        isTopLevel: n,
        contentElements: e.contentElements
      };
    case x.Text:
      return {
        content: e.content,
        styles: e.styles
      };
    case x.Weblink:
      return {
        url: e.url,
        displayText: e.displayText
      };
    case x.List:
      return {
        items: e.items,
        style: e.style
      };
    case x.Table:
      return {
        rows: e.rows,
        label: e.label,
        captions: e.captions,
        titlePrefix: e.titlePrefix,
        title: e.title
      };
    case x.InternalReference:
      return {
        referencedLabel: e.referencedLabel,
        displayText: e.displayText
      };
    case x.Bigskip:
      return {};
    default:
      return null;
  }
};
function C({
  contentElements: e,
  isTopLevel: n = !1,
  onExpandSection: t,
  multiple: r
}) {
  const o = e.map((l) => {
    if (!("type" in l)) return null;
    const i = Rn[l.type];
    return /* @__PURE__ */ u(i, { ...On(l, n) }, Wn(l.type));
  });
  return n ? /* @__PURE__ */ u(wn, { onExpandSection: t, expand: r, children: o }) : /* @__PURE__ */ u("span", { children: o });
}
function Fn({ children: e }) {
  const [n, t] = D({}), r = Ve(
    () => ({
      addReference: (o) => {
        t((l) => ({
          ...l,
          ...o
        }));
      },
      references: n
    }),
    [n, t]
  );
  return /* @__PURE__ */ u(Ke.Provider, { value: r, children: e });
}
function Bn({
  document: e,
  className: n,
  onExpandSection: t,
  multiple: r
}) {
  const o = S("adyen-document-viewer", n);
  return /* @__PURE__ */ u(Fn, { children: /* @__PURE__ */ u("div", { className: o, children: [
    /* @__PURE__ */ u(fe, { level: 1, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ u(H, { content: e.title.content, styles: e.title.styles }) }),
    /* @__PURE__ */ u(
      C,
      {
        contentElements: e.contentElements,
        onExpandSection: t,
        multiple: r,
        isTopLevel: !0
      }
    )
  ] }) });
}
function jn(e) {
  return "type" in e && e.type === x.Chapter;
}
function qn(e) {
  return "type" in e && e.type === x.Section;
}
function Vn(e) {
  return "contentElements" in e && Array.isArray(e.contentElements);
}
function zn(e) {
  return e.isTopLevel ? `${e.counter}` : `${e.prefix}${e.counter}`;
}
function Yn(e, n) {
  return `${e} ${n}`;
}
function z(e, n) {
  if (jn(e)) {
    const t = { prefix: "", counter: 1, isTopLevel: !0 };
    return {
      ...e,
      contentElements: e.contentElements.map(
        (r) => z(r, t)
      )
    };
  } else if (qn(e)) {
    const t = zn(n), r = {
      ...e,
      title: {
        ...e.title,
        content: Yn(t, e.title.content)
      }
    };
    n.counter += 1;
    const o = {
      prefix: `${t}.`,
      counter: 1,
      isTopLevel: !1
    };
    return r.contentElements = e.contentElements.map(
      (l) => z(l, o)
    ), r;
  } else if (Vn(e))
    return {
      ...e,
      contentElements: e.contentElements.map(
        (t) => z(t, n)
      )
    };
  return e;
}
function Gn(e) {
  const n = { prefix: "", counter: 1, isTopLevel: !0 };
  return {
    ...e,
    contentElements: e.contentElements.map(
      (t) => z(t, n)
    )
  };
}
class Jn {
  /**
   * Initializes the library
   * @param target - The target element (HTMLElement or querySelector string)
   * @param options - Configuration options for AdyenDocumentViewer
   */
  constructor(n, t = {}) {
    if (typeof n == "object" && "nodeType" in n)
      this.target = n;
    else {
      const r = window.document.querySelector(n);
      if (r instanceof HTMLElement)
        this.target = r;
      else
        throw new Error("Target element was not found");
    }
    this.options = {
      onExpandSection: t.onExpandSection ?? void 0,
      multiple: t.multiple ?? !1,
      showSectionNumbering: t.showSectionNumbering ?? !1
    };
  }
  /**
   * Renders the document
   * @param document - The JSON document
   */
  render(n) {
    const t = this.options.showSectionNumbering ? Gn(n) : n;
    fn(
      /* @__PURE__ */ u(
        Bn,
        {
          document: t,
          onExpandSection: this.options.onExpandSection,
          multiple: this.options.multiple
        }
      ),
      this.target
    );
  }
}
function Zn({
  contract: e,
  className: n,
  onExpandSection: t,
  showSectionNumbering: r
}) {
  const o = tn("adyen-contract-viewer", n), l = rn(null), [i, c] = ln(null);
  return on(() => {
    l.current && !i && c(
      new Jn(l.current, { onExpandSection: t, showSectionNumbering: r })
    ), i && i.render(e);
  }, [e, i, t, r]), /* @__PURE__ */ nn("div", { ref: l, className: o });
}
export {
  Zn as C
};
