import { setLogLevel as Mn, LogLevel as ut, setLogExtension as Dn, Track as A, RoomEvent as m, ParticipantEvent as y, Room as lt, TrackEvent as At, compareVersions as Rn } 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
}), Nn = {
  left: "right",
  right: "left",
  bottom: "top",
  top: "bottom"
}, Un = {
  start: "end",
  end: "start"
};
function ft(e, t, n) {
  return ue(e, Ve(t, n));
}
function Me(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 Fn(e, t, n) {
  n === void 0 && (n = !1);
  const r = De(e), o = Lt(e), i = _t(o);
  let a = o === "x" ? r === (n ? "end" : "start") ? "right" : "left" : r === "start" ? "bottom" : "top";
  return t.reference[i] > t.floating[i] && (a = ke(a)), [a, ke(a)];
}
function $n(e) {
  const t = ke(e);
  return [He(e), t, He(t)];
}
function He(e) {
  return e.replace(/start|end/g, (t) => Un[t]);
}
function jn(e, t, n) {
  const r = ["left", "right"], o = ["right", "left"], i = ["top", "bottom"], a = ["bottom", "top"];
  switch (e) {
    case "top":
    case "bottom":
      return n ? t ? o : r : t ? r : o;
    case "left":
    case "right":
      return t ? i : a;
    default:
      return [];
  }
}
function Bn(e, t, n, r) {
  const o = De(e);
  let i = jn(re(e), n === "start", r);
  return o && (i = i.map((a) => a + "-" + o), t && (i = i.concat(i.map(He)))), i;
}
function ke(e) {
  return e.replace(/left|right|bottom|top/g, (t) => Nn[t]);
}
function Wn(e) {
  return {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    ...e
  };
}
function Vn(e) {
  return typeof e != "number" ? Wn(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), a = Lt(t), s = _t(a), 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[s] / 2 - o[s] / 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[a] -= v * (n && u ? -1 : 1);
      break;
    case "end":
      d[a] += v * (n && u ? -1 : 1);
      break;
  }
  return d;
}
const Hn = async (e, t, n) => {
  const {
    placement: r = "bottom",
    strategy: o = "absolute",
    middleware: i = [],
    platform: a
  } = n, s = i.filter(Boolean), c = await (a.isRTL == null ? void 0 : a.isRTL(t));
  let u = await a.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 < s.length; p++) {
    const {
      name: b,
      fn: h
    } = s[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: a,
      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 a.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 It(e, t) {
  var n;
  t === void 0 && (t = {});
  const {
    x: r,
    y: o,
    platform: i,
    rects: a,
    elements: s,
    strategy: c
  } = e, {
    boundary: u = "clippingAncestors",
    rootBoundary: l = "viewport",
    elementContext: f = "floating",
    altBoundary: v = !1,
    padding: d = 0
  } = Me(t, e), g = Vn(d), b = s[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(s.floating)),
    boundary: u,
    rootBoundary: l,
    strategy: c
  })), C = f === "floating" ? {
    x: r,
    y: o,
    width: a.floating.width,
    height: a.floating.height
  } : a.reference, P = await (i.getOffsetParent == null ? void 0 : i.getOffsetParent(s.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: s,
    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 zn = function(e) {
  return e === void 0 && (e = {}), {
    name: "flip",
    options: e,
    async fn(t) {
      var n, r;
      const {
        placement: o,
        middlewareData: i,
        rects: a,
        initialPlacement: s,
        platform: c,
        elements: u
      } = t, {
        mainAxis: l = !0,
        crossAxis: f = !0,
        fallbackPlacements: v,
        fallbackStrategy: d = "bestFit",
        fallbackAxisSideDirection: g = "none",
        flipAlignment: p = !0,
        ...b
      } = Me(e, t);
      if ((n = i.arrow) != null && n.alignmentOffset)
        return {};
      const h = re(o), C = de(s), P = re(s) === s, _ = await (c.isRTL == null ? void 0 : c.isRTL(u.floating)), x = v || (P || !p ? [ke(s)] : $n(s)), ae = g !== "none";
      !v && ae && x.push(...Bn(s, p, g, _));
      const se = [s, ...x], E = await It(t, b), S = [];
      let L = ((r = i.flip) == null ? void 0 : r.overflows) || [];
      if (l && S.push(E[h]), f) {
        const H = Fn(o, a, _);
        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 = se[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 (ae) {
                  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, In) => X + In, 0)]).sort((Q, X) => Q[1] - X[1])[0]) == null ? void 0 : B[0];
              ce && (be = ce);
              break;
            }
            case "initialPlacement":
              be = s;
              break;
          }
        if (o !== be)
          return {
            reset: {
              placement: be
            }
          };
      }
      return {};
    }
  };
};
async function Yn(e, t) {
  const {
    placement: n,
    platform: r,
    elements: o
  } = e, i = await (r.isRTL == null ? void 0 : r.isRTL(o.floating)), a = re(n), s = De(n), c = de(n) === "y", u = ["left", "top"].includes(a) ? -1 : 1, l = i && c ? -1 : 1, f = Me(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 s && typeof g == "number" && (d = s === "end" ? g * -1 : g), c ? {
    x: d * l,
    y: v * u
  } : {
    x: v * u,
    y: d * l
  };
}
const Gn = function(e) {
  return e === void 0 && (e = 0), {
    name: "offset",
    options: e,
    async fn(t) {
      var n, r;
      const {
        x: o,
        y: i,
        placement: a,
        middlewareData: s
      } = t, c = await Yn(t, e);
      return a === ((n = s.offset) == null ? void 0 : n.placement) && (r = s.arrow) != null && r.alignmentOffset ? {} : {
        x: o + c.x,
        y: i + c.y,
        data: {
          ...c,
          placement: a
        }
      };
    }
  };
}, Jn = 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: a = !1,
        limiter: s = {
          fn: (b) => {
            let {
              x: h,
              y: C
            } = b;
            return {
              x: h,
              y: C
            };
          }
        },
        ...c
      } = Me(e, t), u = {
        x: n,
        y: r
      }, l = await It(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 (a) {
        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 = s.fn({
        ...t,
        [v]: d,
        [f]: g
      });
      return {
        ...p,
        data: {
          x: p.x - n,
          y: p.y - r,
          enabled: {
            [v]: i,
            [f]: a
          }
        }
      };
    }
  };
};
function Re() {
  return typeof window < "u";
}
function ve(e) {
  return Mt(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 = (Mt(e) ? e.ownerDocument : e.document) || window.document) == null ? void 0 : t.documentElement;
}
function Mt(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 Kn(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 Qn(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), a = F(o);
  return i ? (ze(a), t.concat(a, a.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, a = o ? e.offsetHeight : r, s = Ae(n) !== i || Ae(r) !== a;
  return s && (n = i, r = a), {
    width: n,
    height: r,
    $: s
  };
}
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 a = (i ? Ae(n.width) : n.width) / r, s = (i ? Ae(n.height) : n.height) / o;
  return (!a || !Number.isFinite(a)) && (a = 1), (!s || !Number.isFinite(s)) && (s = 1), {
    x: a,
    y: s
  };
}
const Xn = /* @__PURE__ */ q(0);
function Ft(e) {
  const t = F(e);
  return !ot() || !t.visualViewport ? Xn : {
    x: t.visualViewport.offsetLeft,
    y: t.visualViewport.offsetTop
  };
}
function qn(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 a = q(1);
  t && (r ? W(r) && (a = le(r)) : a = le(e));
  const s = qn(i, n, r) ? Ft(i) : q(0);
  let c = (o.left + s.x) / a.x, u = (o.top + s.y) / a.y, l = o.width / a.x, f = o.height / a.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 Zn(e) {
  let {
    elements: t,
    rect: n,
    offsetParent: r,
    strategy: o
  } = e;
  const i = o === "fixed", a = K(r), s = t ? Ne(t.floating) : !1;
  if (r === a || s && 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(a)) && (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 er(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 tr(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 a = -n.scrollLeft + Ye(e);
  const s = -n.scrollTop;
  return V(r).direction === "rtl" && (a += ue(t.clientWidth, r.clientWidth) - o), {
    width: o,
    height: i,
    x: a,
    y: s
  };
}
function nr(e, t) {
  const n = F(e), r = K(e), o = n.visualViewport;
  let i = r.clientWidth, a = r.clientHeight, s = 0, c = 0;
  if (o) {
    i = o.width, a = o.height;
    const u = ot();
    (!u || u && t === "fixed") && (s = o.offsetLeft, c = o.offsetTop);
  }
  return {
    width: i,
    height: a,
    x: s,
    y: c
  };
}
function rr(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), a = e.clientWidth * i.x, s = e.clientHeight * i.y, c = o * i.x, u = r * i.y;
  return {
    width: a,
    height: s,
    x: c,
    y: u
  };
}
function ht(e, t, n) {
  let r;
  if (t === "viewport")
    r = nr(e, n);
  else if (t === "document")
    r = tr(K(e));
  else if (W(t))
    r = rr(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 or(e, t) {
  const n = t.get(e);
  if (n)
    return n;
  let r = Rt(e, []).filter((s) => W(s) && ve(s) !== "body"), o = null;
  const i = V(e).position === "fixed";
  let a = i ? Z(e) : e;
  for (; W(a) && !pe(a); ) {
    const s = V(a), c = rt(a);
    !c && s.position === "fixed" && (o = null), (i ? !c && !o : !c && s.position === "static" && !!o && ["absolute", "fixed"].includes(o.position) || Te(a) && !c && $t(e, a)) ? r = r.filter((l) => l !== a) : o = s, a = Z(a);
  }
  return t.set(e, r), r;
}
function ir(e) {
  let {
    element: t,
    boundary: n,
    rootBoundary: r,
    strategy: o
  } = e;
  const a = [...n === "clippingAncestors" ? Ne(t) ? [] : or(t, this._c) : [].concat(n), r], s = a[0], c = a.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, s, o));
  return {
    width: c.right - c.left,
    height: c.bottom - c.top,
    x: c.left,
    y: c.top
  };
}
function ar(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", a = Se(e, !0, i, t);
  let s = {
    scrollLeft: 0,
    scrollTop: 0
  };
  const c = q(0);
  if (r || !r && !i)
    if ((ve(t) !== "body" || Te(o)) && (s = 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 + s.scrollTop, u = d.left + s.scrollLeft - // RTL <body> scrollbar.
    Ye(o, d);
  }
  const f = a.left + s.scrollLeft - c.x - u, v = a.top + s.scrollTop - c.y - l;
  return {
    x: f,
    y: v,
    width: a.width,
    height: a.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 && Kn(r) && je(r); )
    r = vt(r, t);
  return r && pe(r) && je(r) && !rt(r) ? n : r || Qn(e) || n;
}
const cr = 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 ur(e) {
  return V(e).direction === "rtl";
}
const lr = {
  convertOffsetParentRelativeRectToViewportRelativeRect: Zn,
  getDocumentElement: K,
  getClippingRect: ir,
  getOffsetParent: jt,
  getElementRects: cr,
  getClientRects: er,
  getDimensions: ar,
  getScale: le,
  isElement: W,
  isRTL: ur
}, fr = Gn, dr = Jn, pr = zn, hr = (e, t, n) => {
  const r = /* @__PURE__ */ new Map(), o = {
    platform: lr,
    ...n
  }, i = {
    ...o.platform,
    _c: r
  };
  return Hn(e, t, {
    ...o,
    platform: i
  });
};
var vr = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function gr(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();
  })(vr, 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 = {}, a = null;
    function s(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 ? s(console, p) : console.log !== void 0 ? s(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 ae(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 se() {
        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 && ae(_), l.call(h);
      }, h.setDefaultLevel = function(w) {
        P = S(w), se() || 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 (a !== h && (C = S(a.getLevel())), l.call(h), a === h)
          for (var w in i)
            i[w].rebuild();
      }, C = S(
        a ? a.getLevel() : "WARN"
      );
      var L = se();
      L != null && (_ = S(L)), l.call(h);
    }
    a = new d(), a.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,
        a.methodFactory
      )), h;
    };
    var g = typeof window !== n ? window.log : void 0;
    return a.noConflict = function() {
      return typeof window !== n && window.log === a && (window.log = g), a;
    }, a.getLoggers = function() {
      return i;
    }, a.default = a, a;
  });
})(Bt);
var mr = Bt.exports;
const br = /* @__PURE__ */ gr(mr);
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 yr(e, t, n, r) {
  function o(i) {
    return i instanceof n ? i : new n(function(a) {
      a(i);
    });
  }
  return new (n || (n = Promise))(function(i, a) {
    function s(l) {
      try {
        u(r.next(l));
      } catch (f) {
        a(f);
      }
    }
    function c(l) {
      try {
        u(r.throw(l));
      } catch (f) {
        a(f);
      }
    }
    function u(l) {
      l.done ? i(l.value) : o(l.value).then(s, 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, a = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
  return a.next = s(0), a.throw = s(1), a.return = s(2), typeof Symbol == "function" && (a[Symbol.iterator] = function() {
    return this;
  }), a;
  function s(u) {
    return function(l) {
      return c([u, l]);
    };
  }
  function c(u) {
    if (r) throw new TypeError("Generator is already executing.");
    for (; a && (a = 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 = [], a;
  try {
    for (; (t === void 0 || t-- > 0) && !(o = r.next()).done; ) i.push(o.value);
  } catch (s) {
    a = { error: s };
  } finally {
    try {
      o && !o.done && (n = r.return) && n.call(r);
    } finally {
      if (a) throw a.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 wr(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), s("next"), s("throw"), s("return", a), o[Symbol.asyncIterator] = function() {
    return this;
  }, o;
  function a(d) {
    return function(g) {
      return Promise.resolve(g).then(d, f);
    };
  }
  function s(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 Sr(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(a) {
      return new Promise(function(s, c) {
        a = e[i](a), o(s, c, a.done, a.value);
      });
    };
  }
  function o(i, a, s, c) {
    Promise.resolve(c).then(function(u) {
      i({ value: u, done: s });
    }, a);
  }
}
function I(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 a = this._parentage;
      if (a)
        if (this._parentage = null, Array.isArray(a))
          try {
            for (var s = he(a), c = s.next(); !c.done; c = s.next()) {
              var u = c.value;
              u.remove(this);
            }
          } catch (p) {
            t = { error: p };
          } finally {
            try {
              c && !c.done && (n = s.return) && n.call(s);
            } finally {
              if (t) throw t.error;
            }
          }
        else
          a.remove(this);
      var l = this.initialTeardown;
      if (I(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 && I(e.remove) && I(e.add) && I(e.unsubscribe);
}
function gt(e) {
  I(e) ? e() : e.unsubscribe();
}
var xr = {
  Promise: void 0
}, Tr = {
  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) {
  Tr.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 = Pr, 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), Cr = 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, a;
    return I(n) || !n ? a = {
      next: n ?? void 0,
      error: r ?? void 0,
      complete: o ?? void 0
    } : a = n, i.destination = new Cr(a), i;
  }
  return t;
}(it);
function Ee(e) {
  Yt(e);
}
function Er(e) {
  throw e;
}
var Pr = {
  closed: !0,
  next: Xe,
  error: Er,
  complete: Xe
}, at = function() {
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
}();
function Gt(e) {
  return e;
}
function Or(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 = kr(t) ? t : new qe(t, n, r);
    return Oe(function() {
      var a = o, s = a.operator, c = a.source;
      i.add(s ? s.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 a = new qe({
        next: function(s) {
          try {
            t(s);
          } catch (c) {
            i(c), a.unsubscribe();
          }
        },
        error: i,
        complete: o
      });
      r.subscribe(a);
    });
  }, e.prototype._subscribe = function(t) {
    var n;
    return (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t);
  }, e.prototype[at] = function() {
    return this;
  }, e.prototype.pipe = function() {
    for (var t = [], n = 0; n < arguments.length; n++)
      t[n] = arguments[n];
    return Or(t)(this);
  }, e.prototype.toPromise = function(t) {
    var n = this;
    return t = mt(t), new t(function(r, o) {
      var i;
      n.subscribe(function(a) {
        return i = a;
      }, function(a) {
        return o(a);
      }, function() {
        return r(i);
      });
    });
  }, e.create = function(t) {
    return new e(t);
  }, e;
}();
function mt(e) {
  var t;
  return (t = e ?? xr.Promise) !== null && t !== void 0 ? t : Promise;
}
function Ar(e) {
  return e && I(e.next) && I(e.error) && I(e.complete);
}
function kr(e) {
  return e && e instanceof it || Ar(e) && zt(e);
}
function _r(e) {
  return I(e == null ? void 0 : e.lift);
}
function Y(e) {
  return function(t) {
    if (_r(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 Lr(e, t, n, r, o);
}
var Lr = function(e) {
  ge(t, e);
  function t(n, r, o, i, a, s) {
    var c = e.call(this, n) || this;
    return c.onFinalize = a, c.shouldUnsubscribe = s, 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), Ir = 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 Ir();
  }, 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 a = he(r.currentObservers), s = a.next(); !s.done; s = a.next()) {
            var c = s.value;
            c.next(n);
          }
        } catch (u) {
          o = { error: u };
        } finally {
          try {
            s && !s.done && (i = a.return) && i.call(a);
          } 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, a = o.isStopped, s = o.observers;
    return i || a ? Ht : (this.currentObservers = null, s.push(n), new Fe(function() {
      r.currentObservers = null, Qe(s, n);
    }));
  }, t.prototype._checkFinalizedStatuses = function(n) {
    var r = this, o = r.hasError, i = r.thrownError, a = r.isStopped;
    o ? n.error(i) : a && 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 Dr(e) {
  return e && I(e.schedule);
}
function Kt(e) {
  return e[e.length - 1];
}
function st(e) {
  return Dr(Kt(e)) ? e.pop() : void 0;
}
function Rr(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 I(e == null ? void 0 : e.then);
}
function qt(e) {
  return I(e[at]);
}
function Zt(e) {
  return Symbol.asyncIterator && I(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 Nr() {
  return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
}
var tn = Nr();
function nn(e) {
  return I(e == null ? void 0 : e[tn]);
}
function rn(e) {
  return wr(this, arguments, function() {
    var n, r, o, i;
    return Wt(this, function(a) {
      switch (a.label) {
        case 0:
          n = e.getReader(), a.label = 1;
        case 1:
          a.trys.push([1, , 9, 10]), a.label = 2;
        case 2:
          return [4, fe(n.read())];
        case 3:
          return r = a.sent(), o = r.value, i = r.done, i ? [4, fe(void 0)] : [3, 5];
        case 4:
          return [2, a.sent()];
        case 5:
          return [4, fe(o)];
        case 6:
          return [4, a.sent()];
        case 7:
          return a.sent(), [3, 2];
        case 8:
          return [3, 10];
        case 9:
          return n.releaseLock(), [7];
        case 10:
          return [2];
      }
    });
  });
}
function on(e) {
  return I(e == null ? void 0 : e.getReader);
}
function te(e) {
  if (e instanceof k)
    return e;
  if (e != null) {
    if (qt(e))
      return Ur(e);
    if (Qt(e))
      return Fr(e);
    if (Xt(e))
      return $r(e);
    if (Zt(e))
      return an(e);
    if (nn(e))
      return jr(e);
    if (on(e))
      return Br(e);
  }
  throw en(e);
}
function Ur(e) {
  return new k(function(t) {
    var n = e[at]();
    if (I(n.subscribe))
      return n.subscribe(t);
    throw new TypeError("Provided object does not correctly implement Symbol.observable");
  });
}
function Fr(e) {
  return new k(function(t) {
    for (var n = 0; n < e.length && !t.closed; n++)
      t.next(e[n]);
    t.complete();
  });
}
function $r(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 jr(e) {
  return new k(function(t) {
    var n, r;
    try {
      for (var o = he(e), i = o.next(); !i.done; i = o.next()) {
        var a = i.value;
        if (t.next(a), t.closed)
          return;
      }
    } catch (s) {
      n = { error: s };
    } finally {
      try {
        i && !i.done && (r = o.return) && r.call(o);
      } finally {
        if (n) throw n.error;
      }
    }
    t.complete();
  });
}
function an(e) {
  return new k(function(t) {
    Wr(e, t).catch(function(n) {
      return t.error(n);
    });
  });
}
function Br(e) {
  return an(rn(e));
}
function Wr(e, t) {
  var n, r, o, i;
  return yr(this, void 0, void 0, function() {
    var a, s;
    return Wt(this, function(c) {
      switch (c.label) {
        case 0:
          c.trys.push([0, 5, 6, 11]), n = Sr(e), c.label = 1;
        case 1:
          return [4, n.next()];
        case 2:
          if (r = c.sent(), !!r.done) return [3, 4];
          if (a = r.value, t.next(a), t.closed)
            return [2];
          c.label = 3;
        case 3:
          return [3, 1];
        case 4:
          return [3, 11];
        case 5:
          return s = c.sent(), o = { error: s }, [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 sn(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 Vr(e, t) {
  return te(e).pipe(cn(t), sn(t));
}
function Hr(e, t) {
  return te(e).pipe(cn(t), sn(t));
}
function zr(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 Yr(e, t) {
  return new k(function(n) {
    var r;
    return ne(n, t, function() {
      r = e[tn](), ne(n, t, function() {
        var o, i, a;
        try {
          o = r.next(), i = o.value, a = o.done;
        } catch (s) {
          n.error(s);
          return;
        }
        a ? n.complete() : n.next(i);
      }, 0, !0);
    }), function() {
      return I(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 Gr(e, t) {
  return un(rn(e), t);
}
function Jr(e, t) {
  if (e != null) {
    if (qt(e))
      return Vr(e, t);
    if (Qt(e))
      return zr(e, t);
    if (Xt(e))
      return Hr(e, t);
    if (Zt(e))
      return un(e, t);
    if (nn(e))
      return Yr(e, t);
    if (on(e))
      return Gr(e, t);
  }
  throw en(e);
}
function ln(e, t) {
  return t ? Jr(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 Kr(e, t, n, r, o, i, a, s) {
  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();
            a || 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), I(t) ? fn(function(r, o) {
    return O(function(i, a) {
      return t(r, i, o, a);
    })(te(e(r, o)));
  }, n) : (typeof t == "number" && (n = t), Y(function(r, o) {
    return Kr(r, o, e, n);
  }));
}
function dn(e) {
  return e === void 0 && (e = 1 / 0), fn(Gt, e);
}
function Qr() {
  return dn(1);
}
function Ze() {
  for (var e = [], t = 0; t < arguments.length; t++)
    e[t] = arguments[t];
  return Qr()(ln(e, st(e)));
}
function Xr() {
  for (var e = [], t = 0; t < arguments.length; t++)
    e[t] = arguments[t];
  var n = st(e), r = Rr(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 qr(e, t, n, r, o) {
  return function(i, a) {
    var s = n, c = t, u = 0;
    i.subscribe(J(a, function(l) {
      var f = u++;
      c = s ? e(c, l, f) : (s = !0, l), a.next(c);
    }, o));
  };
}
function Zr(e) {
  return Y(function(t, n) {
    try {
      t.subscribe(n);
    } finally {
      n.add(e);
    }
  });
}
function eo(e, t) {
  return Y(qr(e, t, arguments.length >= 2, !0));
}
function R() {
  for (var e = [], t = 0; t < arguments.length; t++)
    e[t] = arguments[t];
  var n = st(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, a = !1, s = function() {
      return a && !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, s();
      }));
    }, function() {
      a = !0, s();
    }));
  });
}
function yt(e) {
  return Y(function(t, n) {
    te(e).subscribe(J(n, function() {
      return n.complete();
    }, Xe)), !n.closed && t.subscribe(n);
  });
}
var to = Object.defineProperty, no = Object.defineProperties, ro = Object.getOwnPropertyDescriptors, wt = Object.getOwnPropertySymbols, oo = Object.prototype.hasOwnProperty, io = Object.prototype.propertyIsEnumerable, St = (e, t, n) => t in e ? to(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, G = (e, t) => {
  for (var n in t || (t = {}))
    oo.call(t, n) && St(e, n, t[n]);
  if (wt)
    for (var n of wt(t))
      io.call(t, n) && St(e, n, t[n]);
  return e;
}, we = (e, t) => no(e, ro(t)), j = (e, t, n) => new Promise((r, o) => {
  var i = (c) => {
    try {
      s(n.next(c));
    } catch (u) {
      o(u);
    }
  }, a = (c) => {
    try {
      s(n.throw(c));
    } catch (u) {
      o(u);
    }
  }, s = (c) => c.done ? r(c.value) : Promise.resolve(c.value).then(i, a);
  s((n = n.apply(e, t)).next());
}), hn = "lk";
function $(e) {
  return typeof e > "u" ? !1 : ao(e) || so(e);
}
function ao(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 co(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 uo(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 lo({ 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 hr(e, t, {
      placement: "top",
      middleware: [fr(6), pr(), dr({ padding: 5 })]
    });
    return { x: n, y: r };
  });
}
function oi(e, t) {
  return !e.contains(t.target);
}
var ii = () => ({
  email: lo(),
  url: uo({})
});
function ai(e, t) {
  const n = Object.entries(t).map(
    ([i, a], s) => Array.from(e.matchAll(a)).map(({ index: c, 0: u }) => ({
      type: i,
      weight: s,
      content: u,
      index: c ?? 0
    }))
  ).flat().sort((i, a) => {
    const s = i.index - a.index;
    return s !== 0 ? s : i.weight - a.weight;
  }).filter(({ index: i }, a, s) => {
    if (a === 0) return !0;
    const c = s[a - 1];
    return c.index + c.content.length <= i;
  }), r = [];
  let o = 0;
  for (const { type: i, content: a, index: s } of n)
    s > o && r.push(e.substring(o, s)), r.push({ type: i, content: a }), o = s + a.length;
  return e.length > o && r.push(e.substring(o)), r;
}
var fo = [
  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 = [
  ...fo,
  m.LocalTrackPublished,
  m.LocalTrackUnpublished
], po = [
  y.TrackPublished,
  y.TrackUnpublished,
  y.TrackMuted,
  y.TrackUnmuted,
  y.TrackStreamStateChanged,
  y.TrackSubscribed,
  y.TrackUnsubscribed,
  y.TrackSubscriptionPermissionChanged,
  y.TrackSubscriptionFailed,
  y.LocalTrackPublished,
  y.LocalTrackUnpublished
], ho = [
  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 = [
  ...ho,
  y.LocalTrackPublished,
  y.LocalTrackUnpublished
], si = [
  {
    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
  }
], vo = [
  { 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 vo.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 go(e) {
  return typeof e == "object";
}
function di(e) {
  return Array.isArray(e) && e.filter(go).length > 0;
}
function yn(e, t) {
  return e.isSpeaking === t.isSpeaking ? 0 : e.isSpeaking ? -1 : 1;
}
function wn(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((s) => {
    s.participant.isLocal && s.source === A.Source.Camera ? t.push(s) : s.source === A.Source.ScreenShare ? n.push(s) : s.source === A.Source.Camera ? r.push(s) : o.push(s);
  });
  const i = Sn(n), a = xn(r);
  return [...t, ...i, ...a, ...o];
}
function Sn(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 xn(e) {
  const t = [], n = [];
  return e.forEach((r) => {
    r.participant.isLocal ? t.push(r) : n.push(r);
  }), n.sort((r, o) => r.participant.isSpeaking !== o.participant.isSpeaking ? yn(r.participant, o.participant) : r.participant.lastSpokeAt !== o.participant.lastSpokeAt ? wn(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 a = Sn(r), s = xn(o);
  return [...n, ...a, ...s, ...i];
};
function vi(e) {
  const t = [...e];
  t.sort((r, o) => {
    const i = r.isScreenShareEnabled, a = o.isScreenShareEnabled;
    if (i !== a)
      return i ? -1 : 1;
    if (r.isSpeaking !== o.isSpeaking)
      return yn(r, o);
    if (r.lastSpokeAt !== o.lastSpokeAt)
      return wn(r, o);
    const s = r.videoTrackPublications.size > 0, c = o.videoTrackPublications.size > 0;
    return s !== c ? s ? -1 : 1 : 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 Ie(e, t, n) {
  return e.filter((r) => !t.map((o) => n(o)).includes(n(r)));
}
var M = br.getLogger("lk-components-js");
M.setDefaultLevel("WARN");
function gi(e, t = {}) {
  var n;
  M.setLevel(e), Mn((n = t.liveKitClientLogLevel) != null ? n : e);
}
function mi(e, t = {}) {
  var n;
  const r = M.methodFactory;
  M.methodFactory = (o, i, a) => {
    const s = r(o, i, a), c = ut[o], u = c >= i && c < ut.silent;
    return (l, f) => {
      f ? s(l, f) : s(l), u && e(c, l, f);
    };
  }, M.setLevel(M.getLevel()), Dn((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: Ie(e, t, U),
    added: Ie(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 a = Ie(t, r, U);
    r = [...r, ...a];
  }
  const o = We(r, n), i = We(t, n);
  if (Tt(o, i).forEach(([a, s], c) => {
    if (a && s) {
      const u = We(r, n)[c], l = wo(u, s);
      So(l) && (M.debug(
        `Detected visual changes on page: ${c}, current: ${et(
          a
        )}, next: ${et(s)}`,
        { 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 a = Ie(r, t, U);
    r = r.filter(
      (s) => !a.map(U).includes(U(s))
    );
  }
  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) && co(n, o)
      )
    );
    return r ?? n;
  });
}
function N(e) {
  return `${hn}-${e}`;
}
function yi(e) {
  const t = Ct(e), n = Tn(e.participant).pipe(
    O(() => Ct(e)),
    R(t)
  );
  return { className: N(
    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((a) => {
      e.on(a, o);
    }), () => {
      t.forEach((a) => {
        e.off(a, o);
      });
    };
  }).pipe(R(e));
}
function ie(e, t) {
  return new k((r) => {
    const o = (...a) => {
      r.next(a);
    };
    return e.on(t, o), () => {
      e.off(t, o);
    };
  });
}
function wi(e) {
  return ie(e, m.ConnectionStateChanged).pipe(
    O(([t]) => t),
    R(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 s = yield lt.getLocalDevices(e, n);
      i.next(s);
    } catch (s) {
      t == null || t(s);
    }
  }), i = new ee(), a = i.pipe(
    Zr(() => {
      var s;
      (s = navigator == null ? void 0 : navigator.mediaDevices) == null || s.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((s) => (t == null || t(s), [])),
    a
  );
}
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]) => (M.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),
    R(
      t != null && t.isLocal ? t.isE2EEEnabled : !!(t != null && t.isEncrypted)
    )
  );
}
function Ei(e) {
  return ie(e, m.RecordingStatusChanged).pipe(
    O(([t]) => t),
    R(e.isRecording)
  );
}
function me(e, ...t) {
  return new k((r) => {
    const o = () => {
      r.next(e);
    };
    return t.forEach((a) => {
      e.on(a, o);
    }), () => {
      t.forEach((a) => {
        e.off(a, o);
      });
    };
  }).pipe(R(e));
}
function Tn(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, a = n.getTrackPublication(A.Source.Microphone), s = n.getTrackPublication(A.Source.Camera);
      return {
        isCameraEnabled: o,
        isMicrophoneEnabled: r,
        isScreenShareEnabled: i,
        cameraTrack: s,
        microphoneTrack: a,
        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
    })),
    R({
      name: e.name,
      identity: e.identity,
      metadata: e.metadata
    })
  ) : void 0;
}
function Io(e) {
  return $e(
    e,
    y.ConnectionQualityChanged
  ).pipe(
    O(([n]) => n),
    R(e.connectionQuality)
  );
}
function $e(e, t) {
  return new k((r) => {
    const o = (...a) => {
      r.next(a);
    };
    return e.on(t, o), () => {
      e.off(t, o);
    };
  });
}
function Mo(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 a, s;
      const c = (a = e.publication) != null ? a : i.getTrackPublication(e.source);
      return (s = c == null ? void 0 : c.isMuted) != null ? s : !0;
    }),
    R(
      (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, () => s.unsubscribe())).pipe(R(Array.from(e.remoteParticipants.values()))), i = (n = t.additionalRoomEvents) != null ? n : vn, a = Array.from(
    /* @__PURE__ */ new Set([
      m.ParticipantConnected,
      m.ParticipantDisconnected,
      m.ConnectionStateChanged,
      ...i
    ])
  ), s = oe(e, ...a).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((a) => {
      const s = a.getParticipantByIdentity(t);
      return s ? me(s, ...o) : new k((c) => c.next(void 0));
    }),
    R(e.getParticipantByIdentity(t))
  );
}
function ki(e) {
  return $e(
    e,
    y.ParticipantPermissionsChanged
  ).pipe(
    O(() => e.permissions),
    R(e.permissions)
  );
}
function _i(e, { kind: t, identity: n }, r = {}) {
  var o;
  const i = (o = r.additionalEvents) != null ? o : gn, a = (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) => a(l)
      );
      return u ? me(u, ...i) : new k((l) => l.next(void 0));
    }),
    R(Array.from(e.remoteParticipants.values()).find((c) => a(c)))
  );
}
function Li(e) {
  return typeof e > "u" ? new k() : $e(e, y.AttributesChanged).pipe(
    O(([t]) => ({
      changed: t,
      attributes: e.attributes
    })),
    R({ changed: e.attributes, attributes: e.attributes })
  );
}
function Ii(e, t, n, r, o) {
  const { localParticipant: i } = t, a = (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;
  }, s = Tn(i).pipe(
    O((f) => a(e, f.participant)),
    R(a(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: N("button"),
    toggle: u,
    enabledObserver: s,
    pendingObserver: c.asObservable()
  };
}
function Mi() {
  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: N("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 = (s, ...c) => j(this, [s, ...c], function* (u, l = {}) {
    var f, v, d;
    if (t) {
      M.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" && M.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 && (M.warn(
      "device switch skipped, please provide either a room or a local track to switch on. "
    ), r.next(u));
  });
  return {
    className: N("media-device-select"),
    activeDeviceObservable: o,
    setActiveMediaDevice: i
  };
}
function Ri(e) {
  const t = (r) => {
    e.disconnect(r);
  };
  return { className: N("disconnect-button"), disconnect: t };
}
function Ni(e) {
  const t = N("connection-quality"), n = Io(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 = N(t), r = Mo(e);
  return { className: n, mediaMutedObserver: r };
}
function Fi(e) {
  return { className: "lk-participant-name", infoObserver: Lo(e) };
}
function $i() {
  return {
    className: N("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: a, topic: s } = o;
    yield n.publishData(r, {
      destinationIdentities: a,
      topic: s,
      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 a = new k((c) => {
    i = c;
  });
  return { messageObservable: o, isSendingObservable: a, 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) && Rn((L = e.serverInfo) == null ? void 0 : L.version, "1.17.2") > 0;
  }, { messageDecoder: a, messageEncoder: s, 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 = a ?? $o, C = Xr(
    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(
    eo((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), _ = s ?? 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);
    }
  }), ae = (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 se() {
    o.next(), o.complete(), Pe.delete(e);
  }
  return e.once(m.Disconnected, se), {
    messageObservable: C,
    isSendingObservable: P,
    send: x,
    update: ae
  };
}
function jo(e) {
  return e.ignore == !0;
}
function Bi() {
  const e = (n) => j(this, null, function* () {
    M.info("Start Audio for room: ", n), yield n.startAudio();
  });
  return { className: N("start-audio-button"), roomAudioPlaybackAllowedObservable: Ao, handleStartAudioPlayback: e };
}
function Wi() {
  const e = (n) => j(this, null, function* () {
    M.info("Start Video for room: ", n), yield n.startVideo();
  });
  return { className: N("start-audio-button"), roomVideoPlaybackAllowedObservable: ko, handleStartVideoPlayback: e };
}
function Vi() {
  return { className: [N("button"), N("chat-toggle")].join(" ") };
}
function Hi() {
  return { className: [N("button"), N("focus-toggle-button")].join(" ") };
}
function zi() {
  return { className: "lk-clear-pin-button lk-button" };
}
function Yi() {
  return { className: "lk-room-container" };
}
function Gi() {
  const e = () => {
  };
  return { className: N("add-member-button"), addMember: e };
}
function Ji() {
  return { className: N("member-list-button") };
}
function Pt(e, t, n = !0) {
  const o = [e.localParticipant, ...Array.from(e.remoteParticipants.values())], i = [];
  return o.forEach((a) => {
    t.forEach((s) => {
      const c = Array.from(
        a.trackPublications.values()
      ).filter(
        (u) => u.source === s && // either return all or only the ones that are subscribed
        (!n || u.track)
      ).map((u) => ({
        participant: a,
        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(
    (s) => (!r || r.includes(s.source)) && (!o || s.kind === o) && (!i || s.trackName === i) && // either return all or only the ones that are subscribed
    (!n || s.track)
  ).map((s) => ({
    participant: e,
    publication: s,
    source: s.source
  }));
}
function Ki(e, t, n) {
  var r, o;
  const i = (r = n.additionalRoomEvents) != null ? r : vn, a = (o = n.onlySubscribed) != null ? o : !0, s = 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, ...s).pipe(
    O((u) => Pt(u, t, a)),
    R(Pt(e, t, a))
  );
}
function Qi(e, t) {
  return me(e, ...po).pipe(
    O((r) => Ot(r, t)),
    R(Ot(e, t))
  );
}
function Cn(e, t) {
  return new k((r) => {
    const o = (...a) => {
      r.next(a);
    };
    return e.on(t, o), () => {
      e.off(t, o);
    };
  });
}
function Xi(e) {
  return Cn(e, At.TranscriptionReceived);
}
function qi(e) {
  return Cn(e, At.TimeSyncUpdate).pipe(
    O(([t]) => t)
  );
}
function Bo(e, t) {
  if (typeof localStorage > "u") {
    M.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) {
    M.error(`Error setting item to local storage: ${n}`);
  }
}
function Wo(e) {
  if (typeof localStorage > "u") {
    M.error("Local storage is not available.");
    return;
  }
  try {
    const t = localStorage.getItem(e);
    if (!t) {
      M.warn(`Item with key ${e} does not exist in local storage.`);
      return;
    }
    return JSON.parse(t);
  } catch (t) {
    M.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 Zi(e, t = !1) {
  t !== !0 && Yo(e);
}
function ea(e, t = !1) {
  var n, r, o, i, a;
  const s = {
    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: (a = e == null ? void 0 : e.username) != null ? a : ye.username
  };
  if (t)
    return s;
  {
    const c = zo();
    return G(G({}, s), c ?? {});
  }
}
function En(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 Pn(e, t) {
  return console.trace("pin update", t), t.msg === "set_pin" ? [t.trackReference] : t.msg === "clear_pin" ? [] : { ...e };
}
const On = D.createContext(void 0);
function ta() {
  const e = D.useContext(On);
  if (!e)
    throw Error("Tried to access LayoutContext context outside a LayoutContextProvider provider.");
  return e;
}
function na(e) {
  const t = Go();
  if (e ?? (e = t), !e)
    throw Error("Tried to access LayoutContext context outside a LayoutContextProvider provider.");
  return e;
}
function ra() {
  const [e, t] = D.useReducer(Pn, mn), [n, r] = D.useReducer(En, bn);
  return {
    pin: { dispatch: t, state: e },
    widget: { dispatch: r, state: n }
  };
}
function oa(e) {
  const [t, n] = D.useReducer(Pn, mn), [r, o] = D.useReducer(En, bn);
  return e ?? {
    pin: { dispatch: n, state: t },
    widget: { dispatch: o, state: r }
  };
}
function Go() {
  return D.useContext(On);
}
const An = D.createContext(
  void 0
);
function ia() {
  const e = D.useContext(An);
  if (!e)
    throw Error("tried to access track context outside of track context provider");
  return e;
}
function kn() {
  return D.useContext(An);
}
function aa(e) {
  const t = kn(), 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 _n = D.createContext(void 0);
function sa() {
  const e = D.useContext(_n);
  if (!e)
    throw Error("tried to access participant context outside of participant context provider");
  return e;
}
function Jo() {
  return D.useContext(_n);
}
function ca(e) {
  const t = Jo(), n = kn(), 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 Ln = D.createContext(void 0);
function ua() {
  const e = D.useContext(Ln);
  if (!e)
    throw Error("tried to access room context outside of livekit room component");
  return e;
}
function Ko() {
  return D.useContext(Ln);
}
function la(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 fa(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 {
  ea as $,
  pi as A,
  bi as B,
  Jo as C,
  Lo as D,
  $i as E,
  Oi as F,
  si as G,
  na 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,
  Ln as R,
  Ui as S,
  Ii as T,
  Mi as U,
  go as V,
  Ki as W,
  di as X,
  Ct as Y,
  yi as Z,
  ji as _,
  ta as a,
  Zi as a0,
  Ci as a1,
  $ as a2,
  Qi as a3,
  qi as a4,
  Xi as a5,
  fi as a6,
  li as a7,
  Li as a8,
  Ei as a9,
  kn as aa,
  On as ab,
  Fi as ac,
  gr as ad,
  vr as ae,
  _n as af,
  An as ag,
  qo as ah,
  hi as ai,
  ti as aj,
  oa as ak,
  ai as al,
  ii as am,
  ri as an,
  oi as ao,
  ye as ap,
  Gi as aq,
  Ji as ar,
  ui as as,
  ra as at,
  Zo as au,
  ni as av,
  gi as aw,
  mi as ax,
  sa as ay,
  ia as az,
  zi as b,
  ca as c,
  Ni as d,
  wi as e,
  ua as f,
  Do as g,
  fa as h,
  Ri as i,
  aa as j,
  Go as k,
  M as l,
  Hi as m,
  ei as n,
  ci as o,
  Mo as p,
  U as q,
  Ao as r,
  Yi as s,
  Pi as t,
  la as u,
  Tn as v,
  ki as w,
  Ko as x,
  Ti as y,
  Di as z
};
//# sourceMappingURL=contexts-7Stj-u1L.mjs.map
