import { setLogLevel as Mn, LogLevel as ut, setLogExtension as In, Track as A, RoomEvent as m, ParticipantEvent as y, Room as lt, TrackEvent as At, compareVersions as Dn } from "@cc-livekit/livekit-client";
import * as D from "react";
const Ve = Math.min, ue = Math.max, Ae = Math.round, q = (e) => ({
  x: e,
  y: e
}), Rn = {
  left: "right",
  right: "left",
  bottom: "top",
  top: "bottom"
}, Nn = {
  start: "end",
  end: "start"
};
function ft(e, t, n) {
  return ue(e, Ve(t, n));
}
function Ie(e, t) {
  return typeof e == "function" ? e(t) : e;
}
function re(e) {
  return e.split("-")[0];
}
function De(e) {
  return e.split("-")[1];
}
function kt(e) {
  return e === "x" ? "y" : "x";
}
function _t(e) {
  return e === "y" ? "height" : "width";
}
function de(e) {
  return ["top", "bottom"].includes(re(e)) ? "y" : "x";
}
function Lt(e) {
  return kt(de(e));
}
function Un(e, t, n) {
  n === void 0 && (n = !1);
  const r = De(e), o = Lt(e), i = _t(o);
  let s = o === "x" ? r === (n ? "end" : "start") ? "right" : "left" : r === "start" ? "bottom" : "top";
  return t.reference[i] > t.floating[i] && (s = ke(s)), [s, ke(s)];
}
function Fn(e) {
  const t = ke(e);
  return [He(e), t, He(t)];
}
function He(e) {
  return e.replace(/start|end/g, (t) => Nn[t]);
}
function $n(e, t, n) {
  const r = ["left", "right"], o = ["right", "left"], i = ["top", "bottom"], s = ["bottom", "top"];
  switch (e) {
    case "top":
    case "bottom":
      return n ? t ? o : r : t ? r : o;
    case "left":
    case "right":
      return t ? i : s;
    default:
      return [];
  }
}
function jn(e, t, n, r) {
  const o = De(e);
  let i = $n(re(e), n === "start", r);
  return o && (i = i.map((s) => s + "-" + o), t && (i = i.concat(i.map(He)))), i;
}
function ke(e) {
  return e.replace(/left|right|bottom|top/g, (t) => Rn[t]);
}
function Bn(e) {
  return {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    ...e
  };
}
function Wn(e) {
  return typeof e != "number" ? Bn(e) : {
    top: e,
    right: e,
    bottom: e,
    left: e
  };
}
function _e(e) {
  const {
    x: t,
    y: n,
    width: r,
    height: o
  } = e;
  return {
    width: r,
    height: o,
    top: n,
    left: t,
    right: t + r,
    bottom: n + o,
    x: t,
    y: n
  };
}
function dt(e, t, n) {
  let {
    reference: r,
    floating: o
  } = e;
  const i = de(t), s = Lt(t), a = _t(s), c = re(t), u = i === "y", l = r.x + r.width / 2 - o.width / 2, f = r.y + r.height / 2 - o.height / 2, v = r[a] / 2 - o[a] / 2;
  let d;
  switch (c) {
    case "top":
      d = {
        x: l,
        y: r.y - o.height
      };
      break;
    case "bottom":
      d = {
        x: l,
        y: r.y + r.height
      };
      break;
    case "right":
      d = {
        x: r.x + r.width,
        y: f
      };
      break;
    case "left":
      d = {
        x: r.x - o.width,
        y: f
      };
      break;
    default:
      d = {
        x: r.x,
        y: r.y
      };
  }
  switch (De(t)) {
    case "start":
      d[s] -= v * (n && u ? -1 : 1);
      break;
    case "end":
      d[s] += v * (n && u ? -1 : 1);
      break;
  }
  return d;
}
const Vn = async (e, t, n) => {
  const {
    placement: r = "bottom",
    strategy: o = "absolute",
    middleware: i = [],
    platform: s
  } = n, a = i.filter(Boolean), c = await (s.isRTL == null ? void 0 : s.isRTL(t));
  let u = await s.getElementRects({
    reference: e,
    floating: t,
    strategy: o
  }), {
    x: l,
    y: f
  } = dt(u, r, c), v = r, d = {}, g = 0;
  for (let p = 0; p < a.length; p++) {
    const {
      name: b,
      fn: h
    } = a[p], {
      x: C,
      y: P,
      data: _,
      reset: x
    } = await h({
      x: l,
      y: f,
      initialPlacement: r,
      placement: v,
      strategy: o,
      middlewareData: d,
      rects: u,
      platform: s,
      elements: {
        reference: e,
        floating: t
      }
    });
    l = C ?? l, f = P ?? f, d = {
      ...d,
      [b]: {
        ...d[b],
        ..._
      }
    }, x && g <= 50 && (g++, typeof x == "object" && (x.placement && (v = x.placement), x.rects && (u = x.rects === !0 ? await s.getElementRects({
      reference: e,
      floating: t,
      strategy: o
    }) : x.rects), {
      x: l,
      y: f
    } = dt(u, v, c)), p = -1);
  }
  return {
    x: l,
    y: f,
    placement: v,
    strategy: o,
    middlewareData: d
  };
};
async function Mt(e, t) {
  var n;
  t === void 0 && (t = {});
  const {
    x: r,
    y: o,
    platform: i,
    rects: s,
    elements: a,
    strategy: c
  } = e, {
    boundary: u = "clippingAncestors",
    rootBoundary: l = "viewport",
    elementContext: f = "floating",
    altBoundary: v = !1,
    padding: d = 0
  } = Ie(t, e), g = Wn(d), b = a[v ? f === "floating" ? "reference" : "floating" : f], h = _e(await i.getClippingRect({
    element: (n = await (i.isElement == null ? void 0 : i.isElement(b))) == null || n ? b : b.contextElement || await (i.getDocumentElement == null ? void 0 : i.getDocumentElement(a.floating)),
    boundary: u,
    rootBoundary: l,
    strategy: c
  })), C = f === "floating" ? {
    x: r,
    y: o,
    width: s.floating.width,
    height: s.floating.height
  } : s.reference, P = await (i.getOffsetParent == null ? void 0 : i.getOffsetParent(a.floating)), _ = await (i.isElement == null ? void 0 : i.isElement(P)) ? await (i.getScale == null ? void 0 : i.getScale(P)) || {
    x: 1,
    y: 1
  } : {
    x: 1,
    y: 1
  }, x = _e(i.convertOffsetParentRelativeRectToViewportRelativeRect ? await i.convertOffsetParentRelativeRectToViewportRelativeRect({
    elements: a,
    rect: C,
    offsetParent: P,
    strategy: c
  }) : C);
  return {
    top: (h.top - x.top + g.top) / _.y,
    bottom: (x.bottom - h.bottom + g.bottom) / _.y,
    left: (h.left - x.left + g.left) / _.x,
    right: (x.right - h.right + g.right) / _.x
  };
}
const Hn = function(e) {
  return e === void 0 && (e = {}), {
    name: "flip",
    options: e,
    async fn(t) {
      var n, r;
      const {
        placement: o,
        middlewareData: i,
        rects: s,
        initialPlacement: a,
        platform: c,
        elements: u
      } = t, {
        mainAxis: l = !0,
        crossAxis: f = !0,
        fallbackPlacements: v,
        fallbackStrategy: d = "bestFit",
        fallbackAxisSideDirection: g = "none",
        flipAlignment: p = !0,
        ...b
      } = Ie(e, t);
      if ((n = i.arrow) != null && n.alignmentOffset)
        return {};
      const h = re(o), C = de(a), P = re(a) === a, _ = await (c.isRTL == null ? void 0 : c.isRTL(u.floating)), x = v || (P || !p ? [ke(a)] : Fn(a)), se = g !== "none";
      !v && se && x.push(...jn(a, p, g, _));
      const ae = [a, ...x], E = await Mt(t, b), S = [];
      let L = ((r = i.flip) == null ? void 0 : r.overflows) || [];
      if (l && S.push(E[h]), f) {
        const H = Un(o, s, _);
        S.push(E[H[0]], E[H[1]]);
      }
      if (L = [...L, {
        placement: o,
        overflows: S
      }], !S.every((H) => H <= 0)) {
        var w, T;
        const H = (((w = i.flip) == null ? void 0 : w.index) || 0) + 1, Ce = ae[H];
        if (Ce)
          return {
            data: {
              index: H,
              overflows: L
            },
            reset: {
              placement: Ce
            }
          };
        let be = (T = L.filter((ce) => ce.overflows[0] <= 0).sort((ce, Q) => ce.overflows[1] - Q.overflows[1])[0]) == null ? void 0 : T.placement;
        if (!be)
          switch (d) {
            case "bestFit": {
              var B;
              const ce = (B = L.filter((Q) => {
                if (se) {
                  const X = de(Q.placement);
                  return X === C || // Create a bias to the `y` side axis due to horizontal
                  // reading directions favoring greater width.
                  X === "y";
                }
                return !0;
              }).map((Q) => [Q.placement, Q.overflows.filter((X) => X > 0).reduce((X, Ln) => X + Ln, 0)]).sort((Q, X) => Q[1] - X[1])[0]) == null ? void 0 : B[0];
              ce && (be = ce);
              break;
            }
            case "initialPlacement":
              be = a;
              break;
          }
        if (o !== be)
          return {
            reset: {
              placement: be
            }
          };
      }
      return {};
    }
  };
};
async function zn(e, t) {
  const {
    placement: n,
    platform: r,
    elements: o
  } = e, i = await (r.isRTL == null ? void 0 : r.isRTL(o.floating)), s = re(n), a = De(n), c = de(n) === "y", u = ["left", "top"].includes(s) ? -1 : 1, l = i && c ? -1 : 1, f = Ie(t, e);
  let {
    mainAxis: v,
    crossAxis: d,
    alignmentAxis: g
  } = typeof f == "number" ? {
    mainAxis: f,
    crossAxis: 0,
    alignmentAxis: null
  } : {
    mainAxis: f.mainAxis || 0,
    crossAxis: f.crossAxis || 0,
    alignmentAxis: f.alignmentAxis
  };
  return a && typeof g == "number" && (d = a === "end" ? g * -1 : g), c ? {
    x: d * l,
    y: v * u
  } : {
    x: v * u,
    y: d * l
  };
}
const Yn = function(e) {
  return e === void 0 && (e = 0), {
    name: "offset",
    options: e,
    async fn(t) {
      var n, r;
      const {
        x: o,
        y: i,
        placement: s,
        middlewareData: a
      } = t, c = await zn(t, e);
      return s === ((n = a.offset) == null ? void 0 : n.placement) && (r = a.arrow) != null && r.alignmentOffset ? {} : {
        x: o + c.x,
        y: i + c.y,
        data: {
          ...c,
          placement: s
        }
      };
    }
  };
}, Gn = function(e) {
  return e === void 0 && (e = {}), {
    name: "shift",
    options: e,
    async fn(t) {
      const {
        x: n,
        y: r,
        placement: o
      } = t, {
        mainAxis: i = !0,
        crossAxis: s = !1,
        limiter: a = {
          fn: (b) => {
            let {
              x: h,
              y: C
            } = b;
            return {
              x: h,
              y: C
            };
          }
        },
        ...c
      } = Ie(e, t), u = {
        x: n,
        y: r
      }, l = await Mt(t, c), f = de(re(o)), v = kt(f);
      let d = u[v], g = u[f];
      if (i) {
        const b = v === "y" ? "top" : "left", h = v === "y" ? "bottom" : "right", C = d + l[b], P = d - l[h];
        d = ft(C, d, P);
      }
      if (s) {
        const b = f === "y" ? "top" : "left", h = f === "y" ? "bottom" : "right", C = g + l[b], P = g - l[h];
        g = ft(C, g, P);
      }
      const p = a.fn({
        ...t,
        [v]: d,
        [f]: g
      });
      return {
        ...p,
        data: {
          x: p.x - n,
          y: p.y - r,
          enabled: {
            [v]: i,
            [f]: s
          }
        }
      };
    }
  };
};
function Re() {
  return typeof window < "u";
}
function ve(e) {
  return It(e) ? (e.nodeName || "").toLowerCase() : "#document";
}
function F(e) {
  var t;
  return (e == null || (t = e.ownerDocument) == null ? void 0 : t.defaultView) || window;
}
function K(e) {
  var t;
  return (t = (It(e) ? e.ownerDocument : e.document) || window.document) == null ? void 0 : t.documentElement;
}
function It(e) {
  return Re() ? e instanceof Node || e instanceof F(e).Node : !1;
}
function W(e) {
  return Re() ? e instanceof Element || e instanceof F(e).Element : !1;
}
function z(e) {
  return Re() ? e instanceof HTMLElement || e instanceof F(e).HTMLElement : !1;
}
function pt(e) {
  return !Re() || typeof ShadowRoot > "u" ? !1 : e instanceof ShadowRoot || e instanceof F(e).ShadowRoot;
}
function Te(e) {
  const {
    overflow: t,
    overflowX: n,
    overflowY: r,
    display: o
  } = V(e);
  return /auto|scroll|overlay|hidden|clip/.test(t + r + n) && !["inline", "contents"].includes(o);
}
function Jn(e) {
  return ["table", "td", "th"].includes(ve(e));
}
function Ne(e) {
  return [":popover-open", ":modal"].some((t) => {
    try {
      return e.matches(t);
    } catch {
      return !1;
    }
  });
}
function rt(e) {
  const t = ot(), n = W(e) ? V(e) : e;
  return n.transform !== "none" || n.perspective !== "none" || (n.containerType ? n.containerType !== "normal" : !1) || !t && (n.backdropFilter ? n.backdropFilter !== "none" : !1) || !t && (n.filter ? n.filter !== "none" : !1) || ["transform", "perspective", "filter"].some((r) => (n.willChange || "").includes(r)) || ["paint", "layout", "strict", "content"].some((r) => (n.contain || "").includes(r));
}
function Kn(e) {
  let t = Z(e);
  for (; z(t) && !pe(t); ) {
    if (rt(t))
      return t;
    if (Ne(t))
      return null;
    t = Z(t);
  }
  return null;
}
function ot() {
  return typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("-webkit-backdrop-filter", "none");
}
function pe(e) {
  return ["html", "body", "#document"].includes(ve(e));
}
function V(e) {
  return F(e).getComputedStyle(e);
}
function Ue(e) {
  return W(e) ? {
    scrollLeft: e.scrollLeft,
    scrollTop: e.scrollTop
  } : {
    scrollLeft: e.scrollX,
    scrollTop: e.scrollY
  };
}
function Z(e) {
  if (ve(e) === "html")
    return e;
  const t = (
    // Step into the shadow DOM of the parent of a slotted node.
    e.assignedSlot || // DOM Element detected.
    e.parentNode || // ShadowRoot detected.
    pt(e) && e.host || // Fallback.
    K(e)
  );
  return pt(t) ? t.host : t;
}
function Dt(e) {
  const t = Z(e);
  return pe(t) ? e.ownerDocument ? e.ownerDocument.body : e.body : z(t) && Te(t) ? t : Dt(t);
}
function Rt(e, t, n) {
  var r;
  t === void 0 && (t = []);
  const o = Dt(e), i = o === ((r = e.ownerDocument) == null ? void 0 : r.body), s = F(o);
  return i ? (ze(s), t.concat(s, s.visualViewport || [], Te(o) ? o : [], [])) : t.concat(o, Rt(o, []));
}
function ze(e) {
  return e.parent && Object.getPrototypeOf(e.parent) ? e.frameElement : null;
}
function Nt(e) {
  const t = V(e);
  let n = parseFloat(t.width) || 0, r = parseFloat(t.height) || 0;
  const o = z(e), i = o ? e.offsetWidth : n, s = o ? e.offsetHeight : r, a = Ae(n) !== i || Ae(r) !== s;
  return a && (n = i, r = s), {
    width: n,
    height: r,
    $: a
  };
}
function Ut(e) {
  return W(e) ? e : e.contextElement;
}
function le(e) {
  const t = Ut(e);
  if (!z(t))
    return q(1);
  const n = t.getBoundingClientRect(), {
    width: r,
    height: o,
    $: i
  } = Nt(t);
  let s = (i ? Ae(n.width) : n.width) / r, a = (i ? Ae(n.height) : n.height) / o;
  return (!s || !Number.isFinite(s)) && (s = 1), (!a || !Number.isFinite(a)) && (a = 1), {
    x: s,
    y: a
  };
}
const Qn = /* @__PURE__ */ q(0);
function Ft(e) {
  const t = F(e);
  return !ot() || !t.visualViewport ? Qn : {
    x: t.visualViewport.offsetLeft,
    y: t.visualViewport.offsetTop
  };
}
function Xn(e, t, n) {
  return t === void 0 && (t = !1), !n || t && n !== F(e) ? !1 : t;
}
function Se(e, t, n, r) {
  t === void 0 && (t = !1), n === void 0 && (n = !1);
  const o = e.getBoundingClientRect(), i = Ut(e);
  let s = q(1);
  t && (r ? W(r) && (s = le(r)) : s = le(e));
  const a = Xn(i, n, r) ? Ft(i) : q(0);
  let c = (o.left + a.x) / s.x, u = (o.top + a.y) / s.y, l = o.width / s.x, f = o.height / s.y;
  if (i) {
    const v = F(i), d = r && W(r) ? F(r) : r;
    let g = v, p = ze(g);
    for (; p && r && d !== g; ) {
      const b = le(p), h = p.getBoundingClientRect(), C = V(p), P = h.left + (p.clientLeft + parseFloat(C.paddingLeft)) * b.x, _ = h.top + (p.clientTop + parseFloat(C.paddingTop)) * b.y;
      c *= b.x, u *= b.y, l *= b.x, f *= b.y, c += P, u += _, g = F(p), p = ze(g);
    }
  }
  return _e({
    width: l,
    height: f,
    x: c,
    y: u
  });
}
function qn(e) {
  let {
    elements: t,
    rect: n,
    offsetParent: r,
    strategy: o
  } = e;
  const i = o === "fixed", s = K(r), a = t ? Ne(t.floating) : !1;
  if (r === s || a && i)
    return n;
  let c = {
    scrollLeft: 0,
    scrollTop: 0
  }, u = q(1);
  const l = q(0), f = z(r);
  if ((f || !f && !i) && ((ve(r) !== "body" || Te(s)) && (c = Ue(r)), z(r))) {
    const v = Se(r);
    u = le(r), l.x = v.x + r.clientLeft, l.y = v.y + r.clientTop;
  }
  return {
    width: n.width * u.x,
    height: n.height * u.y,
    x: n.x * u.x - c.scrollLeft * u.x + l.x,
    y: n.y * u.y - c.scrollTop * u.y + l.y
  };
}
function Zn(e) {
  return Array.from(e.getClientRects());
}
function Ye(e, t) {
  const n = Ue(e).scrollLeft;
  return t ? t.left + n : Se(K(e)).left + n;
}
function er(e) {
  const t = K(e), n = Ue(e), r = e.ownerDocument.body, o = ue(t.scrollWidth, t.clientWidth, r.scrollWidth, r.clientWidth), i = ue(t.scrollHeight, t.clientHeight, r.scrollHeight, r.clientHeight);
  let s = -n.scrollLeft + Ye(e);
  const a = -n.scrollTop;
  return V(r).direction === "rtl" && (s += ue(t.clientWidth, r.clientWidth) - o), {
    width: o,
    height: i,
    x: s,
    y: a
  };
}
function tr(e, t) {
  const n = F(e), r = K(e), o = n.visualViewport;
  let i = r.clientWidth, s = r.clientHeight, a = 0, c = 0;
  if (o) {
    i = o.width, s = o.height;
    const u = ot();
    (!u || u && t === "fixed") && (a = o.offsetLeft, c = o.offsetTop);
  }
  return {
    width: i,
    height: s,
    x: a,
    y: c
  };
}
function nr(e, t) {
  const n = Se(e, !0, t === "fixed"), r = n.top + e.clientTop, o = n.left + e.clientLeft, i = z(e) ? le(e) : q(1), s = e.clientWidth * i.x, a = e.clientHeight * i.y, c = o * i.x, u = r * i.y;
  return {
    width: s,
    height: a,
    x: c,
    y: u
  };
}
function ht(e, t, n) {
  let r;
  if (t === "viewport")
    r = tr(e, n);
  else if (t === "document")
    r = er(K(e));
  else if (W(t))
    r = nr(t, n);
  else {
    const o = Ft(e);
    r = {
      ...t,
      x: t.x - o.x,
      y: t.y - o.y
    };
  }
  return _e(r);
}
function $t(e, t) {
  const n = Z(e);
  return n === t || !W(n) || pe(n) ? !1 : V(n).position === "fixed" || $t(n, t);
}
function rr(e, t) {
  const n = t.get(e);
  if (n)
    return n;
  let r = Rt(e, []).filter((a) => W(a) && ve(a) !== "body"), o = null;
  const i = V(e).position === "fixed";
  let s = i ? Z(e) : e;
  for (; W(s) && !pe(s); ) {
    const a = V(s), c = rt(s);
    !c && a.position === "fixed" && (o = null), (i ? !c && !o : !c && a.position === "static" && !!o && ["absolute", "fixed"].includes(o.position) || Te(s) && !c && $t(e, s)) ? r = r.filter((l) => l !== s) : o = a, s = Z(s);
  }
  return t.set(e, r), r;
}
function or(e) {
  let {
    element: t,
    boundary: n,
    rootBoundary: r,
    strategy: o
  } = e;
  const s = [...n === "clippingAncestors" ? Ne(t) ? [] : rr(t, this._c) : [].concat(n), r], a = s[0], c = s.reduce((u, l) => {
    const f = ht(t, l, o);
    return u.top = ue(f.top, u.top), u.right = Ve(f.right, u.right), u.bottom = Ve(f.bottom, u.bottom), u.left = ue(f.left, u.left), u;
  }, ht(t, a, o));
  return {
    width: c.right - c.left,
    height: c.bottom - c.top,
    x: c.left,
    y: c.top
  };
}
function ir(e) {
  const {
    width: t,
    height: n
  } = Nt(e);
  return {
    width: t,
    height: n
  };
}
function sr(e, t, n) {
  const r = z(t), o = K(t), i = n === "fixed", s = Se(e, !0, i, t);
  let a = {
    scrollLeft: 0,
    scrollTop: 0
  };
  const c = q(0);
  if (r || !r && !i)
    if ((ve(t) !== "body" || Te(o)) && (a = Ue(t)), r) {
      const d = Se(t, !0, i, t);
      c.x = d.x + t.clientLeft, c.y = d.y + t.clientTop;
    } else o && (c.x = Ye(o));
  let u = 0, l = 0;
  if (o && !r && !i) {
    const d = o.getBoundingClientRect();
    l = d.top + a.scrollTop, u = d.left + a.scrollLeft - // RTL <body> scrollbar.
    Ye(o, d);
  }
  const f = s.left + a.scrollLeft - c.x - u, v = s.top + a.scrollTop - c.y - l;
  return {
    x: f,
    y: v,
    width: s.width,
    height: s.height
  };
}
function je(e) {
  return V(e).position === "static";
}
function vt(e, t) {
  if (!z(e) || V(e).position === "fixed")
    return null;
  if (t)
    return t(e);
  let n = e.offsetParent;
  return K(e) === n && (n = n.ownerDocument.body), n;
}
function jt(e, t) {
  const n = F(e);
  if (Ne(e))
    return n;
  if (!z(e)) {
    let o = Z(e);
    for (; o && !pe(o); ) {
      if (W(o) && !je(o))
        return o;
      o = Z(o);
    }
    return n;
  }
  let r = vt(e, t);
  for (; r && Jn(r) && je(r); )
    r = vt(r, t);
  return r && pe(r) && je(r) && !rt(r) ? n : r || Kn(e) || n;
}
const ar = async function(e) {
  const t = this.getOffsetParent || jt, n = this.getDimensions, r = await n(e.floating);
  return {
    reference: sr(e.reference, await t(e.floating), e.strategy),
    floating: {
      x: 0,
      y: 0,
      width: r.width,
      height: r.height
    }
  };
};
function cr(e) {
  return V(e).direction === "rtl";
}
const ur = {
  convertOffsetParentRelativeRectToViewportRelativeRect: qn,
  getDocumentElement: K,
  getClippingRect: or,
  getOffsetParent: jt,
  getElementRects: ar,
  getClientRects: Zn,
  getDimensions: ir,
  getScale: le,
  isElement: W,
  isRTL: cr
}, lr = Yn, fr = Gn, dr = Hn, pr = (e, t, n) => {
  const r = /* @__PURE__ */ new Map(), o = {
    platform: ur,
    ...n
  }, i = {
    ...o.platform,
    _c: r
  };
  return Vn(e, t, {
    ...o,
    platform: i
  });
};
var hr = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function vr(e) {
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
function qo(e) {
  if (e.__esModule) return e;
  var t = e.default;
  if (typeof t == "function") {
    var n = function r() {
      return this instanceof r ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
    };
    n.prototype = t.prototype;
  } else n = {};
  return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
    var o = Object.getOwnPropertyDescriptor(e, r);
    Object.defineProperty(n, r, o.get ? o : {
      enumerable: !0,
      get: function() {
        return e[r];
      }
    });
  }), n;
}
var Bt = { exports: {} };
(function(e) {
  (function(t, n) {
    e.exports ? e.exports = n() : t.log = n();
  })(hr, function() {
    var t = function() {
    }, n = "undefined", r = typeof window !== n && typeof window.navigator !== n && /Trident\/|MSIE /.test(window.navigator.userAgent), o = [
      "trace",
      "debug",
      "info",
      "warn",
      "error"
    ], i = {}, s = null;
    function a(p, b) {
      var h = p[b];
      if (typeof h.bind == "function")
        return h.bind(p);
      try {
        return Function.prototype.bind.call(h, p);
      } catch {
        return function() {
          return Function.prototype.apply.apply(h, [p, arguments]);
        };
      }
    }
    function c() {
      console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
    }
    function u(p) {
      return p === "debug" && (p = "log"), typeof console === n ? !1 : p === "trace" && r ? c : console[p] !== void 0 ? a(console, p) : console.log !== void 0 ? a(console, "log") : t;
    }
    function l() {
      for (var p = this.getLevel(), b = 0; b < o.length; b++) {
        var h = o[b];
        this[h] = b < p ? t : this.methodFactory(h, p, this.name);
      }
      if (this.log = this.debug, typeof console === n && p < this.levels.SILENT)
        return "No console available for logging";
    }
    function f(p) {
      return function() {
        typeof console !== n && (l.call(this), this[p].apply(this, arguments));
      };
    }
    function v(p, b, h) {
      return u(p) || f.apply(this, arguments);
    }
    function d(p, b) {
      var h = this, C, P, _, x = "loglevel";
      typeof p == "string" ? x += ":" + p : typeof p == "symbol" && (x = void 0);
      function se(w) {
        var T = (o[w] || "silent").toUpperCase();
        if (!(typeof window === n || !x)) {
          try {
            window.localStorage[x] = T;
            return;
          } catch {
          }
          try {
            window.document.cookie = encodeURIComponent(x) + "=" + T + ";";
          } catch {
          }
        }
      }
      function ae() {
        var w;
        if (!(typeof window === n || !x)) {
          try {
            w = window.localStorage[x];
          } catch {
          }
          if (typeof w === n)
            try {
              var T = window.document.cookie, B = encodeURIComponent(x), H = T.indexOf(B + "=");
              H !== -1 && (w = /^([^;]+)/.exec(
                T.slice(H + B.length + 1)
              )[1]);
            } catch {
            }
          return h.levels[w] === void 0 && (w = void 0), w;
        }
      }
      function E() {
        if (!(typeof window === n || !x)) {
          try {
            window.localStorage.removeItem(x);
          } catch {
          }
          try {
            window.document.cookie = encodeURIComponent(x) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
          } catch {
          }
        }
      }
      function S(w) {
        var T = w;
        if (typeof T == "string" && h.levels[T.toUpperCase()] !== void 0 && (T = h.levels[T.toUpperCase()]), typeof T == "number" && T >= 0 && T <= h.levels.SILENT)
          return T;
        throw new TypeError("log.setLevel() called with invalid level: " + w);
      }
      h.name = p, h.levels = {
        TRACE: 0,
        DEBUG: 1,
        INFO: 2,
        WARN: 3,
        ERROR: 4,
        SILENT: 5
      }, h.methodFactory = b || v, h.getLevel = function() {
        return _ ?? P ?? C;
      }, h.setLevel = function(w, T) {
        return _ = S(w), T !== !1 && se(_), l.call(h);
      }, h.setDefaultLevel = function(w) {
        P = S(w), ae() || h.setLevel(w, !1);
      }, h.resetLevel = function() {
        _ = null, E(), l.call(h);
      }, h.enableAll = function(w) {
        h.setLevel(h.levels.TRACE, w);
      }, h.disableAll = function(w) {
        h.setLevel(h.levels.SILENT, w);
      }, h.rebuild = function() {
        if (s !== h && (C = S(s.getLevel())), l.call(h), s === h)
          for (var w in i)
            i[w].rebuild();
      }, C = S(
        s ? s.getLevel() : "WARN"
      );
      var L = ae();
      L != null && (_ = S(L)), l.call(h);
    }
    s = new d(), s.getLogger = function(b) {
      if (typeof b != "symbol" && typeof b != "string" || b === "")
        throw new TypeError("You must supply a name when creating a logger.");
      var h = i[b];
      return h || (h = i[b] = new d(
        b,
        s.methodFactory
      )), h;
    };
    var g = typeof window !== n ? window.log : void 0;
    return s.noConflict = function() {
      return typeof window !== n && window.log === s && (window.log = g), s;
    }, s.getLoggers = function() {
      return i;
    }, s.default = s, s;
  });
})(Bt);
var gr = Bt.exports;
const mr = /* @__PURE__ */ vr(gr);
var Ge = function(e, t) {
  return Ge = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, r) {
    n.__proto__ = r;
  } || function(n, r) {
    for (var o in r) Object.prototype.hasOwnProperty.call(r, o) && (n[o] = r[o]);
  }, Ge(e, t);
};
function ge(e, t) {
  if (typeof t != "function" && t !== null)
    throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
  Ge(e, t);
  function n() {
    this.constructor = e;
  }
  e.prototype = t === null ? Object.create(t) : (n.prototype = t.prototype, new n());
}
function br(e, t, n, r) {
  function o(i) {
    return i instanceof n ? i : new n(function(s) {
      s(i);
    });
  }
  return new (n || (n = Promise))(function(i, s) {
    function a(l) {
      try {
        u(r.next(l));
      } catch (f) {
        s(f);
      }
    }
    function c(l) {
      try {
        u(r.throw(l));
      } catch (f) {
        s(f);
      }
    }
    function u(l) {
      l.done ? i(l.value) : o(l.value).then(a, c);
    }
    u((r = r.apply(e, t || [])).next());
  });
}
function Wt(e, t) {
  var n = { label: 0, sent: function() {
    if (i[0] & 1) throw i[1];
    return i[1];
  }, trys: [], ops: [] }, r, o, i, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
  return s.next = a(0), s.throw = a(1), s.return = a(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() {
    return this;
  }), s;
  function a(u) {
    return function(l) {
      return c([u, l]);
    };
  }
  function c(u) {
    if (r) throw new TypeError("Generator is already executing.");
    for (; s && (s = 0, u[0] && (n = 0)), n; ) try {
      if (r = 1, o && (i = u[0] & 2 ? o.return : u[0] ? o.throw || ((i = o.return) && i.call(o), 0) : o.next) && !(i = i.call(o, u[1])).done) return i;
      switch (o = 0, i && (u = [u[0] & 2, i.value]), u[0]) {
        case 0:
        case 1:
          i = u;
          break;
        case 4:
          return n.label++, { value: u[1], done: !1 };
        case 5:
          n.label++, o = u[1], u = [0];
          continue;
        case 7:
          u = n.ops.pop(), n.trys.pop();
          continue;
        default:
          if (i = n.trys, !(i = i.length > 0 && i[i.length - 1]) && (u[0] === 6 || u[0] === 2)) {
            n = 0;
            continue;
          }
          if (u[0] === 3 && (!i || u[1] > i[0] && u[1] < i[3])) {
            n.label = u[1];
            break;
          }
          if (u[0] === 6 && n.label < i[1]) {
            n.label = i[1], i = u;
            break;
          }
          if (i && n.label < i[2]) {
            n.label = i[2], n.ops.push(u);
            break;
          }
          i[2] && n.ops.pop(), n.trys.pop();
          continue;
      }
      u = t.call(e, n);
    } catch (l) {
      u = [6, l], o = 0;
    } finally {
      r = i = 0;
    }
    if (u[0] & 5) throw u[1];
    return { value: u[0] ? u[1] : void 0, done: !0 };
  }
}
function he(e) {
  var t = typeof Symbol == "function" && Symbol.iterator, n = t && e[t], r = 0;
  if (n) return n.call(e);
  if (e && typeof e.length == "number") return {
    next: function() {
      return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e };
    }
  };
  throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function Je(e, t) {
  var n = typeof Symbol == "function" && e[Symbol.iterator];
  if (!n) return e;
  var r = n.call(e), o, i = [], s;
  try {
    for (; (t === void 0 || t-- > 0) && !(o = r.next()).done; ) i.push(o.value);
  } catch (a) {
    s = { error: a };
  } finally {
    try {
      o && !o.done && (n = r.return) && n.call(r);
    } finally {
      if (s) throw s.error;
    }
  }
  return i;
}
function Ke(e, t, n) {
  if (n || arguments.length === 2) for (var r = 0, o = t.length, i; r < o; r++)
    (i || !(r in t)) && (i || (i = Array.prototype.slice.call(t, 0, r)), i[r] = t[r]);
  return e.concat(i || Array.prototype.slice.call(t));
}
function fe(e) {
  return this instanceof fe ? (this.v = e, this) : new fe(e);
}
function yr(e, t, n) {
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  var r = n.apply(e, t || []), o, i = [];
  return o = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), a("next"), a("throw"), a("return", s), o[Symbol.asyncIterator] = function() {
    return this;
  }, o;
  function s(d) {
    return function(g) {
      return Promise.resolve(g).then(d, f);
    };
  }
  function a(d, g) {
    r[d] && (o[d] = function(p) {
      return new Promise(function(b, h) {
        i.push([d, p, b, h]) > 1 || c(d, p);
      });
    }, g && (o[d] = g(o[d])));
  }
  function c(d, g) {
    try {
      u(r[d](g));
    } catch (p) {
      v(i[0][3], p);
    }
  }
  function u(d) {
    d.value instanceof fe ? Promise.resolve(d.value.v).then(l, f) : v(i[0][2], d);
  }
  function l(d) {
    c("next", d);
  }
  function f(d) {
    c("throw", d);
  }
  function v(d, g) {
    d(g), i.shift(), i.length && c(i[0][0], i[0][1]);
  }
}
function wr(e) {
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  var t = e[Symbol.asyncIterator], n;
  return t ? t.call(e) : (e = typeof he == "function" ? he(e) : e[Symbol.iterator](), n = {}, r("next"), r("throw"), r("return"), n[Symbol.asyncIterator] = function() {
    return this;
  }, n);
  function r(i) {
    n[i] = e[i] && function(s) {
      return new Promise(function(a, c) {
        s = e[i](s), o(a, c, s.done, s.value);
      });
    };
  }
  function o(i, s, a, c) {
    Promise.resolve(c).then(function(u) {
      i({ value: u, done: a });
    }, s);
  }
}
function M(e) {
  return typeof e == "function";
}
function Vt(e) {
  var t = function(r) {
    Error.call(r), r.stack = new Error().stack;
  }, n = e(t);
  return n.prototype = Object.create(Error.prototype), n.prototype.constructor = n, n;
}
var Be = Vt(function(e) {
  return function(n) {
    e(this), this.message = n ? n.length + ` errors occurred during unsubscription:
` + n.map(function(r, o) {
      return o + 1 + ") " + r.toString();
    }).join(`
  `) : "", this.name = "UnsubscriptionError", this.errors = n;
  };
});
function Qe(e, t) {
  if (e) {
    var n = e.indexOf(t);
    0 <= n && e.splice(n, 1);
  }
}
var Fe = function() {
  function e(t) {
    this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null;
  }
  return e.prototype.unsubscribe = function() {
    var t, n, r, o, i;
    if (!this.closed) {
      this.closed = !0;
      var s = this._parentage;
      if (s)
        if (this._parentage = null, Array.isArray(s))
          try {
            for (var a = he(s), c = a.next(); !c.done; c = a.next()) {
              var u = c.value;
              u.remove(this);
            }
          } catch (p) {
            t = { error: p };
          } finally {
            try {
              c && !c.done && (n = a.return) && n.call(a);
            } finally {
              if (t) throw t.error;
            }
          }
        else
          s.remove(this);
      var l = this.initialTeardown;
      if (M(l))
        try {
          l();
        } catch (p) {
          i = p instanceof Be ? p.errors : [p];
        }
      var f = this._finalizers;
      if (f) {
        this._finalizers = null;
        try {
          for (var v = he(f), d = v.next(); !d.done; d = v.next()) {
            var g = d.value;
            try {
              gt(g);
            } catch (p) {
              i = i ?? [], p instanceof Be ? i = Ke(Ke([], Je(i)), Je(p.errors)) : i.push(p);
            }
          }
        } catch (p) {
          r = { error: p };
        } finally {
          try {
            d && !d.done && (o = v.return) && o.call(v);
          } finally {
            if (r) throw r.error;
          }
        }
      }
      if (i)
        throw new Be(i);
    }
  }, e.prototype.add = function(t) {
    var n;
    if (t && t !== this)
      if (this.closed)
        gt(t);
      else {
        if (t instanceof e) {
          if (t.closed || t._hasParent(this))
            return;
          t._addParent(this);
        }
        (this._finalizers = (n = this._finalizers) !== null && n !== void 0 ? n : []).push(t);
      }
  }, e.prototype._hasParent = function(t) {
    var n = this._parentage;
    return n === t || Array.isArray(n) && n.includes(t);
  }, e.prototype._addParent = function(t) {
    var n = this._parentage;
    this._parentage = Array.isArray(n) ? (n.push(t), n) : n ? [n, t] : t;
  }, e.prototype._removeParent = function(t) {
    var n = this._parentage;
    n === t ? this._parentage = null : Array.isArray(n) && Qe(n, t);
  }, e.prototype.remove = function(t) {
    var n = this._finalizers;
    n && Qe(n, t), t instanceof e && t._removeParent(this);
  }, e.EMPTY = function() {
    var t = new e();
    return t.closed = !0, t;
  }(), e;
}(), Ht = Fe.EMPTY;
function zt(e) {
  return e instanceof Fe || e && "closed" in e && M(e.remove) && M(e.add) && M(e.unsubscribe);
}
function gt(e) {
  M(e) ? e() : e.unsubscribe();
}
var Sr = {
  Promise: void 0
}, xr = {
  setTimeout: function(e, t) {
    for (var n = [], r = 2; r < arguments.length; r++)
      n[r - 2] = arguments[r];
    return setTimeout.apply(void 0, Ke([e, t], Je(n)));
  },
  clearTimeout: function(e) {
    return clearTimeout(e);
  },
  delegate: void 0
};
function Yt(e) {
  xr.setTimeout(function() {
    throw e;
  });
}
function Xe() {
}
function Oe(e) {
  e();
}
var it = function(e) {
  ge(t, e);
  function t(n) {
    var r = e.call(this) || this;
    return r.isStopped = !1, n ? (r.destination = n, zt(n) && n.add(r)) : r.destination = Er, r;
  }
  return t.create = function(n, r, o) {
    return new qe(n, r, o);
  }, t.prototype.next = function(n) {
    this.isStopped || this._next(n);
  }, t.prototype.error = function(n) {
    this.isStopped || (this.isStopped = !0, this._error(n));
  }, t.prototype.complete = function() {
    this.isStopped || (this.isStopped = !0, this._complete());
  }, t.prototype.unsubscribe = function() {
    this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null);
  }, t.prototype._next = function(n) {
    this.destination.next(n);
  }, t.prototype._error = function(n) {
    try {
      this.destination.error(n);
    } finally {
      this.unsubscribe();
    }
  }, t.prototype._complete = function() {
    try {
      this.destination.complete();
    } finally {
      this.unsubscribe();
    }
  }, t;
}(Fe), Tr = function() {
  function e(t) {
    this.partialObserver = t;
  }
  return e.prototype.next = function(t) {
    var n = this.partialObserver;
    if (n.next)
      try {
        n.next(t);
      } catch (r) {
        Ee(r);
      }
  }, e.prototype.error = function(t) {
    var n = this.partialObserver;
    if (n.error)
      try {
        n.error(t);
      } catch (r) {
        Ee(r);
      }
    else
      Ee(t);
  }, e.prototype.complete = function() {
    var t = this.partialObserver;
    if (t.complete)
      try {
        t.complete();
      } catch (n) {
        Ee(n);
      }
  }, e;
}(), qe = function(e) {
  ge(t, e);
  function t(n, r, o) {
    var i = e.call(this) || this, s;
    return M(n) || !n ? s = {
      next: n ?? void 0,
      error: r ?? void 0,
      complete: o ?? void 0
    } : s = n, i.destination = new Tr(s), i;
  }
  return t;
}(it);
function Ee(e) {
  Yt(e);
}
function Cr(e) {
  throw e;
}
var Er = {
  closed: !0,
  next: Xe,
  error: Cr,
  complete: Xe
}, st = function() {
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
}();
function Gt(e) {
  return e;
}
function Pr(e) {
  return e.length === 0 ? Gt : e.length === 1 ? e[0] : function(n) {
    return e.reduce(function(r, o) {
      return o(r);
    }, n);
  };
}
var k = function() {
  function e(t) {
    t && (this._subscribe = t);
  }
  return e.prototype.lift = function(t) {
    var n = new e();
    return n.source = this, n.operator = t, n;
  }, e.prototype.subscribe = function(t, n, r) {
    var o = this, i = Ar(t) ? t : new qe(t, n, r);
    return Oe(function() {
      var s = o, a = s.operator, c = s.source;
      i.add(a ? a.call(i, c) : c ? o._subscribe(i) : o._trySubscribe(i));
    }), i;
  }, e.prototype._trySubscribe = function(t) {
    try {
      return this._subscribe(t);
    } catch (n) {
      t.error(n);
    }
  }, e.prototype.forEach = function(t, n) {
    var r = this;
    return n = mt(n), new n(function(o, i) {
      var s = new qe({
        next: function(a) {
          try {
            t(a);
          } catch (c) {
            i(c), s.unsubscribe();
          }
        },
        error: i,
        complete: o
      });
      r.subscribe(s);
    });
  }, e.prototype._subscribe = function(t) {
    var n;
    return (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t);
  }, e.prototype[st] = function() {
    return this;
  }, e.prototype.pipe = function() {
    for (var t = [], n = 0; n < arguments.length; n++)
      t[n] = arguments[n];
    return Pr(t)(this);
  }, e.prototype.toPromise = function(t) {
    var n = this;
    return t = mt(t), new t(function(r, o) {
      var i;
      n.subscribe(function(s) {
        return i = s;
      }, function(s) {
        return o(s);
      }, function() {
        return r(i);
      });
    });
  }, e.create = function(t) {
    return new e(t);
  }, e;
}();
function mt(e) {
  var t;
  return (t = e ?? Sr.Promise) !== null && t !== void 0 ? t : Promise;
}
function Or(e) {
  return e && M(e.next) && M(e.error) && M(e.complete);
}
function Ar(e) {
  return e && e instanceof it || Or(e) && zt(e);
}
function kr(e) {
  return M(e == null ? void 0 : e.lift);
}
function Y(e) {
  return function(t) {
    if (kr(t))
      return t.lift(function(n) {
        try {
          return e(n, this);
        } catch (r) {
          this.error(r);
        }
      });
    throw new TypeError("Unable to lift unknown Observable type");
  };
}
function J(e, t, n, r, o) {
  return new _r(e, t, n, r, o);
}
var _r = function(e) {
  ge(t, e);
  function t(n, r, o, i, s, a) {
    var c = e.call(this, n) || this;
    return c.onFinalize = s, c.shouldUnsubscribe = a, c._next = r ? function(u) {
      try {
        r(u);
      } catch (l) {
        n.error(l);
      }
    } : e.prototype._next, c._error = i ? function(u) {
      try {
        i(u);
      } catch (l) {
        n.error(l);
      } finally {
        this.unsubscribe();
      }
    } : e.prototype._error, c._complete = o ? function() {
      try {
        o();
      } catch (u) {
        n.error(u);
      } finally {
        this.unsubscribe();
      }
    } : e.prototype._complete, c;
  }
  return t.prototype.unsubscribe = function() {
    var n;
    if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
      var r = this.closed;
      e.prototype.unsubscribe.call(this), !r && ((n = this.onFinalize) === null || n === void 0 || n.call(this));
    }
  }, t;
}(it), Lr = Vt(function(e) {
  return function() {
    e(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
  };
}), ee = function(e) {
  ge(t, e);
  function t() {
    var n = e.call(this) || this;
    return n.closed = !1, n.currentObservers = null, n.observers = [], n.isStopped = !1, n.hasError = !1, n.thrownError = null, n;
  }
  return t.prototype.lift = function(n) {
    var r = new bt(this, this);
    return r.operator = n, r;
  }, t.prototype._throwIfClosed = function() {
    if (this.closed)
      throw new Lr();
  }, t.prototype.next = function(n) {
    var r = this;
    Oe(function() {
      var o, i;
      if (r._throwIfClosed(), !r.isStopped) {
        r.currentObservers || (r.currentObservers = Array.from(r.observers));
        try {
          for (var s = he(r.currentObservers), a = s.next(); !a.done; a = s.next()) {
            var c = a.value;
            c.next(n);
          }
        } catch (u) {
          o = { error: u };
        } finally {
          try {
            a && !a.done && (i = s.return) && i.call(s);
          } finally {
            if (o) throw o.error;
          }
        }
      }
    });
  }, t.prototype.error = function(n) {
    var r = this;
    Oe(function() {
      if (r._throwIfClosed(), !r.isStopped) {
        r.hasError = r.isStopped = !0, r.thrownError = n;
        for (var o = r.observers; o.length; )
          o.shift().error(n);
      }
    });
  }, t.prototype.complete = function() {
    var n = this;
    Oe(function() {
      if (n._throwIfClosed(), !n.isStopped) {
        n.isStopped = !0;
        for (var r = n.observers; r.length; )
          r.shift().complete();
      }
    });
  }, t.prototype.unsubscribe = function() {
    this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
  }, Object.defineProperty(t.prototype, "observed", {
    get: function() {
      var n;
      return ((n = this.observers) === null || n === void 0 ? void 0 : n.length) > 0;
    },
    enumerable: !1,
    configurable: !0
  }), t.prototype._trySubscribe = function(n) {
    return this._throwIfClosed(), e.prototype._trySubscribe.call(this, n);
  }, t.prototype._subscribe = function(n) {
    return this._throwIfClosed(), this._checkFinalizedStatuses(n), this._innerSubscribe(n);
  }, t.prototype._innerSubscribe = function(n) {
    var r = this, o = this, i = o.hasError, s = o.isStopped, a = o.observers;
    return i || s ? Ht : (this.currentObservers = null, a.push(n), new Fe(function() {
      r.currentObservers = null, Qe(a, n);
    }));
  }, t.prototype._checkFinalizedStatuses = function(n) {
    var r = this, o = r.hasError, i = r.thrownError, s = r.isStopped;
    o ? n.error(i) : s && n.complete();
  }, t.prototype.asObservable = function() {
    var n = new k();
    return n.source = this, n;
  }, t.create = function(n, r) {
    return new bt(n, r);
  }, t;
}(k), bt = function(e) {
  ge(t, e);
  function t(n, r) {
    var o = e.call(this) || this;
    return o.destination = n, o.source = r, o;
  }
  return t.prototype.next = function(n) {
    var r, o;
    (o = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || o === void 0 || o.call(r, n);
  }, t.prototype.error = function(n) {
    var r, o;
    (o = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || o === void 0 || o.call(r, n);
  }, t.prototype.complete = function() {
    var n, r;
    (r = (n = this.destination) === null || n === void 0 ? void 0 : n.complete) === null || r === void 0 || r.call(n);
  }, t.prototype._subscribe = function(n) {
    var r, o;
    return (o = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(n)) !== null && o !== void 0 ? o : Ht;
  }, t;
}(ee), Jt = function(e) {
  ge(t, e);
  function t(n) {
    var r = e.call(this) || this;
    return r._value = n, r;
  }
  return Object.defineProperty(t.prototype, "value", {
    get: function() {
      return this.getValue();
    },
    enumerable: !1,
    configurable: !0
  }), t.prototype._subscribe = function(n) {
    var r = e.prototype._subscribe.call(this, n);
    return !r.closed && n.next(this._value), r;
  }, t.prototype.getValue = function() {
    var n = this, r = n.hasError, o = n.thrownError, i = n._value;
    if (r)
      throw o;
    return this._throwIfClosed(), i;
  }, t.prototype.next = function(n) {
    e.prototype.next.call(this, this._value = n);
  }, t;
}(ee), Mr = new k(function(e) {
  return e.complete();
});
function Ir(e) {
  return e && M(e.schedule);
}
function Kt(e) {
  return e[e.length - 1];
}
function at(e) {
  return Ir(Kt(e)) ? e.pop() : void 0;
}
function Dr(e, t) {
  return typeof Kt(e) == "number" ? e.pop() : t;
}
var Qt = function(e) {
  return e && typeof e.length == "number" && typeof e != "function";
};
function Xt(e) {
  return M(e == null ? void 0 : e.then);
}
function qt(e) {
  return M(e[st]);
}
function Zt(e) {
  return Symbol.asyncIterator && M(e == null ? void 0 : e[Symbol.asyncIterator]);
}
function en(e) {
  return new TypeError("You provided " + (e !== null && typeof e == "object" ? "an invalid object" : "'" + e + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
}
function Rr() {
  return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
}
var tn = Rr();
function nn(e) {
  return M(e == null ? void 0 : e[tn]);
}
function rn(e) {
  return yr(this, arguments, function() {
    var n, r, o, i;
    return Wt(this, function(s) {
      switch (s.label) {
        case 0:
          n = e.getReader(), s.label = 1;
        case 1:
          s.trys.push([1, , 9, 10]), s.label = 2;
        case 2:
          return [4, fe(n.read())];
        case 3:
          return r = s.sent(), o = r.value, i = r.done, i ? [4, fe(void 0)] : [3, 5];
        case 4:
          return [2, s.sent()];
        case 5:
          return [4, fe(o)];
        case 6:
          return [4, s.sent()];
        case 7:
          return s.sent(), [3, 2];
        case 8:
          return [3, 10];
        case 9:
          return n.releaseLock(), [7];
        case 10:
          return [2];
      }
    });
  });
}
function on(e) {
  return M(e == null ? void 0 : e.getReader);
}
function te(e) {
  if (e instanceof k)
    return e;
  if (e != null) {
    if (qt(e))
      return Nr(e);
    if (Qt(e))
      return Ur(e);
    if (Xt(e))
      return Fr(e);
    if (Zt(e))
      return sn(e);
    if (nn(e))
      return $r(e);
    if (on(e))
      return jr(e);
  }
  throw en(e);
}
function Nr(e) {
  return new k(function(t) {
    var n = e[st]();
    if (M(n.subscribe))
      return n.subscribe(t);
    throw new TypeError("Provided object does not correctly implement Symbol.observable");
  });
}
function Ur(e) {
  return new k(function(t) {
    for (var n = 0; n < e.length && !t.closed; n++)
      t.next(e[n]);
    t.complete();
  });
}
function Fr(e) {
  return new k(function(t) {
    e.then(function(n) {
      t.closed || (t.next(n), t.complete());
    }, function(n) {
      return t.error(n);
    }).then(null, Yt);
  });
}
function $r(e) {
  return new k(function(t) {
    var n, r;
    try {
      for (var o = he(e), i = o.next(); !i.done; i = o.next()) {
        var s = i.value;
        if (t.next(s), t.closed)
          return;
      }
    } catch (a) {
      n = { error: a };
    } finally {
      try {
        i && !i.done && (r = o.return) && r.call(o);
      } finally {
        if (n) throw n.error;
      }
    }
    t.complete();
  });
}
function sn(e) {
  return new k(function(t) {
    Br(e, t).catch(function(n) {
      return t.error(n);
    });
  });
}
function jr(e) {
  return sn(rn(e));
}
function Br(e, t) {
  var n, r, o, i;
  return br(this, void 0, void 0, function() {
    var s, a;
    return Wt(this, function(c) {
      switch (c.label) {
        case 0:
          c.trys.push([0, 5, 6, 11]), n = wr(e), c.label = 1;
        case 1:
          return [4, n.next()];
        case 2:
          if (r = c.sent(), !!r.done) return [3, 4];
          if (s = r.value, t.next(s), t.closed)
            return [2];
          c.label = 3;
        case 3:
          return [3, 1];
        case 4:
          return [3, 11];
        case 5:
          return a = c.sent(), o = { error: a }, [3, 11];
        case 6:
          return c.trys.push([6, , 9, 10]), r && !r.done && (i = n.return) ? [4, i.call(n)] : [3, 8];
        case 7:
          c.sent(), c.label = 8;
        case 8:
          return [3, 10];
        case 9:
          if (o) throw o.error;
          return [7];
        case 10:
          return [7];
        case 11:
          return t.complete(), [2];
      }
    });
  });
}
function ne(e, t, n, r, o) {
  r === void 0 && (r = 0), o === void 0 && (o = !1);
  var i = t.schedule(function() {
    n(), o ? e.add(this.schedule(null, r)) : this.unsubscribe();
  }, r);
  if (e.add(i), !o)
    return i;
}
function an(e, t) {
  return t === void 0 && (t = 0), Y(function(n, r) {
    n.subscribe(J(r, function(o) {
      return ne(r, e, function() {
        return r.next(o);
      }, t);
    }, function() {
      return ne(r, e, function() {
        return r.complete();
      }, t);
    }, function(o) {
      return ne(r, e, function() {
        return r.error(o);
      }, t);
    }));
  });
}
function cn(e, t) {
  return t === void 0 && (t = 0), Y(function(n, r) {
    r.add(e.schedule(function() {
      return n.subscribe(r);
    }, t));
  });
}
function Wr(e, t) {
  return te(e).pipe(cn(t), an(t));
}
function Vr(e, t) {
  return te(e).pipe(cn(t), an(t));
}
function Hr(e, t) {
  return new k(function(n) {
    var r = 0;
    return t.schedule(function() {
      r === e.length ? n.complete() : (n.next(e[r++]), n.closed || this.schedule());
    });
  });
}
function zr(e, t) {
  return new k(function(n) {
    var r;
    return ne(n, t, function() {
      r = e[tn](), ne(n, t, function() {
        var o, i, s;
        try {
          o = r.next(), i = o.value, s = o.done;
        } catch (a) {
          n.error(a);
          return;
        }
        s ? n.complete() : n.next(i);
      }, 0, !0);
    }), function() {
      return M(r == null ? void 0 : r.return) && r.return();
    };
  });
}
function un(e, t) {
  if (!e)
    throw new Error("Iterable cannot be null");
  return new k(function(n) {
    ne(n, t, function() {
      var r = e[Symbol.asyncIterator]();
      ne(n, t, function() {
        r.next().then(function(o) {
          o.done ? n.complete() : n.next(o.value);
        });
      }, 0, !0);
    });
  });
}
function Yr(e, t) {
  return un(rn(e), t);
}
function Gr(e, t) {
  if (e != null) {
    if (qt(e))
      return Wr(e, t);
    if (Qt(e))
      return Hr(e, t);
    if (Xt(e))
      return Vr(e, t);
    if (Zt(e))
      return un(e, t);
    if (nn(e))
      return zr(e, t);
    if (on(e))
      return Yr(e, t);
  }
  throw en(e);
}
function ln(e, t) {
  return t ? Gr(e, t) : te(e);
}
function O(e, t) {
  return Y(function(n, r) {
    var o = 0;
    n.subscribe(J(r, function(i) {
      r.next(e.call(t, i, o++));
    }));
  });
}
function Jr(e, t, n, r, o, i, s, a) {
  var c = [], u = 0, l = 0, f = !1, v = function() {
    f && !c.length && !u && t.complete();
  }, d = function(p) {
    return u < r ? g(p) : c.push(p);
  }, g = function(p) {
    u++;
    var b = !1;
    te(n(p, l++)).subscribe(J(t, function(h) {
      t.next(h);
    }, function() {
      b = !0;
    }, void 0, function() {
      if (b)
        try {
          u--;
          for (var h = function() {
            var C = c.shift();
            s || g(C);
          }; c.length && u < r; )
            h();
          v();
        } catch (C) {
          t.error(C);
        }
    }));
  };
  return e.subscribe(J(t, d, function() {
    f = !0, v();
  })), function() {
  };
}
function fn(e, t, n) {
  return n === void 0 && (n = 1 / 0), M(t) ? fn(function(r, o) {
    return O(function(i, s) {
      return t(r, i, o, s);
    })(te(e(r, o)));
  }, n) : (typeof t == "number" && (n = t), Y(function(r, o) {
    return Jr(r, o, e, n);
  }));
}
function dn(e) {
  return e === void 0 && (e = 1 / 0), fn(Gt, e);
}
function Kr() {
  return dn(1);
}
function Ze() {
  for (var e = [], t = 0; t < arguments.length; t++)
    e[t] = arguments[t];
  return Kr()(ln(e, at(e)));
}
function Qr() {
  for (var e = [], t = 0; t < arguments.length; t++)
    e[t] = arguments[t];
  var n = at(e), r = Dr(e, 1 / 0), o = e;
  return o.length ? o.length === 1 ? te(o[0]) : dn(r)(ln(o, n)) : Mr;
}
function ct(e, t) {
  return Y(function(n, r) {
    var o = 0;
    n.subscribe(J(r, function(i) {
      return e.call(t, i, o++) && r.next(i);
    }));
  });
}
function Xr(e, t, n, r, o) {
  return function(i, s) {
    var a = n, c = t, u = 0;
    i.subscribe(J(s, function(l) {
      var f = u++;
      c = a ? e(c, l, f) : (a = !0, l), s.next(c);
    }, o));
  };
}
function qr(e) {
  return Y(function(t, n) {
    try {
      t.subscribe(n);
    } finally {
      n.add(e);
    }
  });
}
function Zr(e, t) {
  return Y(Xr(e, t, arguments.length >= 2, !0));
}
function N() {
  for (var e = [], t = 0; t < arguments.length; t++)
    e[t] = arguments[t];
  var n = at(e);
  return Y(function(r, o) {
    (n ? Ze(e, r, n) : Ze(e, r)).subscribe(o);
  });
}
function pn(e, t) {
  return Y(function(n, r) {
    var o = null, i = 0, s = !1, a = function() {
      return s && !o && r.complete();
    };
    n.subscribe(J(r, function(c) {
      o == null || o.unsubscribe();
      var u = 0, l = i++;
      te(e(c, l)).subscribe(o = J(r, function(f) {
        return r.next(t ? t(c, f, l, u++) : f);
      }, function() {
        o = null, a();
      }));
    }, function() {
      s = !0, a();
    }));
  });
}
function yt(e) {
  return Y(function(t, n) {
    te(e).subscribe(J(n, function() {
      return n.complete();
    }, Xe)), !n.closed && t.subscribe(n);
  });
}
var eo = Object.defineProperty, to = Object.defineProperties, no = Object.getOwnPropertyDescriptors, wt = Object.getOwnPropertySymbols, ro = Object.prototype.hasOwnProperty, oo = Object.prototype.propertyIsEnumerable, St = (e, t, n) => t in e ? eo(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, G = (e, t) => {
  for (var n in t || (t = {}))
    ro.call(t, n) && St(e, n, t[n]);
  if (wt)
    for (var n of wt(t))
      oo.call(t, n) && St(e, n, t[n]);
  return e;
}, we = (e, t) => to(e, no(t)), j = (e, t, n) => new Promise((r, o) => {
  var i = (c) => {
    try {
      a(n.next(c));
    } catch (u) {
      o(u);
    }
  }, s = (c) => {
    try {
      a(n.throw(c));
    } catch (u) {
      o(u);
    }
  }, a = (c) => c.done ? r(c.value) : Promise.resolve(c.value).then(i, s);
  a((n = n.apply(e, t)).next());
}), hn = "lk";
function $(e) {
  return typeof e > "u" ? !1 : io(e) || so(e);
}
function io(e) {
  var t;
  return e ? e.hasOwnProperty("participant") && e.hasOwnProperty("source") && e.hasOwnProperty("track") && typeof ((t = e.publication) == null ? void 0 : t.track) < "u" : !1;
}
function so(e) {
  return e ? e.hasOwnProperty("participant") && e.hasOwnProperty("source") && e.hasOwnProperty("publication") && typeof e.publication < "u" : !1;
}
function xe(e) {
  return e ? e.hasOwnProperty("participant") && e.hasOwnProperty("source") && typeof e.publication > "u" : !1;
}
function U(e) {
  if (typeof e == "string" || typeof e == "number")
    return `${e}`;
  if (xe(e))
    return `${e.participant.identity}_${e.source}_placeholder`;
  if ($(e))
    return `${e.participant.identity}_${e.publication.source}_${e.publication.trackSid}`;
  throw new Error(`Can't generate a id for the given track reference: ${e}`);
}
function Zo(e, t) {
  return e === void 0 || t === void 0 ? !1 : $(e) && $(t) ? e.publication.trackSid === t.publication.trackSid : U(e) === U(t);
}
function ei(e, t) {
  return typeof t > "u" ? !1 : $(e) ? t.some(
    (n) => n.participant.identity === e.participant.identity && $(n) && n.publication.trackSid === e.publication.trackSid
  ) : xe(e) ? t.some(
    (n) => n.participant.identity === e.participant.identity && xe(n) && n.source === e.source
  ) : !1;
}
function ao(e, t) {
  return xe(e) && $(t) && t.participant.identity === e.participant.identity && t.source === e.source;
}
function ti() {
  const e = document.createElement("p");
  e.style.width = "100%", e.style.height = "200px";
  const t = document.createElement("div");
  t.style.position = "absolute", t.style.top = "0px", t.style.left = "0px", t.style.visibility = "hidden", t.style.width = "200px", t.style.height = "150px", t.style.overflow = "hidden", t.appendChild(e), document.body.appendChild(t);
  const n = e.offsetWidth;
  t.style.overflow = "scroll";
  let r = e.offsetWidth;
  return n === r && (r = t.clientWidth), document.body.removeChild(t), n - r;
}
function ni() {
  return typeof document < "u";
}
function co(e) {
  e = G({}, e);
  const t = "(?:(?:[a-z]+:)?//)?", n = "(?:\\S+(?::\\S*)?@)?", r = new RegExp(
    "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",
    "g"
  ).source, u = `(?:${t}|www\\.)${n}(?:localhost|${r}|(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#][^\\s"]*)?`;
  return e.exact ? new RegExp(`(?:^${u}$)`, "i") : new RegExp(u, "ig");
}
var xt = "[^\\.\\s@:](?:[^\\s@:]*[^\\s@:\\.])?@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*";
function uo({ exact: e } = {}) {
  return e ? new RegExp(`^${xt}$`) : new RegExp(xt, "g");
}
function ri(e, t) {
  return j(this, null, function* () {
    const { x: n, y: r } = yield pr(e, t, {
      placement: "top",
      middleware: [lr(6), dr(), fr({ padding: 5 })]
    });
    return { x: n, y: r };
  });
}
function oi(e, t) {
  return !e.contains(t.target);
}
var ii = () => ({
  email: uo(),
  url: co({})
});
function si(e, t) {
  const n = Object.entries(t).map(
    ([i, s], a) => Array.from(e.matchAll(s)).map(({ index: c, 0: u }) => ({
      type: i,
      weight: a,
      content: u,
      index: c ?? 0
    }))
  ).flat().sort((i, s) => {
    const a = i.index - s.index;
    return a !== 0 ? a : i.weight - s.weight;
  }).filter(({ index: i }, s, a) => {
    if (s === 0) return !0;
    const c = a[s - 1];
    return c.index + c.content.length <= i;
  }), r = [];
  let o = 0;
  for (const { type: i, content: s, index: a } of n)
    a > o && r.push(e.substring(o, a)), r.push({ type: i, content: s }), o = a + s.length;
  return e.length > o && r.push(e.substring(o)), r;
}
var lo = [
  m.ConnectionStateChanged,
  m.RoomMetadataChanged,
  m.ActiveSpeakersChanged,
  m.ConnectionQualityChanged,
  m.ParticipantConnected,
  m.ParticipantDisconnected,
  m.ParticipantPermissionsChanged,
  m.ParticipantMetadataChanged,
  m.ParticipantNameChanged,
  m.ParticipantAttributesChanged,
  m.TrackMuted,
  m.TrackUnmuted,
  m.TrackPublished,
  m.TrackUnpublished,
  m.TrackStreamStateChanged,
  m.TrackSubscriptionFailed,
  m.TrackSubscriptionPermissionChanged,
  m.TrackSubscriptionStatusChanged
], vn = [
  ...lo,
  m.LocalTrackPublished,
  m.LocalTrackUnpublished
], fo = [
  y.TrackPublished,
  y.TrackUnpublished,
  y.TrackMuted,
  y.TrackUnmuted,
  y.TrackStreamStateChanged,
  y.TrackSubscribed,
  y.TrackUnsubscribed,
  y.TrackSubscriptionPermissionChanged,
  y.TrackSubscriptionFailed,
  y.LocalTrackPublished,
  y.LocalTrackUnpublished
], po = [
  y.ConnectionQualityChanged,
  y.IsSpeakingChanged,
  y.ParticipantMetadataChanged,
  y.ParticipantPermissionsChanged,
  y.TrackMuted,
  y.TrackUnmuted,
  y.TrackPublished,
  y.TrackUnpublished,
  y.TrackStreamStateChanged,
  y.TrackSubscriptionFailed,
  y.TrackSubscriptionPermissionChanged,
  y.TrackSubscriptionStatusChanged
], gn = [
  ...po,
  y.LocalTrackPublished,
  y.LocalTrackUnpublished
], ai = [
  {
    columns: 1,
    rows: 1
  },
  {
    columns: 1,
    rows: 2,
    orientation: "portrait"
  },
  {
    columns: 2,
    rows: 1,
    orientation: "landscape"
  },
  {
    columns: 2,
    rows: 2,
    minWidth: 560
  },
  {
    columns: 3,
    rows: 3,
    minWidth: 700
  },
  {
    columns: 4,
    rows: 4,
    minWidth: 960
  },
  {
    columns: 5,
    rows: 5,
    minWidth: 1100
  }
], ho = [
  { condition: (e) => e === 1 },
  {
    condition: (e) => e === 2,
    wrapperStyle: {
      gridTemplateColumns: "1fr 1fr",
      width: "100%",
      height: "28.3vw"
    }
  },
  {
    condition: (e) => e === 3,
    wrapperStyle: {
      gridTemplateColumns: "repeat(4, 1fr)",
      gridTemplateRows: "1fr 1fr",
      width: "100%",
      height: "56.25vw"
    },
    gridColumns: ["1 / 3", "3 / 5", "2 / 4"]
  },
  {
    condition: (e) => e === 4,
    wrapperStyle: {
      gridTemplateColumns: "1fr 1fr",
      gridTemplateRows: "1fr 1fr",
      width: "100%",
      height: "56.25vw"
    }
  },
  {
    condition: (e) => e === 5,
    wrapperStyle: {
      gridTemplateColumns: "repeat(6, 1fr)",
      gridTemplateRows: "1fr 1fr",
      height: "56.25vw"
    },
    gridColumns: ["1 / 4", "4 / 7", "1 / 3", "3 / 5", "5 / 7"]
  },
  {
    condition: (e) => e === 6,
    wrapperStyle: {
      gridTemplateColumns: "repeat(3, 1fr)",
      gridTemplateRows: "1fr 1fr",
      height: "50vw"
    }
  },
  {
    condition: (e) => e === 7,
    wrapperStyle: {
      gridTemplateColumns: "repeat(12, 1fr)",
      gridTemplateRows: "1fr 1fr",
      height: "50vw"
    },
    gridColumns: ["1 / 5", "5 / 9", "9 / 13", "1 / 4", "4 / 7", "7 / 10", "10 / 13"]
  },
  {
    condition: (e) => e === 8,
    wrapperStyle: {
      gridTemplateColumns: "repeat(6, 1fr)",
      gridTemplateRows: "repeat(3, 1fr)",
      height: "100%"
    },
    gridColumns: ["1 / 3", "3 / 5", "5 / 7", "1 / 3", "3 / 5", "5 / 7", "2 / 4", "4 / 6"]
  },
  {
    condition: (e) => e === 9,
    wrapperStyle: {
      gridTemplateColumns: "repeat(3, 1fr)",
      gridTemplateRows: "repeat(3, 1fr)",
      height: "100%"
    }
  },
  {
    condition: (e) => e > 9,
    wrapperStyle: {
      gridTemplateColumns: "repeat(4, 1fr)",
      gridTemplateRows: "repeat(4, 1fr)",
      height: "100%"
    }
  }
];
function ci(e, t) {
  if (e.length < 1)
    throw new Error("At least one grid layout definition must be provided.");
  return ho.find((r) => r.condition(t));
}
function ui() {
  return typeof navigator < "u" && navigator.mediaDevices && !!navigator.mediaDevices.getDisplayMedia;
}
function li(e, t) {
  var n;
  return we(G({}, e), {
    receivedAtMediaTimestamp: (n = t.rtpTimestamp) != null ? n : 0,
    receivedAt: t.timestamp
  });
}
function fi(e, t, n) {
  return [...e, ...t].reduceRight((r, o) => (r.find((i) => i.id === o.id) || r.unshift(o), r), []).slice(0 - n);
}
var mn = [], bn = {
  showChat: !1,
  unreadMessages: 0,
  showSettings: !1
};
function vo(e) {
  return typeof e == "object";
}
function di(e) {
  return Array.isArray(e) && e.filter(vo).length > 0;
}
function go(e, t) {
  return e.isSpeaking === t.isSpeaking ? 0 : e.isSpeaking ? -1 : 1;
}
function yn(e, t) {
  var n, r, o, i;
  return e.lastSpokeAt !== void 0 || t.lastSpokeAt !== void 0 ? ((r = (n = t.lastSpokeAt) == null ? void 0 : n.getTime()) != null ? r : 0) - ((i = (o = e.lastSpokeAt) == null ? void 0 : o.getTime()) != null ? i : 0) : 0;
}
function Le(e, t) {
  var n, r, o, i;
  return ((r = (n = e.joinedAt) == null ? void 0 : n.getTime()) != null ? r : 0) - ((i = (o = t.joinedAt) == null ? void 0 : o.getTime()) != null ? i : 0);
}
function mo(e, t) {
  return $(e) ? $(t) ? 0 : -1 : $(t) ? 1 : 0;
}
function bo(e, t) {
  const n = e.participant.isCameraEnabled, r = t.participant.isCameraEnabled;
  return n !== r ? n ? -1 : 1 : 0;
}
function pi(e) {
  const t = [], n = [], r = [], o = [];
  e.forEach((a) => {
    a.participant.isLocal && a.source === A.Source.Camera ? t.push(a) : a.source === A.Source.ScreenShare ? n.push(a) : a.source === A.Source.Camera ? r.push(a) : o.push(a);
  });
  const i = wn(n), s = Sn(r);
  return [...t, ...i, ...s, ...o];
}
function wn(e) {
  const t = [], n = [];
  return e.forEach((o) => {
    o.participant.isLocal ? t.push(o) : n.push(o);
  }), t.sort((o, i) => Le(o.participant, i.participant)), n.sort((o, i) => Le(o.participant, i.participant)), [...n, ...t];
}
function Sn(e) {
  const t = [], n = [];
  return e.forEach((r) => {
    r.participant.isLocal ? t.push(r) : n.push(r);
  }), n.sort((r, o) => {
    const i = r.participant.videoTrackPublications.size > 0, s = o.participant.videoTrackPublications.size > 0;
    if (i !== s)
      return i ? -1 : 1;
    const a = r.participant.isMicrophoneEnabled, c = o.participant.isMicrophoneEnabled;
    return a !== c ? a ? -1 : 1 : r.participant.lastSpokeAt !== o.participant.lastSpokeAt ? yn(r.participant, o.participant) : $(r) !== $(o) ? mo(r, o) : r.participant.isCameraEnabled !== o.participant.isCameraEnabled ? bo(r, o) : Le(r.participant, o.participant);
  }), [...t, ...n];
}
var hi = (e, t) => {
  const n = [], r = [], o = [], i = [];
  e.forEach((c) => {
    c.participant.isLocal && c.source === A.Source.Camera ? n.push(c) : c.source === A.Source.ScreenShare || t && t.source === A.Source.ScreenShare && c.participant.identity === t.participant.identity ? r.push(c) : c.source === A.Source.Camera ? o.push(c) : i.push(c);
  });
  const s = wn(r), a = Sn(o);
  return [...n, ...s, ...a, ...i];
};
function vi(e) {
  const t = [...e];
  t.sort((r, o) => {
    const i = r.isScreenShareEnabled, s = o.isScreenShareEnabled;
    if (i !== s)
      return i ? -1 : 1;
    if (r.isSpeaking !== o.isSpeaking)
      return go(r, o);
    const a = r.videoTrackPublications.size > 0, c = o.videoTrackPublications.size > 0;
    if (a !== c)
      return a ? -1 : 1;
    const u = r.isMicrophoneEnabled, l = o.isMicrophoneEnabled;
    return u !== l ? u ? -1 : 1 : r.lastSpokeAt !== o.lastSpokeAt ? yn(r, o) : Le(r, o);
  });
  const n = t.find((r) => r.isLocal);
  if (n) {
    const r = t.indexOf(n);
    r >= 0 && (t.splice(r, 1), t.length > 0 ? t.splice(0, 0, n) : t.push(n));
  }
  return t;
}
function yo(e, t) {
  return e.reduce(
    (n, r, o) => o % t === 0 ? [...n, [r]] : [...n.slice(0, -1), [...n.slice(-1)[0], r]],
    []
  );
}
function Tt(e, t) {
  const n = Math.max(e.length, t.length);
  return new Array(n).fill([]).map((r, o) => [e[o], t[o]]);
}
function Me(e, t, n) {
  return e.filter((r) => !t.map((o) => n(o)).includes(n(r)));
}
var I = mr.getLogger("lk-components-js");
I.setDefaultLevel("WARN");
function gi(e, t = {}) {
  var n;
  I.setLevel(e), Mn((n = t.liveKitClientLogLevel) != null ? n : e);
}
function mi(e, t = {}) {
  var n;
  const r = I.methodFactory;
  I.methodFactory = (o, i, s) => {
    const a = r(o, i, s), c = ut[o], u = c >= i && c < ut.silent;
    return (l, f) => {
      f ? a(l, f) : a(l), u && e(c, l, f);
    };
  }, I.setLevel(I.getLevel()), In((n = t.liveKitClientLogExtension) != null ? n : e);
}
function et(e) {
  return e.map((t) => typeof t == "string" || typeof t == "number" ? `${t}` : U(t));
}
function wo(e, t) {
  return {
    dropped: Me(e, t, U),
    added: Me(t, e, U)
  };
}
function So(e) {
  return e.added.length !== 0 || e.dropped.length !== 0;
}
function tt(e, t) {
  const n = t.findIndex(
    (r) => U(r) === U(e)
  );
  if (n === -1)
    throw new Error(
      `Element not part of the array: ${U(
        e
      )} not in ${et(t)}`
    );
  return n;
}
function xo(e, t, n) {
  const r = tt(e, n), o = tt(t, n);
  return n.splice(r, 1, t), n.splice(o, 1, e), n;
}
function To(e, t) {
  const n = tt(e, t);
  return t.splice(n, 1), t;
}
function Co(e, t) {
  return [...t, e];
}
function We(e, t) {
  return yo(e, t);
}
function bi(e, t, n) {
  let r = Eo(e, t);
  if (r.length < t.length) {
    const s = Me(t, r, U);
    r = [...r, ...s];
  }
  const o = We(r, n), i = We(t, n);
  if (Tt(o, i).forEach(([s, a], c) => {
    if (s && a) {
      const u = We(r, n)[c], l = wo(u, a);
      So(l) && (I.debug(
        `Detected visual changes on page: ${c}, current: ${et(
          s
        )}, next: ${et(a)}`,
        { changes: l }
      ), l.added.length === l.dropped.length && Tt(l.added, l.dropped).forEach(([f, v]) => {
        if (f && v)
          r = xo(f, v, r);
        else
          throw new Error(
            `For a swap action we need a addition and a removal one is missing: ${f}, ${v}`
          );
      }), l.added.length === 0 && l.dropped.length > 0 && l.dropped.forEach((f) => {
        r = To(f, r);
      }), l.added.length > 0 && l.dropped.length === 0 && l.added.forEach((f) => {
        r = Co(f, r);
      }));
    }
  }), r.length > t.length) {
    const s = Me(r, t, U);
    r = r.filter(
      (a) => !s.map(U).includes(U(a))
    );
  }
  return r;
}
function Eo(e, t) {
  return e.map((n) => {
    const r = t.find(
      (o) => (
        // If the IDs match or ..
        U(n) === U(o) || // ... if the current item is a placeholder and the new item is the track reference can replace it.
        typeof n != "number" && xe(n) && $(o) && ao(n, o)
      )
    );
    return r ?? n;
  });
}
function R(e) {
  return `${hn}-${e}`;
}
function yi(e) {
  const t = Ct(e), n = xn(e.participant).pipe(
    O(() => Ct(e)),
    N(t)
  );
  return { className: R(
    e.source === A.Source.Camera || e.source === A.Source.ScreenShare ? "participant-media-video" : "participant-media-audio"
  ), trackObserver: n };
}
function Ct(e) {
  if ($(e))
    return e.publication;
  {
    const { source: t, name: n, participant: r } = e;
    if (t && n)
      return r.getTrackPublications().find((o) => o.source === t && o.trackName === n);
    if (n)
      return r.getTrackPublicationByName(n);
    if (t)
      return r.getTrackPublication(t);
    throw new Error("At least one of source and name needs to be defined");
  }
}
function oe(e, ...t) {
  return new k((r) => {
    const o = () => {
      r.next(e);
    };
    return t.forEach((s) => {
      e.on(s, o);
    }), () => {
      t.forEach((s) => {
        e.off(s, o);
      });
    };
  }).pipe(N(e));
}
function ie(e, t) {
  return new k((r) => {
    const o = (...s) => {
      r.next(s);
    };
    return e.on(t, o), () => {
      e.off(t, o);
    };
  });
}
function wi(e) {
  return ie(e, m.ConnectionStateChanged).pipe(
    O(([t]) => t),
    N(e.state)
  );
}
function Si(e) {
  return oe(
    e,
    m.RoomMetadataChanged,
    m.ConnectionStateChanged
  ).pipe(
    O((n) => ({ name: n.name, metadata: n.metadata }))
  );
}
function xi(e) {
  return ie(e, m.ActiveSpeakersChanged).pipe(
    O(([t]) => t)
  );
}
function Ti(e, t, n = !0) {
  var r;
  const o = () => j(this, null, function* () {
    try {
      const a = yield lt.getLocalDevices(e, n);
      i.next(a);
    } catch (a) {
      t == null || t(a);
    }
  }), i = new ee(), s = i.pipe(
    qr(() => {
      var a;
      (a = navigator == null ? void 0 : navigator.mediaDevices) == null || a.removeEventListener("devicechange", o);
    })
  );
  if (typeof window < "u") {
    if (!window.isSecureContext)
      throw new Error(
        "Accessing media devices is available only in secure contexts (HTTPS and localhost), in some or all supporting browsers. See: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mediaDevices"
      );
    (r = navigator == null ? void 0 : navigator.mediaDevices) == null || r.addEventListener("devicechange", o);
  }
  return Ze(
    lt.getLocalDevices(e, n).catch((a) => (t == null || t(a), [])),
    s
  );
}
function Po(e) {
  return ie(e, m.DataReceived);
}
function Oo(e) {
  return ie(e, m.ChatMessage);
}
function Ao(e) {
  return oe(e, m.AudioPlaybackStatusChanged).pipe(
    O((n) => ({ canPlayAudio: n.canPlaybackAudio }))
  );
}
function ko(e) {
  return oe(e, m.VideoPlaybackStatusChanged).pipe(
    O((n) => ({ canPlayVideo: n.canPlaybackVideo }))
  );
}
function _o(e, t) {
  return ie(e, m.ActiveDeviceChanged).pipe(
    ct(([n]) => n === t),
    O(([n, r]) => (I.debug("activeDeviceObservable | RoomEvent.ActiveDeviceChanged", { kind: n, deviceId: r }), r))
  );
}
function Ci(e, t) {
  return ie(e, m.ParticipantEncryptionStatusChanged).pipe(
    ct(
      ([, n]) => (t == null ? void 0 : t.identity) === (n == null ? void 0 : n.identity) || !n && (t == null ? void 0 : t.identity) === e.localParticipant.identity
    ),
    O(([n]) => n),
    N(
      t != null && t.isLocal ? t.isE2EEEnabled : !!(t != null && t.isEncrypted)
    )
  );
}
function Ei(e) {
  return ie(e, m.RecordingStatusChanged).pipe(
    O(([t]) => t),
    N(e.isRecording)
  );
}
function me(e, ...t) {
  return new k((r) => {
    const o = () => {
      r.next(e);
    };
    return t.forEach((s) => {
      e.on(s, o);
    }), () => {
      t.forEach((s) => {
        e.off(s, o);
      });
    };
  }).pipe(N(e));
}
function xn(e) {
  return me(
    e,
    y.TrackMuted,
    y.TrackUnmuted,
    y.ParticipantPermissionsChanged,
    // ParticipantEvent.IsSpeakingChanged,
    y.TrackPublished,
    y.TrackUnpublished,
    y.LocalTrackPublished,
    y.LocalTrackUnpublished,
    y.MediaDevicesError,
    y.TrackSubscriptionStatusChanged
    // ParticipantEvent.ConnectionQualityChanged,
  ).pipe(
    O((n) => {
      const { isMicrophoneEnabled: r, isCameraEnabled: o, isScreenShareEnabled: i } = n, s = n.getTrackPublication(A.Source.Microphone), a = n.getTrackPublication(A.Source.Camera);
      return {
        isCameraEnabled: o,
        isMicrophoneEnabled: r,
        isScreenShareEnabled: i,
        cameraTrack: a,
        microphoneTrack: s,
        participant: n
      };
    })
  );
}
function Lo(e) {
  return e ? me(
    e,
    y.ParticipantMetadataChanged,
    y.ParticipantNameChanged
  ).pipe(
    O(({ name: n, identity: r, metadata: o }) => ({
      name: n,
      identity: r,
      metadata: o
    })),
    N({
      name: e.name,
      identity: e.identity,
      metadata: e.metadata
    })
  ) : void 0;
}
function Mo(e) {
  return $e(
    e,
    y.ConnectionQualityChanged
  ).pipe(
    O(([n]) => n),
    N(e.connectionQuality)
  );
}
function $e(e, t) {
  return new k((r) => {
    const o = (...s) => {
      r.next(s);
    };
    return e.on(t, o), () => {
      e.off(t, o);
    };
  });
}
function Io(e) {
  var t, n, r, o;
  return me(
    e.participant,
    y.TrackMuted,
    y.TrackUnmuted,
    y.TrackSubscribed,
    y.TrackUnsubscribed,
    y.LocalTrackPublished,
    y.LocalTrackUnpublished
  ).pipe(
    O((i) => {
      var s, a;
      const c = (s = e.publication) != null ? s : i.getTrackPublication(e.source);
      return (a = c == null ? void 0 : c.isMuted) != null ? a : !0;
    }),
    N(
      (o = (r = (t = e.publication) == null ? void 0 : t.isMuted) != null ? r : (n = e.participant.getTrackPublication(e.source)) == null ? void 0 : n.isMuted) != null ? o : !0
    )
  );
}
function Pi(e) {
  return $e(e, y.IsSpeakingChanged).pipe(
    O(([t]) => t)
  );
}
function Oi(e, t = {}) {
  var n;
  let r;
  const o = new k((c) => (r = c, () => a.unsubscribe())).pipe(N(Array.from(e.remoteParticipants.values()))), i = (n = t.additionalRoomEvents) != null ? n : vn, s = Array.from(
    /* @__PURE__ */ new Set([
      m.ParticipantConnected,
      m.ParticipantDisconnected,
      m.ConnectionStateChanged,
      ...i
    ])
  ), a = oe(e, ...s).subscribe(
    (c) => r == null ? void 0 : r.next(Array.from(c.remoteParticipants.values()))
  );
  return e.remoteParticipants.size > 0 && (r == null || r.next(Array.from(e.remoteParticipants.values()))), o;
}
function Ai(e, t, n = {}) {
  var r;
  const o = (r = n.additionalEvents) != null ? r : gn;
  return oe(
    e,
    m.ParticipantConnected,
    m.ParticipantDisconnected,
    m.ConnectionStateChanged
  ).pipe(
    pn((s) => {
      const a = s.getParticipantByIdentity(t);
      return a ? me(a, ...o) : new k((c) => c.next(void 0));
    }),
    N(e.getParticipantByIdentity(t))
  );
}
function ki(e) {
  return $e(
    e,
    y.ParticipantPermissionsChanged
  ).pipe(
    O(() => e.permissions),
    N(e.permissions)
  );
}
function _i(e, { kind: t, identity: n }, r = {}) {
  var o;
  const i = (o = r.additionalEvents) != null ? o : gn, s = (c) => {
    let u = !0;
    return t && (u = u && c.kind === t), n && (u = u && c.identity === n), u;
  };
  return oe(
    e,
    m.ParticipantConnected,
    m.ParticipantDisconnected,
    m.ConnectionStateChanged
  ).pipe(
    pn((c) => {
      const u = Array.from(c.remoteParticipants.values()).find(
        (l) => s(l)
      );
      return u ? me(u, ...i) : new k((l) => l.next(void 0));
    }),
    N(Array.from(e.remoteParticipants.values()).find((c) => s(c)))
  );
}
function Li(e) {
  return typeof e > "u" ? new k() : $e(e, y.AttributesChanged).pipe(
    O(([t]) => ({
      changed: t,
      attributes: e.attributes
    })),
    N({ changed: e.attributes, attributes: e.attributes })
  );
}
function Mi(e, t, n, r, o) {
  const { localParticipant: i } = t, s = (f, v) => {
    let d = !1;
    switch (f) {
      case A.Source.Camera:
        d = v.isCameraEnabled;
        break;
      case A.Source.Microphone:
        d = v.isMicrophoneEnabled;
        break;
      case A.Source.ScreenShare:
        d = v.isScreenShareEnabled;
        break;
    }
    return d;
  }, a = xn(i).pipe(
    O((f) => s(e, f.participant)),
    N(s(e, i))
  ), c = new ee(), u = (f, v) => j(this, null, function* () {
    try {
      switch (v ?? (v = n), c.next(!0), e) {
        case A.Source.Camera:
          if (t.metadata && JSON.parse(t.metadata).canPublishVideo === !1) {
            const g = t.localParticipant.getTrackPublication(A.Source.Camera);
            if (!i.isCameraEnabled && !g)
              throw new Error("RATE_LIMIT");
          }
          return yield i.setCameraEnabled(
            f ?? !i.isCameraEnabled,
            v,
            r
          ), i.isCameraEnabled;
        case A.Source.Microphone:
          if (t.metadata && JSON.parse(t.metadata).canPublishAudio === !1) {
            const g = t.localParticipant.getTrackPublication(A.Source.Microphone);
            if (!i.isMicrophoneEnabled && !g)
              throw new Error("RATE_LIMIT");
          }
          return yield i.setMicrophoneEnabled(
            f ?? !i.isMicrophoneEnabled,
            v,
            r
          ), i.isMicrophoneEnabled;
        case A.Source.ScreenShare:
          return console.warn("do nothing, use custom screen share picker."), i.isScreenShareEnabled;
        default:
          throw new TypeError("Tried to toggle unsupported source");
      }
    } catch (d) {
      if (o && d instanceof Error) {
        o == null || o(d);
        return;
      } else
        throw d;
    } finally {
      c.next(!1);
    }
  });
  return {
    className: R("button"),
    toggle: u,
    enabledObserver: a,
    pendingObserver: c.asObservable()
  };
}
function Ii() {
  let e = !1;
  const t = new ee(), n = new ee(), r = (i) => j(this, null, function* () {
    n.next(!0), e = i ?? !e, t.next(e), n.next(!1);
  });
  return {
    className: R("button"),
    toggle: r,
    enabledObserver: t.asObservable(),
    pendingObserver: n.asObservable()
  };
}
function Di(e, t, n) {
  const r = new Jt(void 0), o = t ? _o(t, e) : r.asObservable(), i = (a, ...c) => j(this, [a, ...c], function* (u, l = {}) {
    var f, v, d;
    if (t) {
      I.debug(`Switching active device of kind "${e}" with id ${u}.`), yield t.switchActiveDevice(e, u, l.exact);
      const g = (f = t.getActiveDevice(e)) != null ? f : u;
      g !== u && u !== "default" && I.info(
        `We tried to select the device with id (${u}), but the browser decided to select the device with id (${g}) instead.`
      );
      let p;
      e === "audioinput" ? p = (v = t.localParticipant.getTrackPublication(A.Source.Microphone)) == null ? void 0 : v.track : e === "videoinput" && (p = (d = t.localParticipant.getTrackPublication(A.Source.Camera)) == null ? void 0 : d.track);
      const b = u === "default" && !p || u === "default" && (p == null ? void 0 : p.mediaStreamTrack.label.startsWith("Default"));
      r.next(b ? u : g);
    } else r.value !== u && (I.warn(
      "device switch skipped, please provide either a room or a local track to switch on. "
    ), r.next(u));
  });
  return {
    className: R("media-device-select"),
    activeDeviceObservable: o,
    setActiveMediaDevice: i
  };
}
function Ri(e) {
  const t = (r) => {
    e.disconnect(r);
  };
  return { className: R("disconnect-button"), disconnect: t };
}
function Ni(e) {
  const t = R("connection-quality"), n = Mo(e);
  return { className: t, connectionQualityObserver: n };
}
function Ui(e) {
  let t = "track-muted-indicator-camera";
  switch (e.source) {
    case A.Source.Camera:
      t = "track-muted-indicator-camera";
      break;
    case A.Source.Microphone:
      t = "track-muted-indicator-microphone";
      break;
  }
  const n = R(t), r = Io(e);
  return { className: n, mediaMutedObserver: r };
}
function Fi(e) {
  return { className: "lk-participant-name", infoObserver: Lo(e) };
}
function $i() {
  return {
    className: R("participant-tile")
  };
}
var Et = {
  CHAT: "lk-chat-topic",
  CHAT_UPDATE: "lk-chat-update-topic"
};
function nt(e, t) {
  return j(this, arguments, function* (n, r, o = {}) {
    const { reliable: i, destinationIdentities: s, topic: a } = o;
    yield n.publishData(r, {
      destinationIdentities: s,
      topic: a,
      reliable: i
    });
  });
}
function Do(e, t, n) {
  const r = Array.isArray(t) ? t : [t], o = Po(e).pipe(
    ct(
      ([, , , c]) => t === void 0 || c !== void 0 && r.includes(c)
    ),
    O(([c, u, , l]) => {
      const f = {
        payload: c,
        topic: l,
        from: u
      };
      return n == null || n(f), f;
    })
  );
  let i;
  const s = new k((c) => {
    i = c;
  });
  return { messageObservable: o, isSendingObservable: s, send: (c, ...u) => j(this, [c, ...u], function* (l, f = {}) {
    i.next(!0);
    try {
      yield nt(e.localParticipant, l, G({ topic: r[0] }, f));
    } finally {
      i.next(!1);
    }
  }) };
}
function Ro(e) {
  return { chatObservable: Oo(e), send: (o) => j(this, null, function* () {
    return yield e.localParticipant.sendChatMessage(o);
  }), edit: (o, i) => j(this, null, function* () {
    return yield e.localParticipant.editChatMessage(o, i);
  }) };
}
var No = new TextEncoder(), Uo = new TextDecoder(), Pe = /* @__PURE__ */ new Map(), Fo = (e) => No.encode(JSON.stringify(e)), $o = (e) => JSON.parse(Uo.decode(e));
function ji(e, t) {
  var n, r;
  const o = new ee(), i = () => {
    var E, S, L;
    return ((E = e.serverInfo) == null ? void 0 : E.edition) === 1 || !!((S = e.serverInfo) != null && S.version) && Dn((L = e.serverInfo) == null ? void 0 : L.version, "1.17.2") > 0;
  }, { messageDecoder: s, messageEncoder: a, channelTopic: c, updateChannelTopic: u } = t ?? {}, l = c ?? Et.CHAT, f = u ?? Et.CHAT_UPDATE;
  let v = !1;
  Pe.has(e) || (v = !0);
  const d = (n = Pe.get(e)) != null ? n : /* @__PURE__ */ new Map(), g = (r = d.get(l)) != null ? r : new ee();
  if (d.set(l, g), Pe.set(e, d), v) {
    const { messageObservable: E } = Do(e, [l, f]);
    E.pipe(yt(o)).subscribe(g);
  }
  const { chatObservable: p, send: b } = Ro(e), h = s ?? $o, C = Qr(
    g.pipe(
      O((E) => {
        const S = h(E.payload), L = we(G({}, S), { from: E.from });
        if (!jo(L))
          return L;
      })
    ),
    p.pipe(
      O(([E, S]) => we(G({}, E), { from: S }))
    )
  ).pipe(
    Zr((E, S) => {
      var L;
      if (!S)
        return E;
      if ("id" in S && E.find((w) => {
        var T, B;
        return ((T = w.from) == null ? void 0 : T.identity) === ((B = S.from) == null ? void 0 : B.identity) && w.id === S.id;
      })) {
        const w = E.findIndex((T) => T.id === S.id);
        if (w > -1) {
          const T = E[w];
          E[w] = we(G({}, S), {
            timestamp: T.timestamp,
            editTimestamp: (L = S.editTimestamp) != null ? L : S.timestamp
          });
        }
        return [...E];
      }
      return [...E, S];
    }, []),
    yt(o)
  ), P = new Jt(!1), _ = a ?? Fo, x = (E) => j(this, null, function* () {
    P.next(!0);
    try {
      const S = yield b(E), L = _(we(G({}, S), {
        ignore: i()
      }));
      return yield nt(e.localParticipant, L, {
        reliable: !0,
        topic: l
      }), S;
    } finally {
      P.next(!1);
    }
  }), se = (E, S) => j(this, null, function* () {
    const L = Date.now(), w = typeof S == "string" ? { id: S, message: "", timestamp: L } : S;
    P.next(!0);
    try {
      const T = yield e.localParticipant.editChatMessage(E, w), B = _(T);
      return yield nt(e.localParticipant, B, {
        topic: f,
        reliable: !0
      }), T;
    } finally {
      P.next(!1);
    }
  });
  function ae() {
    o.next(), o.complete(), Pe.delete(e);
  }
  return e.once(m.Disconnected, ae), {
    messageObservable: C,
    isSendingObservable: P,
    send: x,
    update: se
  };
}
function jo(e) {
  return e.ignore == !0;
}
function Bi() {
  const e = (n) => j(this, null, function* () {
    I.info("Start Audio for room: ", n), yield n.startAudio();
  });
  return { className: R("start-audio-button"), roomAudioPlaybackAllowedObservable: Ao, handleStartAudioPlayback: e };
}
function Wi() {
  const e = (n) => j(this, null, function* () {
    I.info("Start Video for room: ", n), yield n.startVideo();
  });
  return { className: R("start-audio-button"), roomVideoPlaybackAllowedObservable: ko, handleStartVideoPlayback: e };
}
function Vi() {
  return { className: [R("button"), R("chat-toggle")].join(" ") };
}
function Hi() {
  return { className: [R("button"), R("focus-toggle-button")].join(" ") };
}
function zi() {
  return { className: "lk-clear-pin-button lk-button" };
}
function Yi() {
  return { className: "lk-room-container" };
}
function Gi() {
  return { className: R("member-list-button") };
}
function Ji() {
  const e = () => {
  };
  return { className: R("back-to-main-button"), backToMain: e };
}
function Ki() {
  const e = () => {
  };
  return { className: R("raise-hand-button"), raiseHand: e };
}
function Pt(e, t, n = !0) {
  const o = [e.localParticipant, ...Array.from(e.remoteParticipants.values())], i = [];
  return o.forEach((s) => {
    t.forEach((a) => {
      const c = Array.from(
        s.trackPublications.values()
      ).filter(
        (u) => u.source === a && // either return all or only the ones that are subscribed
        (!n || u.track)
      ).map((u) => ({
        participant: s,
        publication: u,
        source: u.source
      }));
      i.push(...c);
    });
  }), { trackReferences: i, participants: o };
}
function Ot(e, t, n = !1) {
  const { sources: r, kind: o, name: i } = t;
  return Array.from(e.trackPublications.values()).filter(
    (a) => (!r || r.includes(a.source)) && (!o || a.kind === o) && (!i || a.trackName === i) && // either return all or only the ones that are subscribed
    (!n || a.track)
  ).map((a) => ({
    participant: e,
    publication: a,
    source: a.source
  }));
}
function Qi(e, t, n) {
  var r, o;
  const i = (r = n.additionalRoomEvents) != null ? r : vn, s = (o = n.onlySubscribed) != null ? o : !0, a = Array.from(
    (/* @__PURE__ */ new Set([
      m.ParticipantConnected,
      m.ParticipantDisconnected,
      m.ConnectionStateChanged,
      m.LocalTrackPublished,
      m.LocalTrackUnpublished,
      m.TrackPublished,
      m.TrackUnpublished,
      m.TrackSubscriptionStatusChanged,
      ...i
    ])).values()
  );
  return oe(e, ...a).pipe(
    O((u) => Pt(u, t, s)),
    N(Pt(e, t, s))
  );
}
function Xi(e, t) {
  return me(e, ...fo).pipe(
    O((r) => Ot(r, t)),
    N(Ot(e, t))
  );
}
function Tn(e, t) {
  return new k((r) => {
    const o = (...s) => {
      r.next(s);
    };
    return e.on(t, o), () => {
      e.off(t, o);
    };
  });
}
function qi(e) {
  return Tn(e, At.TranscriptionReceived);
}
function Zi(e) {
  return Tn(e, At.TimeSyncUpdate).pipe(
    O(([t]) => t)
  );
}
function Bo(e, t) {
  if (typeof localStorage > "u") {
    I.error("Local storage is not available.");
    return;
  }
  try {
    if (t) {
      const n = Object.fromEntries(
        Object.entries(t).filter(([, r]) => r !== "")
      );
      localStorage.setItem(e, JSON.stringify(n));
    }
  } catch (n) {
    I.error(`Error setting item to local storage: ${n}`);
  }
}
function Wo(e) {
  if (typeof localStorage > "u") {
    I.error("Local storage is not available.");
    return;
  }
  try {
    const t = localStorage.getItem(e);
    if (!t) {
      I.warn(`Item with key ${e} does not exist in local storage.`);
      return;
    }
    return JSON.parse(t);
  } catch (t) {
    I.error(`Error getting item from local storage: ${t}`);
    return;
  }
}
function Vo(e) {
  return {
    load: () => Wo(e),
    save: (t) => Bo(e, t)
  };
}
var Ho = `${hn}-user-choices`, ye = {
  videoEnabled: !0,
  audioEnabled: !0,
  videoDeviceId: "",
  audioDeviceId: "",
  username: ""
}, { load: zo, save: Yo } = Vo(Ho);
function es(e, t = !1) {
  t !== !0 && Yo(e);
}
function ts(e, t = !1) {
  var n, r, o, i, s;
  const a = {
    videoEnabled: (n = e == null ? void 0 : e.videoEnabled) != null ? n : ye.videoEnabled,
    audioEnabled: (r = e == null ? void 0 : e.audioEnabled) != null ? r : ye.audioEnabled,
    videoDeviceId: (o = e == null ? void 0 : e.videoDeviceId) != null ? o : ye.videoDeviceId,
    audioDeviceId: (i = e == null ? void 0 : e.audioDeviceId) != null ? i : ye.audioDeviceId,
    username: (s = e == null ? void 0 : e.username) != null ? s : ye.username
  };
  if (t)
    return a;
  {
    const c = zo();
    return G(G({}, a), c ?? {});
  }
}
function Cn(e, t) {
  if (t.msg === "show_chat")
    return { ...e, showChat: !0, unreadMessages: 0 };
  if (t.msg === "hide_chat")
    return { ...e, showChat: !1 };
  if (t.msg === "toggle_chat") {
    const n = { ...e, showChat: !e.showChat };
    return n.showChat === !0 && (n.unreadMessages = 0), n;
  } else return t.msg === "unread_msg" ? { ...e, unreadMessages: t.count } : t.msg === "toggle_settings" ? { ...e, showSettings: !e.showSettings } : { ...e };
}
function En(e, t) {
  return console.trace("pin update", t), t.msg === "set_pin" ? [t.trackReference] : t.msg === "clear_pin" ? [] : { ...e };
}
const Pn = D.createContext(void 0);
function ns() {
  const e = D.useContext(Pn);
  if (!e)
    throw Error("Tried to access LayoutContext context outside a LayoutContextProvider provider.");
  return e;
}
function rs(e) {
  const t = Go();
  if (e ?? (e = t), !e)
    throw Error("Tried to access LayoutContext context outside a LayoutContextProvider provider.");
  return e;
}
function os() {
  const [e, t] = D.useReducer(En, mn), [n, r] = D.useReducer(Cn, bn);
  return {
    pin: { dispatch: t, state: e },
    widget: { dispatch: r, state: n }
  };
}
function is(e) {
  const [t, n] = D.useReducer(En, mn), [r, o] = D.useReducer(Cn, bn);
  return e ?? {
    pin: { dispatch: n, state: t },
    widget: { dispatch: o, state: r }
  };
}
function Go() {
  return D.useContext(Pn);
}
const On = D.createContext(
  void 0
);
function ss() {
  const e = D.useContext(On);
  if (!e)
    throw Error("tried to access track context outside of track context provider");
  return e;
}
function An() {
  return D.useContext(On);
}
function as(e) {
  const t = An(), n = e ?? t;
  if (!n)
    throw new Error(
      "No TrackRef, make sure you are inside a TrackRefContext or pass the TrackRef explicitly"
    );
  return n;
}
const kn = D.createContext(void 0);
function cs() {
  const e = D.useContext(kn);
  if (!e)
    throw Error("tried to access participant context outside of participant context provider");
  return e;
}
function Jo() {
  return D.useContext(kn);
}
function us(e) {
  const t = Jo(), n = An(), r = e ?? t ?? (n == null ? void 0 : n.participant);
  if (!r)
    throw new Error(
      "No participant provided, make sure you are inside a participant context or pass the participant explicitly"
    );
  return r;
}
const _n = D.createContext(void 0);
function ls() {
  const e = D.useContext(_n);
  if (!e)
    throw Error("tried to access room context outside of livekit room component");
  return e;
}
function Ko() {
  return D.useContext(_n);
}
function fs(e) {
  const t = Ko(), n = e ?? t;
  if (!n)
    throw new Error(
      "No room provided, make sure you are inside a Room context or pass the room explicitly"
    );
  return n;
}
const Qo = D.createContext(void 0);
function ds(e) {
  const t = D.useContext(Qo);
  if (e === !0) {
    if (t)
      return t;
    throw Error("tried to access feature context, but none is present");
  }
  return t;
}
export {
  ts as $,
  pi as A,
  bi as B,
  Jo as C,
  Lo as D,
  $i as E,
  Oi as F,
  ai as G,
  rs as H,
  Ai as I,
  _i as J,
  Si as K,
  Qo as L,
  xi as M,
  vi as N,
  Bi as O,
  Wi as P,
  Vi as Q,
  _n as R,
  Ui as S,
  Mi as T,
  Ii as U,
  vo as V,
  Qi as W,
  di as X,
  Ct as Y,
  yi as Z,
  ji as _,
  ns as a,
  es as a0,
  Ci as a1,
  $ as a2,
  Xi as a3,
  Zi as a4,
  qi as a5,
  fi as a6,
  li as a7,
  Li as a8,
  Ei as a9,
  ss as aA,
  vr as aa,
  An as ab,
  Pn as ac,
  Fi as ad,
  hr as ae,
  kn as af,
  On as ag,
  qo as ah,
  hi as ai,
  ti as aj,
  is as ak,
  si as al,
  ii as am,
  ri as an,
  oi as ao,
  ye as ap,
  Gi as aq,
  Ji as ar,
  Ki as as,
  ui as at,
  os as au,
  Zo as av,
  ni as aw,
  gi as ax,
  mi as ay,
  cs as az,
  zi as b,
  us as c,
  Ni as d,
  wi as e,
  ls as f,
  Do as g,
  ds as h,
  Ri as i,
  as as j,
  Go as k,
  I as l,
  Hi as m,
  ei as n,
  ci as o,
  Io as p,
  U as q,
  Ao as r,
  Yi as s,
  Pi as t,
  fs as u,
  xn as v,
  ki as w,
  Ko as x,
  Ti as y,
  Di as z
};
//# sourceMappingURL=contexts-94kvHczU.mjs.map
