;
{
  try {
    let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? 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 (e) {
  }
}
;
import { jsx } from "preact/jsx-runtime";
import cx from "classnames";
import { useRef, useState, useEffect } from "preact/hooks";
var Q, h, Pe, L, he, Le, He, Te, le, re, oe, Ie, O = {}, Ae = [], tt = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, J = Array.isArray;
function C(e, t) {
  for (var n in t) e[n] = t[n];
  return e;
}
function ae(e) {
  e && e.parentNode && e.parentNode.removeChild(e);
}
function Re(e, t, n) {
  var r, _, o, s = {};
  for (o in t) o == "key" ? r = t[o] : o == "ref" ? _ = t[o] : s[o] = t[o];
  if (arguments.length > 2 && (s.children = arguments.length > 3 ? Q.call(arguments, 2) : n), typeof e == "function" && e.defaultProps != null) for (o in e.defaultProps) s[o] === void 0 && (s[o] = e.defaultProps[o]);
  return q(e, s, r, _, null);
}
function q(e, t, n, r, _) {
  var o = { type: e, props: t, key: n, ref: r, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: _ ?? ++Pe, __i: -1, __u: 0 };
  return _ == null && h.vnode != null && h.vnode(o), o;
}
function X(e) {
  return e.children;
}
function V(e, t) {
  this.props = e, this.context = t;
}
function A(e, t) {
  if (t == null) return e.__ ? A(e.__, e.__i + 1) : null;
  for (var n; t < e.__k.length; t++) if ((n = e.__k[t]) != null && n.__e != null) return n.__e;
  return typeof e.type == "function" ? A(e) : null;
}
function Ue(e) {
  var t, n;
  if ((e = e.__) != null && e.__c != null) {
    for (e.__e = e.__c.base = null, t = 0; t < e.__k.length; t++) if ((n = e.__k[t]) != null && n.__e != null) {
      e.__e = e.__c.base = n.__e;
      break;
    }
    return Ue(e);
  }
}
function _e(e) {
  (!e.__d && (e.__d = true) && L.push(e) && !Y.__r++ || he != h.debounceRendering) && ((he = h.debounceRendering) || Le)(Y);
}
function Y() {
  for (var e, t, n, r, _, o, s, c = 1; L.length; ) L.length > c && L.sort(He), e = L.shift(), c = L.length, e.__d && (n = void 0, r = void 0, _ = (r = (t = e).__v).__e, o = [], s = [], t.__P && ((n = C({}, r)).__v = r.__v + 1, h.vnode && h.vnode(n), ue(t.__P, n, r, t.__n, t.__P.namespaceURI, 32 & r.__u ? [_] : null, o, _ ?? A(r), !!(32 & r.__u), s), n.__v = r.__v, n.__.__k[n.__i] = n, Oe(o, n, s), r.__e = r.__ = null, n.__e != _ && Ue(n)));
  Y.__r = 0;
}
function De(e, t, n, r, _, o, s, c, u, l, d) {
  var i, p, f, g, k, w, m, v = r && r.__k || Ae, $ = t.length;
  for (u = nt(n, t, v, u, $), i = 0; i < $; i++) (f = n.__k[i]) != null && (p = f.__i == -1 ? O : v[f.__i] || O, f.__i = i, w = ue(e, f, p, _, o, s, c, u, l, d), g = f.__e, f.ref && p.ref != f.ref && (p.ref && fe(p.ref, null, f), d.push(f.ref, f.__c || g, f)), k == null && g != null && (k = g), (m = !!(4 & f.__u)) || p.__k === f.__k ? u = Me(f, u, e, m) : typeof f.type == "function" && w !== void 0 ? u = w : g && (u = g.nextSibling), f.__u &= -7);
  return n.__e = k, u;
}
function nt(e, t, n, r, _) {
  var o, s, c, u, l, d = n.length, i = d, p = 0;
  for (e.__k = new Array(_), o = 0; o < _; o++) (s = t[o]) != null && typeof s != "boolean" && typeof s != "function" ? (typeof s == "string" || typeof s == "number" || typeof s == "bigint" || s.constructor == String ? s = e.__k[o] = q(null, s, null, null, null) : J(s) ? s = e.__k[o] = q(X, { children: s }, null, null, null) : s.constructor == null && s.__b > 0 ? s = e.__k[o] = q(s.type, s.props, s.key, s.ref ? s.ref : null, s.__v) : e.__k[o] = s, u = o + p, s.__ = e, s.__b = e.__b + 1, (l = s.__i = rt(s, n, u, i)) != -1 && (i--, (c = n[l]) && (c.__u |= 2)), c == null || c.__v == null ? (l == -1 && (_ > d ? p-- : _ < d && p++), typeof s.type != "function" && (s.__u |= 4)) : l != u && (l == u - 1 ? p-- : l == u + 1 ? p++ : (l > u ? p-- : p++, s.__u |= 4))) : e.__k[o] = null;
  if (i) for (o = 0; o < d; o++) (c = n[o]) != null && (2 & c.__u) == 0 && (c.__e == r && (r = A(c)), Be(c, c));
  return r;
}
function Me(e, t, n, r) {
  var _, o;
  if (typeof e.type == "function") {
    for (_ = e.__k, o = 0; _ && o < _.length; o++) _[o] && (_[o].__ = e, t = Me(_[o], t, n, r));
    return t;
  }
  e.__e != t && (r && (t && e.type && !t.parentNode && (t = A(e)), n.insertBefore(e.__e, t || null)), t = e.__e);
  do
    t = t && t.nextSibling;
  while (t != null && t.nodeType == 8);
  return t;
}
function rt(e, t, n, r) {
  var _, o, s, c = e.key, u = e.type, l = t[n], d = l != null && (2 & l.__u) == 0;
  if (l === null && c == null || d && c == l.key && u == l.type) return n;
  if (r > (d ? 1 : 0)) {
    for (_ = n - 1, o = n + 1; _ >= 0 || o < t.length; ) if ((l = t[s = _ >= 0 ? _-- : o++]) != null && (2 & l.__u) == 0 && c == l.key && u == l.type) return s;
  }
  return -1;
}
function ve(e, t, n) {
  t[0] == "-" ? e.setProperty(t, n ?? "") : e[t] = n == null ? "" : typeof n != "number" || tt.test(t) ? n : n + "px";
}
function F(e, t, n, r, _) {
  var o, s;
  e: if (t == "style") if (typeof n == "string") e.style.cssText = n;
  else {
    if (typeof r == "string" && (e.style.cssText = r = ""), r) for (t in r) n && t in n || ve(e.style, t, "");
    if (n) for (t in n) r && n[t] == r[t] || ve(e.style, t, n[t]);
  }
  else if (t[0] == "o" && t[1] == "n") o = t != (t = t.replace(Te, "$1")), s = t.toLowerCase(), t = s in e || t == "onFocusOut" || t == "onFocusIn" ? s.slice(2) : t.slice(2), e.l || (e.l = {}), e.l[t + o] = n, n ? r ? n.u = r.u : (n.u = le, e.addEventListener(t, o ? oe : re, o)) : e.removeEventListener(t, o ? oe : re, o);
  else {
    if (_ == "http://www.w3.org/2000/svg") t = t.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
    else if (t != "width" && t != "height" && t != "href" && t != "list" && t != "form" && t != "tabIndex" && t != "download" && t != "rowSpan" && t != "colSpan" && t != "role" && t != "popover" && t in e) try {
      e[t] = n ?? "";
      break e;
    } catch {
    }
    typeof n == "function" || (n == null || n === false && t[4] != "-" ? e.removeAttribute(t) : e.setAttribute(t, t == "popover" && n == 1 ? "" : n));
  }
}
function me(e) {
  return function(t) {
    if (this.l) {
      var n = this.l[t.type + e];
      if (t.t == null) t.t = le++;
      else if (t.t < n.u) return;
      return n(h.event ? h.event(t) : t);
    }
  };
}
function ue(e, t, n, r, _, o, s, c, u, l) {
  var d, i, p, f, g, k, w, m, v, $, P, W, D, pe, B, M, ee, x = t.type;
  if (t.constructor != null) return null;
  128 & n.__u && (u = !!(32 & n.__u), o = [c = t.__e = n.__e]), (d = h.__b) && d(t);
  e: if (typeof x == "function") try {
    if (m = t.props, v = "prototype" in x && x.prototype.render, $ = (d = x.contextType) && r[d.__c], P = d ? $ ? $.props.value : d.__ : r, n.__c ? w = (i = t.__c = n.__c).__ = i.__E : (v ? t.__c = i = new x(m, P) : (t.__c = i = new V(m, P), i.constructor = x, i.render = _t), $ && $.sub(i), i.state || (i.state = {}), i.__n = r, p = i.__d = true, i.__h = [], i._sb = []), v && i.__s == null && (i.__s = i.state), v && x.getDerivedStateFromProps != null && (i.__s == i.state && (i.__s = C({}, i.__s)), C(i.__s, x.getDerivedStateFromProps(m, i.__s))), f = i.props, g = i.state, i.__v = t, p) v && x.getDerivedStateFromProps == null && i.componentWillMount != null && i.componentWillMount(), v && i.componentDidMount != null && i.__h.push(i.componentDidMount);
    else {
      if (v && x.getDerivedStateFromProps == null && m !== f && i.componentWillReceiveProps != null && i.componentWillReceiveProps(m, P), t.__v == n.__v || !i.__e && i.shouldComponentUpdate != null && i.shouldComponentUpdate(m, i.__s, P) === false) {
        for (t.__v != n.__v && (i.props = m, i.state = i.__s, i.__d = false), t.__e = n.__e, t.__k = n.__k, t.__k.some(function(T) {
          T && (T.__ = t);
        }), W = 0; W < i._sb.length; W++) i.__h.push(i._sb[W]);
        i._sb = [], i.__h.length && s.push(i);
        break e;
      }
      i.componentWillUpdate != null && i.componentWillUpdate(m, i.__s, P), v && i.componentDidUpdate != null && i.__h.push(function() {
        i.componentDidUpdate(f, g, k);
      });
    }
    if (i.context = P, i.props = m, i.__P = e, i.__e = false, D = h.__r, pe = 0, v) {
      for (i.state = i.__s, i.__d = false, D && D(t), d = i.render(i.props, i.state, i.context), B = 0; B < i._sb.length; B++) i.__h.push(i._sb[B]);
      i._sb = [];
    } else do
      i.__d = false, D && D(t), d = i.render(i.props, i.state, i.context), i.state = i.__s;
    while (i.__d && ++pe < 25);
    i.state = i.__s, i.getChildContext != null && (r = C(C({}, r), i.getChildContext())), v && !p && i.getSnapshotBeforeUpdate != null && (k = i.getSnapshotBeforeUpdate(f, g)), M = d, d != null && d.type === X && d.key == null && (M = We(d.props.children)), c = De(e, J(M) ? M : [M], t, n, r, _, o, s, c, u, l), i.base = t.__e, t.__u &= -161, i.__h.length && s.push(i), w && (i.__E = i.__ = null);
  } catch (T) {
    if (t.__v = null, u || o != null) if (T.then) {
      for (t.__u |= u ? 160 : 128; c && c.nodeType == 8 && c.nextSibling; ) c = c.nextSibling;
      o[o.indexOf(c)] = null, t.__e = c;
    } else {
      for (ee = o.length; ee--; ) ae(o[ee]);
      ie(t);
    }
    else t.__e = n.__e, t.__k = n.__k, T.then || ie(t);
    h.__e(T, t, n);
  }
  else o == null && t.__v == n.__v ? (t.__k = n.__k, t.__e = n.__e) : c = t.__e = ot(n.__e, t, n, r, _, o, s, u, l);
  return (d = h.diffed) && d(t), 128 & t.__u ? void 0 : c;
}
function ie(e) {
  e && e.__c && (e.__c.__e = true), e && e.__k && e.__k.forEach(ie);
}
function Oe(e, t, n) {
  for (var r = 0; r < n.length; r++) fe(n[r], n[++r], n[++r]);
  h.__c && h.__c(t, e), e.some(function(_) {
    try {
      e = _.__h, _.__h = [], e.some(function(o) {
        o.call(_);
      });
    } catch (o) {
      h.__e(o, _.__v);
    }
  });
}
function We(e) {
  return typeof e != "object" || e == null || e.__b && e.__b > 0 ? e : J(e) ? e.map(We) : C({}, e);
}
function ot(e, t, n, r, _, o, s, c, u) {
  var l, d, i, p, f, g, k, w = n.props || O, m = t.props, v = t.type;
  if (v == "svg" ? _ = "http://www.w3.org/2000/svg" : v == "math" ? _ = "http://www.w3.org/1998/Math/MathML" : _ || (_ = "http://www.w3.org/1999/xhtml"), o != null) {
    for (l = 0; l < o.length; l++) if ((f = o[l]) && "setAttribute" in f == !!v && (v ? f.localName == v : f.nodeType == 3)) {
      e = f, o[l] = null;
      break;
    }
  }
  if (e == null) {
    if (v == null) return document.createTextNode(m);
    e = document.createElementNS(_, v, m.is && m), c && (h.__m && h.__m(t, o), c = false), o = null;
  }
  if (v == null) w === m || c && e.data == m || (e.data = m);
  else {
    if (o = o && Q.call(e.childNodes), !c && o != null) for (w = {}, l = 0; l < e.attributes.length; l++) w[(f = e.attributes[l]).name] = f.value;
    for (l in w) if (f = w[l], l != "children") {
      if (l == "dangerouslySetInnerHTML") i = f;
      else if (!(l in m)) {
        if (l == "value" && "defaultValue" in m || l == "checked" && "defaultChecked" in m) continue;
        F(e, l, null, f, _);
      }
    }
    for (l in m) f = m[l], l == "children" ? p = f : l == "dangerouslySetInnerHTML" ? d = f : l == "value" ? g = f : l == "checked" ? k = f : c && typeof f != "function" || w[l] === f || F(e, l, f, w[l], _);
    if (d) c || i && (d.__html == i.__html || d.__html == e.innerHTML) || (e.innerHTML = d.__html), t.__k = [];
    else if (i && (e.innerHTML = ""), De(t.type == "template" ? e.content : e, J(p) ? p : [p], t, n, r, v == "foreignObject" ? "http://www.w3.org/1999/xhtml" : _, o, s, o ? o[0] : n.__k && A(n, 0), c, u), o != null) for (l = o.length; l--; ) ae(o[l]);
    c || (l = "value", v == "progress" && g == null ? e.removeAttribute("value") : g != null && (g !== e[l] || v == "progress" && !g || v == "option" && g != w[l]) && F(e, l, g, w[l], _), l = "checked", k != null && k != e[l] && F(e, l, k, w[l], _));
  }
  return e;
}
function fe(e, t, n) {
  try {
    if (typeof e == "function") {
      var r = typeof e.__u == "function";
      r && e.__u(), r && t == null || (e.__u = e(t));
    } else e.current = t;
  } catch (_) {
    h.__e(_, n);
  }
}
function Be(e, t, n) {
  var r, _;
  if (h.unmount && h.unmount(e), (r = e.ref) && (r.current && r.current != e.__e || fe(r, null, t)), (r = e.__c) != null) {
    if (r.componentWillUnmount) try {
      r.componentWillUnmount();
    } catch (o) {
      h.__e(o, t);
    }
    r.base = r.__P = null;
  }
  if (r = e.__k) for (_ = 0; _ < r.length; _++) r[_] && Be(r[_], t, n || typeof e.type != "function");
  n || ae(e.__e), e.__c = e.__ = e.__e = void 0;
}
function _t(e, t, n) {
  return this.constructor(e, n);
}
function it(e, t, n) {
  var r, _, o, s;
  t == document && (t = document.documentElement), h.__ && h.__(e, t), _ = (r = false) ? null : t.__k, o = [], s = [], ue(t, e = t.__k = Re(X, null, [e]), _ || O, O, t.namespaceURI, _ ? null : t.firstChild ? Q.call(t.childNodes) : null, o, _ ? _.__e : t.firstChild, r, s), Oe(o, e, s);
}
function Fe(e) {
  function t(n) {
    var r, _;
    return this.getChildContext || (r = /* @__PURE__ */ new Set(), (_ = {})[t.__c] = this, this.getChildContext = function() {
      return _;
    }, this.componentWillUnmount = function() {
      r = null;
    }, this.shouldComponentUpdate = function(o) {
      this.props.value != o.value && r.forEach(function(s) {
        s.__e = true, _e(s);
      });
    }, this.sub = function(o) {
      r.add(o);
      var s = o.componentWillUnmount;
      o.componentWillUnmount = function() {
        r && r.delete(o), s && s.call(o);
      };
    }), n.children;
  }
  return t.__c = "__cC" + Ie++, t.__ = e, t.Provider = t.__l = (t.Consumer = function(n, r) {
    return n.children(r);
  }).contextType = t, t;
}
Q = Ae.slice, h = { __e: function(e, t, n, r) {
  for (var _, o, s; t = t.__; ) if ((_ = t.__c) && !_.__) try {
    if ((o = _.constructor) && o.getDerivedStateFromError != null && (_.setState(o.getDerivedStateFromError(e)), s = _.__d), _.componentDidCatch != null && (_.componentDidCatch(e, r || {}), s = _.__d), s) return _.__E = _;
  } catch (c) {
    e = c;
  }
  throw e;
} }, Pe = 0, V.prototype.setState = function(e, t) {
  var n;
  n = this.__s != null && this.__s != this.state ? this.__s : this.__s = C({}, this.state), typeof e == "function" && (e = e(C({}, n), this.props)), e && C(n, e), e != null && this.__v && (t && this._sb.push(t), _e(this));
}, V.prototype.forceUpdate = function(e) {
  this.__v && (this.__e = true, e && this.__h.push(e), _e(this));
}, V.prototype.render = X, L = [], Le = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, He = function(e, t) {
  return e.__v.__b - t.__v.__b;
}, Y.__r = 0, Te = /(PointerCapture)$|Capture$/i, le = 0, re = me(false), oe = me(true), Ie = 0;
var st = 0;
function a(e, t, n, r, _, o) {
  t || (t = {});
  var s, c, u = t;
  if ("ref" in u) for (c in u = {}, t) c == "ref" ? s = t[c] : u[c] = t[c];
  var l = { type: e, props: u, key: n, ref: s, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --st, __i: -1, __u: 0, __source: _, __self: o };
  if (typeof e == "function" && (s = e.defaultProps)) for (c in s) u[c] === void 0 && (u[c] = s[c]);
  return h.vnode && h.vnode(l), l;
}
function ct(e) {
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
var te = { exports: {} };
var ye;
function lt() {
  return ye || (ye = 1, (function(e) {
    (function() {
      var t = {}.hasOwnProperty;
      function n() {
        for (var o = "", s = 0; s < arguments.length; s++) {
          var c = arguments[s];
          c && (o = _(o, r(c)));
        }
        return o;
      }
      function r(o) {
        if (typeof o == "string" || typeof o == "number")
          return o;
        if (typeof o != "object")
          return "";
        if (Array.isArray(o))
          return n.apply(null, o);
        if (o.toString !== Object.prototype.toString && !o.toString.toString().includes("[native code]"))
          return o.toString();
        var s = "";
        for (var c in o)
          t.call(o, c) && o[c] && (s = _(s, c));
        return s;
      }
      function _(o, s) {
        return s ? o ? o + " " + s : o + s : o;
      }
      e.exports ? (n.default = n, e.exports = n) : window.classNames = n;
    })();
  })(te)), te.exports;
}
var at = lt();
const S = /* @__PURE__ */ ct(at);
var N = /* @__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))(N || {}), se = /* @__PURE__ */ ((e) => (e.Bold = "BOLD", e.Italic = "ITALIC", e))(se || {});
let ge = Date.now();
const qe = (e = "id") => (ge += 1, `${e}-${ge}`);
var R, y, ne, be, G = 0, Ve = [], b = h, we = b.__b, ke = b.__r, Ne = b.diffed, xe = b.__c, Ce = b.unmount, Se = b.__;
function Z(e, t) {
  b.__h && b.__h(y, e, G || t), G = 0;
  var n = y.__H || (y.__H = { __: [], __h: [] });
  return e >= n.__.length && n.__.push({}), n.__[e];
}
function U(e) {
  return G = 1, ut(Ge, e);
}
function ut(e, t, n) {
  var r = Z(R++, 2);
  if (r.t = e, !r.__c && (r.__ = [Ge(void 0, t), function(c) {
    var u = r.__N ? r.__N[0] : r.__[0], l = r.t(u, c);
    u !== l && (r.__N = [l, r.__[1]], r.__c.setState({}));
  }], r.__c = y, !y.__f)) {
    var _ = function(c, u, l) {
      if (!r.__c.__H) return true;
      var d = r.__c.__H.__.filter(function(p) {
        return !!p.__c;
      });
      if (d.every(function(p) {
        return !p.__N;
      })) return !o || o.call(this, c, u, l);
      var i = 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] && (i = true);
        }
      }), o && o.call(this, c, u, l) || i;
    };
    y.__f = true;
    var o = y.shouldComponentUpdate, s = y.componentWillUpdate;
    y.componentWillUpdate = function(c, u, l) {
      if (this.__e) {
        var d = o;
        o = void 0, _(c, u, l), o = d;
      }
      s && s.call(this, c, u, l);
    }, y.shouldComponentUpdate = _;
  }
  return r.__N || r.__;
}
function I(e, t) {
  var n = Z(R++, 3);
  !b.__s && Ye(n.__H, t) && (n.__ = e, n.u = t, y.__H.__h.push(n));
}
function ft(e) {
  return G = 5, je(function() {
    return { current: e };
  }, []);
}
function je(e, t) {
  var n = Z(R++, 7);
  return Ye(n.__H, t) && (n.__ = e(), n.__H = t, n.__h = e), n.__;
}
function ze(e) {
  var t = y.context[e.__c], n = Z(R++, 9);
  return n.c = e, t ? (n.__ == null && (n.__ = true, t.sub(y)), t.props.value) : e.__;
}
function dt() {
  for (var e; e = Ve.shift(); ) if (e.__P && e.__H) try {
    e.__H.__h.forEach(j), e.__H.__h.forEach(ce), e.__H.__h = [];
  } catch (t) {
    e.__H.__h = [], b.__e(t, e.__v);
  }
}
b.__b = function(e) {
  y = null, we && we(e);
}, b.__ = function(e, t) {
  e && t.__k && t.__k.__m && (e.__m = t.__k.__m), Se && Se(e, t);
}, b.__r = function(e) {
  ke && ke(e), R = 0;
  var t = (y = e.__c).__H;
  t && (ne === y ? (t.__h = [], y.__h = [], t.__.forEach(function(n) {
    n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
  })) : (t.__h.forEach(j), t.__h.forEach(ce), t.__h = [], R = 0)), ne = y;
}, b.diffed = function(e) {
  Ne && Ne(e);
  var t = e.__c;
  t && t.__H && (t.__H.__h.length && (Ve.push(t) !== 1 && be === b.requestAnimationFrame || ((be = b.requestAnimationFrame) || pt)(dt)), t.__H.__.forEach(function(n) {
    n.u && (n.__H = n.u), n.u = void 0;
  })), ne = y = null;
}, b.__c = function(e, t) {
  t.some(function(n) {
    try {
      n.__h.forEach(j), n.__h = n.__h.filter(function(r) {
        return !r.__ || ce(r);
      });
    } catch (r) {
      t.some(function(_) {
        _.__h && (_.__h = []);
      }), t = [], b.__e(r, n.__v);
    }
  }), xe && xe(e, t);
}, b.unmount = function(e) {
  Ce && Ce(e);
  var t, n = e.__c;
  n && n.__H && (n.__H.__.forEach(function(r) {
    try {
      j(r);
    } catch (_) {
      t = _;
    }
  }), n.__H = void 0, t && b.__e(t, n.__v));
};
var $e = typeof requestAnimationFrame == "function";
function pt(e) {
  var t, n = function() {
    clearTimeout(r), $e && cancelAnimationFrame(t), setTimeout(e);
  }, r = setTimeout(n, 35);
  $e && (t = requestAnimationFrame(n));
}
function j(e) {
  var t = y, n = e.__c;
  typeof n == "function" && (e.__c = void 0, n()), y = t;
}
function ce(e) {
  var t = y;
  e.__c = e.__(), y = t;
}
function Ye(e, t) {
  return !e || e.length !== t.length || t.some(function(n, r) {
    return n !== e[r];
  });
}
function Ge(e, t) {
  return typeof t == "function" ? t(e) : t;
}
const Ke = Fe(null);
function ht({
  children: e,
  className: t,
  expand: n = false,
  type: r,
  onExpandSection: _
}) {
  const [o, s] = U([]), c = S("adv-accordion", t, {
    "adv-accordion--container": r === "container"
  });
  return /* @__PURE__ */ a(Ke.Provider, { value: { expand: n, items: o, setItems: s, onExpandSection: _ }, children: /* @__PURE__ */ a("div", { className: c, children: e }) });
}
function vt() {
  return /* @__PURE__ */ a("div", { className: "adv-bigskip" });
}
const Ee = {
  1: "h1",
  2: "h2"
};
function de({ className: e, level: t, children: n }) {
  const r = Ee[t] || Ee[1], _ = S("adv-heading", `adv-heading--${t}`, e);
  return Re(r, { className: _ }, n);
}
function H({ content: e, styles: t }) {
  const n = S({
    "adv-u-font-weight-semi-bold": t?.includes(se.Bold),
    "adv-u-font-italic": t?.includes(se.Italic)
  });
  return /* @__PURE__ */ a("span", { className: n, children: e });
}
function mt({ title: e, contentElements: t }) {
  return /* @__PURE__ */ a("section", { className: "adv-u-margin-bottom-48", children: [
    /* @__PURE__ */ a(de, { level: 2, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ a(H, { content: e.content, styles: e.styles }) }),
    /* @__PURE__ */ a(E, { contentElements: t, isTopLevel: true })
  ] });
}
const Qe = Fe({
  references: {},
  addReference: () => {
  }
});
function Je() {
  const e = ze(Qe);
  if (e === void 0)
    throw new Error("useReferenceContext must be used within a ReferenceProvider");
  return e;
}
const yt = (e) => new Promise((t) => {
  setTimeout(t, e);
}), K = (e) => e ? `adyen-document-viewer-${e.replace(/[^\w-]/g, "").slice(0, 32)}` : void 0, Xe = (e) => {
  if (!e) return null;
  const t = e instanceof HTMLElement, n = t && window.getComputedStyle(e).overflowY;
  return t && (n !== "visible" && n !== "hidden") ? e : Xe(e.parentNode) ?? document.body;
}, gt = ({ onClick: e, label: t }) => /* @__PURE__ */ a("button", { className: "adv-link", type: "button", onClick: e, title: t, children: t });
function bt({
  referencedLabel: e,
  displayText: t
}) {
  const n = t ? t.content : e, r = K(e) ?? "", { references: _ } = Je();
  return /* @__PURE__ */ a(gt, { onClick: async () => {
    _ && r && _[r] && (_[r].openSection(), await yt(150)), Xe(document.getElementById(r))?.querySelector(`#${r}`)?.scrollIntoView({ behavior: "smooth" });
  }, label: n });
}
function wt({ className: e, nested: t, ordered: n, noMarkers: r, children: _ }) {
  const o = S([
    "adv-list",
    t && "adv-list--nested",
    n && "adv-list--ordered",
    r && "adv-list--no-markers",
    e
  ]);
  return /* @__PURE__ */ a("ul", { className: o, children: _ });
}
function kt({ className: e, children: t, noMarkers: n }) {
  const r = S(["adv-list__item", n && "adv-list__item--no-markers", e]);
  return /* @__PURE__ */ a("li", { className: r, children: t });
}
function Ze({ items: e, style: t }) {
  return /* @__PURE__ */ a(wt, { ordered: t.ordered, children: e.map((n, r) => /* @__PURE__ */ a(kt, { children: [
    /* @__PURE__ */ a(E, { contentElements: n.content }),
    n.subList && /* @__PURE__ */ a(Ze, { style: n.subList.style, items: n.subList.items })
  ] }, r)) });
}
function Nt({ isTopLevel: e, contentElements: t }) {
  const n = S("adv-paragraph", {
    "adv-u-margin-bottom-16": e
  });
  return /* @__PURE__ */ a("p", { className: n, children: /* @__PURE__ */ a(E, { contentElements: t }) });
}
function xt({
  children: e,
  collapsed: t = false
}) {
  const n = ft(null), [r, _] = U(t ? 0 : void 0);
  return I(() => {
    _(t ? 0 : n.current?.scrollHeight);
  }, [t]), /* @__PURE__ */ a(
    "div",
    {
      className: "adv-collapsible-container",
      "aria-hidden": t,
      ref: n,
      style: { height: r },
      children: e
    }
  );
}
const Ct = ({ className: e = "", name: t }) => {
  const n = {
    "chevron-up": /* @__PURE__ */ a("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 15 15", width: "15", height: "15", children: /* @__PURE__ */ a(
      "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__ */ a("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 15 15", width: "15", height: "15", children: /* @__PURE__ */ a(
      "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__ */ a("i", { className: S("adv-icon", e), role: "img", "aria-hidden": true, children: n[t] });
};
function St() {
  return ze(Ke);
}
function $t({
  children: e,
  open: t = false,
  title: n = "",
  onOpen: r = () => {
  },
  onClose: _ = () => {
  }
}) {
  const { expand: o, items: s, setItems: c, onExpandSection: u } = St(), [l, d] = U(t), [i] = U(qe), p = () => {
    const f = !l, g = [...s];
    o ? (g.find((k) => k.id === i).isOpen = f, c(g)) : c(g.map((k) => ({ ...k, isOpen: k.id === i ? f : false })));
  };
  return I(() => {
    c((f) => [...f, { id: i, isOpen: l }]);
  }, []), I(() => {
    d(t);
  }, [t]), I(() => {
    d(s.find((f) => f.id === i)?.isOpen ?? false);
  }, [s]), I(() => {
    l ? (u?.(n), r()) : _();
  }, [l]), /* @__PURE__ */ a("div", { className: "adv-accordion__item", children: [
    /* @__PURE__ */ a("div", { role: "button", className: "adv-accordion__header", tabIndex: 0, onClick: p, children: [
      /* @__PURE__ */ a(Ct, { name: l ? "chevron-up" : "chevron-down", className: "adv-accordion__toggle" }),
      /* @__PURE__ */ a("div", { className: "adv-accordion__title-wrapper", children: /* @__PURE__ */ a("div", { className: "adv-accordion__title", children: n }) })
    ] }),
    /* @__PURE__ */ a(xt, { collapsed: !l, children: /* @__PURE__ */ a("div", { className: "adv-accordion__content", children: e }) })
  ] });
}
const et = (e) => {
  if (typeof e != "object" || e === null) return [];
  const t = [];
  "label" in e && typeof e.label == "string" && e.label !== "" && t.push(e.label);
  for (const n in e) {
    const r = e[n];
    (Array.isArray(r) || typeof r == "object" && r !== null) && t.push(...et(r));
  }
  return t;
};
function Et({
  title: e,
  label: t,
  isTopLevel: n,
  contentElements: r
}) {
  const [_, o] = U(false), { addReference: s } = Je(), c = K(t);
  return I(() => {
    if (n) {
      const u = et(r).map(K);
      c && u.push(c), u.length && u.forEach((l) => {
        s({ [l]: { openSection: () => o(true) } });
      });
    }
  }, []), n ? /* @__PURE__ */ a(
    $t,
    {
      title: e.content,
      open: _,
      onOpen: () => {
        o(true);
      },
      onClose: () => {
        o(false);
      },
      children: /* @__PURE__ */ a("section", { className: "adv-section-box", id: c, children: /* @__PURE__ */ a(E, { contentElements: r }) })
    }
  ) : /* @__PURE__ */ a("section", { id: c, children: [
    /* @__PURE__ */ a(de, { level: 2, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ a(H, { content: e.content, styles: e.styles }) }),
    /* @__PURE__ */ a(E, { contentElements: r })
  ] });
}
function Pt({
  rows: e,
  label: t,
  captions: n,
  titlePrefix: r,
  title: _
}) {
  const o = K(t);
  return /* @__PURE__ */ a("div", { id: o, children: [
    /* @__PURE__ */ a("div", { className: "adv-u-margin-y-8 adv-u-text-align-center", children: [
      r && /* @__PURE__ */ a(H, { ...r }),
      r && _ && " ",
      _ && /* @__PURE__ */ a(H, { ..._ })
    ] }),
    /* @__PURE__ */ a("table", { className: "adv-table adv-table--condensed", children: [
      n && /* @__PURE__ */ a("caption", { children: /* @__PURE__ */ a(E, { contentElements: n }) }),
      /* @__PURE__ */ a("tbody", { className: "adv-table__body", children: e.map((s, c) => /* @__PURE__ */ a("tr", { className: "adv-table__row", children: s.map((u, l) => /* @__PURE__ */ a("td", { className: "adv-table__cell", children: /* @__PURE__ */ a(E, { contentElements: u.elements }) }, l)) }, c)) })
    ] })
  ] });
}
const Lt = ({
  className: e,
  children: t,
  href: n,
  underline: r,
  inheritStyles: _,
  onClick: o
}) => {
  const s = S("adv-link", e, {
    "adv-link--underline": r,
    "adv-link--inherit": _
  });
  return /* @__PURE__ */ a(
    "a",
    {
      href: n,
      className: s,
      target: "_blank",
      rel: "noopener noreferrer",
      onClick: o,
      children: /* @__PURE__ */ a("span", { className: "adv-link__text", children: t })
    }
  );
}, Ht = ({ url: e, displayText: t }) => /* @__PURE__ */ a(Lt, { href: e, children: t ? /* @__PURE__ */ a(H, { ...t }) : e }), Tt = {
  chapter: mt,
  section: Et,
  paragraph: Nt,
  text: H,
  weblink: Ht,
  list: Ze,
  table: Pt,
  internalReference: bt,
  breakline: "br",
  bigskip: vt
}, It = (e) => `key-${e}-${qe()}`, At = (e, t) => {
  if (!("type" in e)) return null;
  switch (e.type) {
    case N.Chapter:
      return {
        title: e.title,
        contentElements: e.contentElements
      };
    case N.Section:
      return {
        isTopLevel: t,
        title: e.title,
        label: e.label,
        contentElements: e.contentElements
      };
    case N.Paragraph:
      return {
        isTopLevel: t,
        contentElements: e.contentElements
      };
    case N.Text:
      return {
        content: e.content,
        styles: e.styles
      };
    case N.Weblink:
      return {
        url: e.url,
        displayText: e.displayText
      };
    case N.List:
      return {
        items: e.items,
        style: e.style
      };
    case N.Table:
      return {
        rows: e.rows,
        label: e.label,
        captions: e.captions,
        titlePrefix: e.titlePrefix,
        title: e.title
      };
    case N.InternalReference:
      return {
        referencedLabel: e.referencedLabel,
        displayText: e.displayText
      };
    case N.Bigskip:
      return {};
    default:
      return null;
  }
};
function E({
  contentElements: e,
  isTopLevel: t = false,
  onExpandSection: n,
  multiple: r
}) {
  const _ = e.map((o) => {
    if (!("type" in o)) return null;
    const s = Tt[o.type];
    return /* @__PURE__ */ a(s, { ...At(o, t) }, It(o.type));
  });
  return t ? /* @__PURE__ */ a(ht, { onExpandSection: n, expand: r, children: _ }) : /* @__PURE__ */ a("span", { children: _ });
}
function Rt({ children: e }) {
  const [t, n] = U({}), r = je(
    () => ({
      addReference: (_) => {
        n((o) => ({
          ...o,
          ..._
        }));
      },
      references: t
    }),
    [t, n]
  );
  return /* @__PURE__ */ a(Qe.Provider, { value: r, children: e });
}
function Ut({
  document: e,
  className: t,
  onExpandSection: n,
  multiple: r
}) {
  const _ = S("adyen-document-viewer", t);
  return /* @__PURE__ */ a(Rt, { children: /* @__PURE__ */ a("div", { className: _, children: [
    /* @__PURE__ */ a(de, { level: 1, className: "adv-u-margin-top-24 adv-u-margin-bottom-16", children: /* @__PURE__ */ a(H, { content: e.title.content, styles: e.title.styles }) }),
    /* @__PURE__ */ a(
      E,
      {
        contentElements: e.contentElements,
        onExpandSection: n,
        multiple: r,
        isTopLevel: true
      }
    )
  ] }) });
}
function Dt(e) {
  return "type" in e && e.type === N.Chapter;
}
function Mt(e) {
  return "type" in e && e.type === N.Section;
}
function Ot(e) {
  return "contentElements" in e && Array.isArray(e.contentElements);
}
function Wt(e) {
  return e.isTopLevel ? `${e.counter}` : `${e.prefix}${e.counter}`;
}
function Bt(e, t) {
  return `${e} ${t}`;
}
function z(e, t) {
  if (Dt(e)) {
    const n = { prefix: "", counter: 1, isTopLevel: true };
    return {
      ...e,
      contentElements: e.contentElements.map(
        (r) => z(r, n)
      )
    };
  } else if (Mt(e)) {
    const n = Wt(t), r = {
      ...e,
      title: {
        ...e.title,
        content: Bt(n, e.title.content)
      }
    };
    t.counter += 1;
    const _ = {
      prefix: `${n}.`,
      counter: 1,
      isTopLevel: false
    };
    return r.contentElements = e.contentElements.map(
      (o) => z(o, _)
    ), r;
  } else if (Ot(e))
    return {
      ...e,
      contentElements: e.contentElements.map(
        (n) => z(n, t)
      )
    };
  return e;
}
function Ft(e) {
  const t = { prefix: "", counter: 1, isTopLevel: true };
  return {
    ...e,
    contentElements: e.contentElements.map(
      (n) => z(n, t)
    )
  };
}
class qt {
  /**
   * Initializes the library
   * @param target - The target element (HTMLElement or querySelector string)
   * @param options - Configuration options for AdyenDocumentViewer
   */
  constructor(t, n = {}) {
    if (typeof t == "object" && "nodeType" in t)
      this.target = t;
    else {
      const r = window.document.querySelector(t);
      if (r instanceof HTMLElement)
        this.target = r;
      else
        throw new Error("Target element was not found");
    }
    this.options = {
      onExpandSection: n.onExpandSection ?? void 0,
      multiple: n.multiple ?? false,
      showSectionNumbering: n.showSectionNumbering ?? false
    };
  }
  /**
   * Renders the document
   * @param document - The JSON document
   */
  render(t) {
    const n = this.options.showSectionNumbering ? Ft(t) : t;
    it(
      /* @__PURE__ */ a(
        Ut,
        {
          document: n,
          onExpandSection: this.options.onExpandSection,
          multiple: this.options.multiple
        }
      ),
      this.target
    );
  }
}
function ContractViewer({
  contract,
  className,
  onExpandSection,
  showSectionNumbering
}) {
  const classNames = cx("adyen-contract-viewer", className);
  const container = useRef(null);
  const [adyenDocumentViewer, setAdyenDocumentViewer] = useState(null);
  useEffect(() => {
    if (container.current && !adyenDocumentViewer) {
      setAdyenDocumentViewer(
        new qt(container.current, { onExpandSection, showSectionNumbering })
      );
    }
    if (adyenDocumentViewer) {
      adyenDocumentViewer.render(contract);
    }
  }, [contract, adyenDocumentViewer, onExpandSection, showSectionNumbering]);
  return /* @__PURE__ */ jsx("div", { ref: container, className: classNames });
}
export {
  ContractViewer as C
};
