import * as e from "react";
import j, { useState as oe, useMemo as de } from "react";
import { c as Le, w as Re, r as De, m as xe, a as X } from "./room-C7g9NN9R.mjs";
import { C as Ae, S as Be, a as Oe, M as Q, b as _e, T as G, c as He, P as Ve, d as me, u as pe, e as he, f as $e, g as ae, h as Ue, i as ze, j as We, D as ne, k as le, l as qe, m as fe, L as se, G as Ee, n as Z, F as ve, o as ge, p as ke, R as Se, q as be, r as je, s as Ge, t as Ke, v as Je, w as ue, x as Qe, y as Ye, z as Xe, B as Ze } from "./components-npB4q5QB.mjs";
import { w as Fe, x as ce, y as et, a as tt, z as Ce, A as nt, B as ye, C as Ne, n as F, m as we, D as at } from "./hooks-D627_42a.mjs";
import { k as Pe, an as st, ao as ct, l as _, ap as it, a as rt, aq as ot, ar as lt, as as ut, h as J, at as dt, au as Te, a2 as K, av as Me, aw as Ie, f as mt } from "./contexts-94kvHczU.mjs";
import { Track as C, facingModeFromLocalTrack as pt, Mutex as ht, createLocalTracks as ft, createLocalVideoTrack as Et, VideoPresets as vt, createLocalAudioTrack as gt, ConnectionState as kt, RoomEvent as q } from "@cc-livekit/livekit-client";
function ie({
  messageFormatter: t,
  messageDecoder: a,
  messageEncoder: s,
  channelTopic: n,
  ...l
}) {
  const u = e.useRef(null), m = e.useRef(null), v = e.useMemo(() => ({ messageDecoder: a, messageEncoder: s, channelTopic: n }), [a, s, n]), { send: c, chatMessages: d, isSending: p } = Fe(v), S = Pe(), g = e.useRef(0);
  async function i(r) {
    r.preventDefault(), u.current && u.current.value.trim() !== "" && c && (await c(u.current.value), u.current.value = "", u.current.focus());
  }
  return e.useEffect(() => {
    var r;
    m && ((r = m.current) == null || r.scrollTo({ top: m.current.scrollHeight }));
  }, [m, d]), e.useEffect(() => {
    var f, N, E, b, y;
    if (!S || d.length === 0)
      return;
    if ((f = S.widget.state) != null && f.showChat && d.length > 0 && g.current !== ((N = d[d.length - 1]) == null ? void 0 : N.timestamp)) {
      g.current = (E = d[d.length - 1]) == null ? void 0 : E.timestamp;
      return;
    }
    const r = d.filter(
      (x) => !g.current || x.timestamp > g.current
    ).length, { widget: o } = S;
    r > 0 && ((b = o.state) == null ? void 0 : b.unreadMessages) !== r && ((y = o.dispatch) == null || y.call(o, { msg: "unread_msg", count: r }));
  }, [d, S == null ? void 0 : S.widget]), /* @__PURE__ */ e.createElement("div", { ...l, className: "lk-chat" }, /* @__PURE__ */ e.createElement("div", { className: "lk-chat-header" }, "Messages", S && /* @__PURE__ */ e.createElement(Ae, { className: "lk-close-button" }, /* @__PURE__ */ e.createElement(Be, null))), /* @__PURE__ */ e.createElement("ul", { className: "lk-list lk-chat-messages", ref: m }, l.children ? d.map(
    (r, o) => Le(l.children, {
      entry: r,
      key: r.id ?? o,
      messageFormatter: t
    })
  ) : d.map((r, o, f) => {
    const N = o >= 1 && f[o - 1].from === r.from, E = o >= 1 && r.timestamp - f[o - 1].timestamp < 6e4;
    return /* @__PURE__ */ e.createElement(
      Oe,
      {
        key: r.id ?? o,
        hideName: N,
        hideTimestamp: N === !1 ? !1 : E,
        entry: r,
        messageFormatter: t
      }
    );
  })), /* @__PURE__ */ e.createElement("form", { className: "lk-chat-form", onSubmit: i }, /* @__PURE__ */ e.createElement(
    "input",
    {
      className: "lk-form-control lk-chat-form-input",
      disabled: p,
      ref: u,
      type: "text",
      placeholder: "Enter a message...",
      onInput: (r) => r.stopPropagation(),
      onKeyDown: (r) => r.stopPropagation(),
      onKeyUp: (r) => r.stopPropagation()
    }
  ), /* @__PURE__ */ e.createElement("button", { type: "submit", className: "lk-button lk-chat-form-button", disabled: p }, "Send")));
}
function Y({
  kind: t,
  initialSelection: a,
  onActiveDeviceChange: s,
  tracks: n,
  requestPermissions: l = !1,
  ...u
}) {
  const [m, v] = e.useState(!1), [c, d] = e.useState([]), [p, S] = e.useState(!0), [g, i] = e.useState(l), r = (E, b) => {
    _.debug("handle device change"), v(!1), s == null || s(E, b);
  }, o = e.useRef(null), f = e.useRef(null);
  e.useLayoutEffect(() => {
    m && i(!0);
  }, [m]), e.useLayoutEffect(() => {
    o.current && f.current && (c || p) && st(o.current, f.current).then(({ x: E, y: b }) => {
      f.current && Object.assign(f.current.style, { left: `${E}px`, top: `${b}px` });
    }), S(!1);
  }, [o, f, c, p]);
  const N = e.useCallback(
    (E) => {
      f.current && E.target !== o.current && m && ct(f.current, E) && v(!1);
    },
    [m, f, o]
  );
  return e.useEffect(() => (document.addEventListener("click", N), window.addEventListener("resize", () => S(!0)), () => {
    document.removeEventListener("click", N), window.removeEventListener("resize", () => S(!0));
  }), [N, S]), /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
    "button",
    {
      className: "lk-button lk-button-menu",
      "aria-pressed": m,
      ...u,
      onClick: () => v(!m),
      ref: o
    },
    u.children
  ), !u.disabled && /* @__PURE__ */ e.createElement(
    "div",
    {
      className: "lk-device-menu",
      ref: f,
      style: { visibility: m ? "visible" : "hidden" }
    },
    t ? t === "audioinput" ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
      "p",
      {
        style: {
          textAlign: "left",
          paddingLeft: 16,
          color: "#878787"
        }
      },
      "Microphone"
    ), /* @__PURE__ */ e.createElement(
      Q,
      {
        initialSelection: a,
        onActiveDeviceChange: (E) => r("audioinput", E),
        onDeviceListChange: d,
        kind: "audioinput",
        track: n == null ? void 0 : n.audioinput,
        requestPermissions: g
      }
    ), /* @__PURE__ */ e.createElement(
      "p",
      {
        style: {
          textAlign: "left",
          paddingLeft: 16,
          color: "#878787",
          marginTop: 4
        }
      },
      "Speakers"
    ), /* @__PURE__ */ e.createElement(
      Q,
      {
        initialSelection: a,
        onActiveDeviceChange: (E) => r("audiooutput", E),
        onDeviceListChange: d,
        kind: "audiooutput",
        track: n == null ? void 0 : n.audiooutput,
        requestPermissions: g
      }
    )) : /* @__PURE__ */ e.createElement(
      Q,
      {
        initialSelection: a,
        onActiveDeviceChange: (E) => r(t, E),
        onDeviceListChange: d,
        kind: t,
        track: n == null ? void 0 : n[t],
        requestPermissions: g
      }
    ) : /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "lk-device-menu-heading" }, "Audio inputs"), /* @__PURE__ */ e.createElement(
      Q,
      {
        kind: "audioinput",
        onActiveDeviceChange: (E) => r("audioinput", E),
        onDeviceListChange: d,
        track: n == null ? void 0 : n.audioinput,
        requestPermissions: g
      }
    ), /* @__PURE__ */ e.createElement("div", { className: "lk-device-menu-heading" }, "Video inputs"), /* @__PURE__ */ e.createElement(
      Q,
      {
        kind: "videoinput",
        onActiveDeviceChange: (E) => r("videoinput", E),
        onDeviceListChange: d,
        track: n == null ? void 0 : n.videoinput,
        requestPermissions: g
      }
    ))
  ));
}
function ee() {
  e.useEffect(() => {
    Re();
  }, []);
}
function St(t, a) {
  const [s, n] = e.useState(), l = e.useMemo(() => new ht(), []);
  return e.useEffect(() => {
    let u = !1, m = [];
    return l.lock().then(async (v) => {
      try {
        (t.audio || t.video) && (m = await ft(t), u ? m.forEach((c) => c.stop()) : n(m));
      } catch (c) {
        a && c instanceof Error ? a(c) : _.error(c);
      } finally {
        v();
      }
    }), () => {
      u = !0, m.forEach((v) => {
        v.stop();
      });
    };
  }, [JSON.stringify(t, De), a, l]), s;
}
function zt(t, a, s) {
  const [n, l] = e.useState(null), [u, m] = e.useState(!1), v = et({ kind: s }), [c, d] = e.useState(
    void 0
  ), [p, S] = e.useState(), [g, i] = e.useState(a);
  e.useEffect(() => {
    i(a);
  }, [a]);
  const r = async (N, E) => {
    try {
      const b = E === "videoinput" ? await Et({
        deviceId: N,
        resolution: vt.h720.resolution
      }) : await gt({ deviceId: N }), y = await b.getDeviceId();
      y && N !== y && (f.current = y, i(y)), S(b);
    } catch (b) {
      b instanceof Error && l(b);
    }
  }, o = async (N, E) => {
    await N.setDeviceId(E), f.current = E;
  }, f = e.useRef(g);
  return e.useEffect(() => {
    t && !p && !n && !u && (_.debug("creating track", s), m(!0), r(g, s).finally(() => {
      m(!1);
    }));
  }, [t, p, n, u]), e.useEffect(() => {
    p && (t ? c != null && c.deviceId && f.current !== (c == null ? void 0 : c.deviceId) ? (_.debug(`switching ${s} device from`, f.current, c.deviceId), o(p, c.deviceId)) : (_.debug(`unmuting local ${s} track`), p.unmute()) : (_.debug(`muting ${s} track`), p.mute().then(() => _.debug(p.mediaStreamTrack))));
  }, [p, c, t, s]), e.useEffect(() => () => {
    p && (_.debug(`stopping local ${s} track`), p.stop(), p.mute());
  }, []), e.useEffect(() => {
    d(v == null ? void 0 : v.find((N) => N.deviceId === g));
  }, [g, v]), {
    selectedDevice: c,
    localTrack: p,
    deviceError: n
  };
}
function Wt({
  defaults: t = {},
  onValidate: a,
  onSubmit: s,
  onError: n,
  debug: l,
  joinLabel: u = "Join Room",
  micLabel: m = "Microphone",
  camLabel: v = "Camera",
  userLabel: c = "Username",
  persistUserChoices: d = !0,
  videoProcessor: p,
  ...S
}) {
  const [g, i] = e.useState(it), r = {
    ...t.audioDeviceId !== void 0 && { audioDeviceId: t.audioDeviceId },
    ...t.videoDeviceId !== void 0 && { videoDeviceId: t.videoDeviceId },
    ...t.audioEnabled !== void 0 && { audioEnabled: t.audioEnabled },
    ...t.videoEnabled !== void 0 && { videoEnabled: t.videoEnabled },
    ...t.username !== void 0 && { username: t.username }
  }, {
    userChoices: o,
    saveAudioInputDeviceId: f,
    saveAudioInputEnabled: N,
    saveVideoInputDeviceId: E,
    saveVideoInputEnabled: b,
    saveUsername: y
  } = ce({
    defaults: r,
    preventSave: !d,
    preventLoad: !d
  }), [x, D] = e.useState(o.audioEnabled), [I, L] = e.useState(o.videoEnabled), [H, w] = e.useState(
    o.audioDeviceId
  ), [A, W] = e.useState(
    o.videoDeviceId
  ), [z, P] = e.useState(o.username);
  e.useEffect(() => {
    N(x);
  }, [x, N]), e.useEffect(() => {
    b(I);
  }, [I, b]), e.useEffect(() => {
    f(H);
  }, [H, f]), e.useEffect(() => {
    E(A);
  }, [A, E]), e.useEffect(() => {
    y(z);
  }, [z, y]);
  const h = St(
    {
      audio: x ? { deviceId: o.audioDeviceId } : !1,
      video: I ? { deviceId: o.videoDeviceId, processor: p } : !1
    },
    n
  ), B = e.useRef(null), T = e.useMemo(
    () => h == null ? void 0 : h.filter((M) => M.kind === C.Kind.Video)[0],
    [h]
  ), V = e.useMemo(() => {
    if (T) {
      const { facingMode: M } = pt(T);
      return M;
    } else
      return "undefined";
  }, [T]), O = e.useMemo(
    () => h == null ? void 0 : h.filter((M) => M.kind === C.Kind.Audio)[0],
    [h]
  );
  e.useEffect(() => (B.current && T && (T.unmute(), T.attach(B.current)), () => {
    T == null || T.detach();
  }), [T]);
  const [R, U] = e.useState(), k = e.useCallback(
    (M) => typeof a == "function" ? a(M) : M.username !== "",
    [a]
  );
  e.useEffect(() => {
    const M = {
      username: z,
      videoEnabled: I,
      videoDeviceId: A,
      audioEnabled: x,
      audioDeviceId: H
    };
    i(M), U(k(M));
  }, [z, I, k, x, H, A]);
  function $(M) {
    M.preventDefault(), k(g) ? typeof s == "function" && s(g) : _.warn("Validation failed with: ", g);
  }
  return ee(), /* @__PURE__ */ e.createElement("div", { className: "lk-prejoin", ...S }, /* @__PURE__ */ e.createElement("div", { className: "lk-video-container" }, T && /* @__PURE__ */ e.createElement("video", { ref: B, width: "1280", height: "720", "data-lk-facing-mode": V }), (!T || !I) && /* @__PURE__ */ e.createElement("div", { className: "lk-camera-off-note" }, /* @__PURE__ */ e.createElement(_e, null))), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-container" }, /* @__PURE__ */ e.createElement("div", { className: "lk-button-group audio" }, /* @__PURE__ */ e.createElement(
    G,
    {
      initialState: x,
      source: C.Source.Microphone,
      onChange: (M) => D(M)
    },
    m
  ), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-menu" }, /* @__PURE__ */ e.createElement(
    Y,
    {
      initialSelection: H,
      kind: "audioinput",
      disabled: !O,
      tracks: { audioinput: O },
      onActiveDeviceChange: (M, te) => w(te)
    }
  ))), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group video" }, /* @__PURE__ */ e.createElement(
    G,
    {
      initialState: I,
      source: C.Source.Camera,
      onChange: (M) => L(M)
    },
    v
  ), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-menu" }, /* @__PURE__ */ e.createElement(
    Y,
    {
      initialSelection: A,
      kind: "videoinput",
      disabled: !T,
      tracks: { videoinput: T },
      onActiveDeviceChange: (M, te) => W(te)
    }
  )))), /* @__PURE__ */ e.createElement("form", { className: "lk-username-container" }, /* @__PURE__ */ e.createElement(
    "input",
    {
      className: "lk-form-control",
      id: "username",
      name: "username",
      type: "text",
      defaultValue: z,
      placeholder: c,
      onChange: (M) => P(M.target.value),
      autoComplete: "off"
    }
  ), /* @__PURE__ */ e.createElement(
    "button",
    {
      className: "lk-button lk-join-button",
      type: "submit",
      onClick: $,
      disabled: !R
    },
    u
  )), l && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("strong", null, "User Choices:"), /* @__PURE__ */ e.createElement("ul", { className: "lk-list", style: { overflow: "hidden", maxWidth: "15rem" } }, /* @__PURE__ */ e.createElement("li", null, "Username: ", `${g.username}`), /* @__PURE__ */ e.createElement("li", null, "Video Enabled: ", `${g.videoEnabled}`), /* @__PURE__ */ e.createElement("li", null, "Audio Enabled: ", `${g.audioEnabled}`), /* @__PURE__ */ e.createElement("li", null, "Video Device: ", `${g.videoDeviceId}`), /* @__PURE__ */ e.createElement("li", null, "Audio Device: ", `${g.audioDeviceId}`))));
}
function bt({ props: t }) {
  const { dispatch: a, state: s } = rt().widget, n = "lk-button lk-settings-toggle";
  return { mergedProps: e.useMemo(() => xe(t, {
    className: n,
    onClick: () => {
      a && a({ msg: "toggle_settings" });
    },
    "aria-pressed": s != null && s.showSettings ? "true" : "false"
  }), [t, n, a, s]) };
}
const Ct = /* @__PURE__ */ e.forwardRef(
  function(a, s) {
    const { mergedProps: n } = bt({ props: a });
    return /* @__PURE__ */ e.createElement("button", { ref: s, ...n }, a.children);
  }
);
function yt(t) {
  return { buttonProps: e.useMemo(() => {
    const { className: s } = ot();
    return X(t, {
      className: s
    });
  }, [t]) };
}
const Nt = /* @__PURE__ */ e.forwardRef(
  function(a, s) {
    const { buttonProps: n } = yt(a);
    return /* @__PURE__ */ e.createElement("button", { ref: s, ...n }, a.children);
  }
), wt = [
  "Good 👍",
  "Agree ✅",
  "Disagree ❌",
  "Bad 😝",
  "Can't hear you. Bad Signal",
  "Can't hear you. Your voice is too low",
  "Please make screen bigger",
  "Please go faster",
  "Gotta go, bye"
], Pt = (t) => {
  const a = Math.ceil(t.length / 2);
  return t.reduce(
    (s, n, l) => {
      const u = l < a ? 0 : 1;
      return s[u].push(n), s;
    },
    [[], []]
  );
}, Tt = (t) => {
  const [a, s] = oe(""), [n, l] = oe(!1), u = de(() => t.presetTexts ? t.presetTexts : wt, [t.presetTexts]), m = () => {
    const v = Pt(u).map((c, d) => /* @__PURE__ */ j.createElement("div", { className: "unprefix-text-message-preset-block", key: d }, c.map((p, S) => /* @__PURE__ */ j.createElement(
      "span",
      {
        key: S,
        className: "unprefix-text-message-preset-block-cell",
        onClick: () => {
          var g;
          (g = t.onSendMessage) == null || g.call(t, p), l(!1);
        }
      },
      p
    ))));
    return /* @__PURE__ */ j.createElement("div", { className: "unprefix-text-message-preset" }, v);
  };
  return /* @__PURE__ */ j.createElement("div", { className: "lk-message-sender-container" }, /* @__PURE__ */ j.createElement("div", { className: "lk-message-sender-icon" }, /* @__PURE__ */ j.createElement(He, null)), /* @__PURE__ */ j.createElement(
    Ve,
    {
      content: m(),
      open: n,
      onOpenChange: (v) => l(v),
      destroyTooltipOnHide: !0,
      overlayClassName: "unprefix-message-sender-preset-popover"
    },
    /* @__PURE__ */ j.createElement(
      "input",
      {
        type: "text",
        maxLength: 500,
        placeholder: "Send to all",
        value: a,
        onChange: (v) => {
          const c = v.currentTarget.value;
          c && n && l(!1), !c && !n && l(!0), s(c);
        },
        onKeyDown: (v) => {
          var c, d;
          v.key !== "Enter" || (c = v.nativeEvent) != null && c.isComposing || a && ((d = t.onSendMessage) == null || d.call(t, a), s(""));
        },
        spellCheck: !1
      }
    )
  ));
}, Mt = /* @__PURE__ */ e.forwardRef(
  function(a, s) {
    const n = tt();
    return /* @__PURE__ */ e.createElement(me, { title: "End Call for All" }, /* @__PURE__ */ e.createElement(
      "button",
      {
        ref: s,
        disabled: n === kt.Disconnected,
        className: "lk-end-call-button",
        onClick: a.onClick
      },
      a.children
    ));
  }
);
function It(t) {
  return { buttonProps: e.useMemo(() => {
    const { className: s } = lt();
    return X(t, {
      className: s
    });
  }, [t]) };
}
const Lt = /* @__PURE__ */ e.forwardRef(
  function(a, s) {
    const { buttonProps: n } = It(a);
    return /* @__PURE__ */ e.createElement("button", { ref: s, ...n }, a.children);
  }
);
function Rt(t) {
  return { buttonProps: e.useMemo(() => {
    const { className: s } = ut();
    return X(t, {
      className: s
    });
  }, [t]) };
}
const Dt = /* @__PURE__ */ e.forwardRef(
  function(a, s) {
    const { buttonProps: n } = Rt(a), l = J(), { localParticipant: u } = Ce(), m = de(() => {
      var c;
      return (c = l == null ? void 0 : l.raiseHandList) == null ? void 0 : c.some(
        (d) => d.identity === (u == null ? void 0 : u.identity)
      );
    }, [l == null ? void 0 : l.raiseHandList, u == null ? void 0 : u.identity]), v = pe(async () => {
      if (!(!l || !u))
        try {
          m ? await l.cancelHand([u.identity]) : await l.raiseHand();
        } catch (c) {
          console.log("raise hand button click error", c);
        }
    });
    return /* @__PURE__ */ e.createElement(
      "button",
      {
        ref: s,
        ...n,
        className: he([
          n.className,
          {
            "lk-is-raised": m
          }
        ]),
        onClick: v
      },
      a.children
    );
  }
);
function re({
  variation: t,
  controls: a,
  saveUserChoices: s = !0,
  onDeviceError: n,
  onScreenShareClick: l,
  onAddMember: u,
  onMemberList: m,
  ...v
}) {
  var R, U;
  const [c, d] = e.useState(!1), p = Pe();
  e.useEffect(() => {
    var k, $;
    ((k = p == null ? void 0 : p.widget.state) == null ? void 0 : k.showChat) !== void 0 && d(($ = p == null ? void 0 : p.widget.state) == null ? void 0 : $.showChat);
  }, [(R = p == null ? void 0 : p.widget.state) == null ? void 0 : R.showChat]);
  const g = nt(`(max-width: ${c ? 1e3 : 760}px)`) ? "minimal" : "verbose";
  t ?? (t = g);
  const i = { leave: !0, ...a }, r = ye(), o = Ne(), [f, N] = e.useState(!1);
  r ? (i.camera ?? (i.camera = r.canPublish), i.microphone ?? (i.microphone = r.canPublish), i.screenShare ?? (i.screenShare = r.canPublish), i.chat ?? (i.chat = r.canPublishData && (a == null ? void 0 : a.chat))) : (i.camera = !1, i.chat = !1, i.microphone = !1, i.screenShare = !1);
  const E = e.useMemo(
    () => t === "minimal" || t === "verbose",
    [t]
  ), b = e.useMemo(
    () => t === "textOnly" || t === "verbose",
    [t]
  ), y = dt(), [x, D] = e.useState(!1), I = e.useCallback(
    (k) => {
      D(k);
    },
    [D]
  ), L = X({ className: "lk-control-bar" }, v), {
    saveAudioInputEnabled: H,
    saveVideoInputEnabled: w,
    saveAudioInputDeviceId: A,
    saveVideoInputDeviceId: W
  } = ce({ preventSave: !s }), z = e.useCallback(
    (k, $) => $ ? H(k) : null,
    [H]
  ), P = e.useCallback(
    (k, $) => $ ? w(k) : null,
    [w]
  ), h = J(), B = (h == null ? void 0 : h.onSendMessage) || void 0, T = () => {
    var k;
    (k = h == null ? void 0 : h.onEndCall) == null || k.call(h);
  }, V = () => {
    var k;
    (k = h == null ? void 0 : h.onBackToMain) == null || k.call(h);
  }, O = ((U = h == null ? void 0 : h.components) == null ? void 0 : U.ContextMenu) ?? e.Fragment;
  return /* @__PURE__ */ e.createElement("div", { ...L }, i.backToMain && /* @__PURE__ */ e.createElement(Lt, { onClick: V }, /* @__PURE__ */ e.createElement($e, null)), /* @__PURE__ */ e.createElement("div", { className: "lk-control-area" }, /* @__PURE__ */ e.createElement(Dt, null, /* @__PURE__ */ e.createElement(ae, null)), i.microphone && /* @__PURE__ */ e.createElement("div", { className: "lk-button-group" }, /* @__PURE__ */ e.createElement(me, { mouseEnterDelay: 0.5, placement: "top", title: "Press spacebar to mute/unmute" }, /* @__PURE__ */ e.createElement(
    G,
    {
      source: C.Source.Microphone,
      showIcon: E,
      onChange: z,
      onDeviceError: (k) => n == null ? void 0 : n({ source: C.Source.Microphone, error: k })
    },
    b && "Microphone"
  )), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-menu" }, /* @__PURE__ */ e.createElement(
    Y,
    {
      kind: "audioinput",
      onActiveDeviceChange: (k, $) => A($ ?? "")
    }
  ))), i.camera && /* @__PURE__ */ e.createElement("div", { className: "lk-button-group" }, /* @__PURE__ */ e.createElement(
    G,
    {
      source: C.Source.Camera,
      showIcon: E,
      onChange: P,
      onDeviceError: (k) => n == null ? void 0 : n({ source: C.Source.Camera, error: k })
    },
    b && "Camera"
  ), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-menu" }, /* @__PURE__ */ e.createElement(
    Y,
    {
      kind: "videoinput",
      onActiveDeviceChange: (k, $) => W($ ?? "")
    }
  ))), i.screenShare && y && /* @__PURE__ */ e.createElement(
    G,
    {
      source: C.Source.ScreenShare,
      captureOptions: { audio: !0, selfBrowserSurface: "include" },
      showIcon: E,
      onChange: I,
      onClick: l,
      onDeviceError: (k) => n == null ? void 0 : n({ source: C.Source.ScreenShare, error: k })
    },
    b && (x ? "Stop screen share" : "Share screen")
  ), i.settings && /* @__PURE__ */ e.createElement(Ct, null, E && /* @__PURE__ */ e.createElement(Ue, null), b && "Settings"), i.memberList && /* @__PURE__ */ e.createElement("div", { className: "lk-button-group lk-member-list-button-group" }, /* @__PURE__ */ e.createElement(Nt, { onClick: m }, E && /* @__PURE__ */ e.createElement(ze, null), b && "Member list", /* @__PURE__ */ e.createElement("span", { style: { fontSize: 14, fontWeight: 510 } }, o.length)), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-menu" }, /* @__PURE__ */ e.createElement(
    O,
    {
      trigger: ["click"],
      placement: "top",
      align: {
        offset: [0, -2]
      },
      menu: {
        items: [
          {
            key: "invite",
            label: /* @__PURE__ */ e.createElement(
              "div",
              {
                className: "lk-invite-member-item",
                onClick: () => {
                  u == null || u();
                }
              },
              /* @__PURE__ */ e.createElement(We, null),
              " Invite"
            ),
            onClick: () => {
              u == null || u();
            }
          }
        ]
      }
    },
    /* @__PURE__ */ e.createElement(
      "button",
      {
        className: "lk-button lk-button-menu",
        onClick: () => N((k) => !k)
      }
    )
  ))), i.leave && (h == null ? void 0 : h.type) === "1on1" && /* @__PURE__ */ e.createElement(ne, { title: "End call" }, E && /* @__PURE__ */ e.createElement(le, null), b && "Leave"), i.leave && (h == null ? void 0 : h.type) !== "1on1" && /* @__PURE__ */ e.createElement("div", { className: "lk-leave-button-group" }, /* @__PURE__ */ e.createElement(ne, null, E && /* @__PURE__ */ e.createElement(qe, null), "Leave"), /* @__PURE__ */ e.createElement(Mt, { onClick: T }, /* @__PURE__ */ e.createElement(le, null))), /* @__PURE__ */ e.createElement(fe, null)), i.chat && /* @__PURE__ */ e.createElement(Tt, { onSendMessage: B, presetTexts: h == null ? void 0 : h.chatPresets }));
}
function qt({
  chatMessageFormatter: t,
  chatMessageDecoder: a,
  chatMessageEncoder: s,
  SettingsComponent: n,
  onScreenShareClick: l,
  onAddMember: u,
  onMemberList: m,
  controls: v,
  ...c
}) {
  var E, b;
  const [d, p] = e.useState({
    showChat: !1,
    unreadMessages: 0,
    showSettings: !1
  }), S = e.useRef(null), g = F(
    [
      { source: C.Source.Camera, withPlaceholder: !0 },
      { source: C.Source.ScreenShare, withPlaceholder: !1 }
    ],
    { updateOnlyOn: [q.ActiveSpeakersChanged], onlySubscribed: !1 }
  ), i = (y) => {
    _.debug("updating widget state", y), p(y);
  }, r = Te(), o = g.filter(K).filter((y) => y.publication.source === C.Source.ScreenShare), f = (E = we(r)) == null ? void 0 : E[0], N = g.filter((y) => !Me(y, f));
  return e.useEffect(() => {
    var y, x, D, I, L, H;
    if (o.some((w) => w.publication.isSubscribed) && S.current === null ? (_.debug("Auto set screen share focus:", { newScreenShareTrack: o[0] }), (x = (y = r.pin).dispatch) == null || x.call(y, { msg: "set_pin", trackReference: o[0] }), S.current = o[0]) : S.current && !o.some(
      (w) => {
        var A, W;
        return w.publication.trackSid === ((W = (A = S.current) == null ? void 0 : A.publication) == null ? void 0 : W.trackSid);
      }
    ) && (_.debug("Auto clearing screen share focus."), (I = (D = r.pin).dispatch) == null || I.call(D, { msg: "clear_pin" }), S.current = null), f && !K(f)) {
      const w = g.find(
        (A) => A.participant.identity === f.participant.identity && A.source === f.source
      );
      w !== f && K(w) && ((H = (L = r.pin).dispatch) == null || H.call(L, { msg: "set_pin", trackReference: w }));
    }
  }, [
    o.map((y) => `${y.publication.trackSid}_${y.publication.isSubscribed}`).join(),
    (b = f == null ? void 0 : f.publication) == null ? void 0 : b.trackSid,
    g
  ]), ee(), /* @__PURE__ */ e.createElement("div", { className: "lk-video-conference", ...c }, Ie() && /* @__PURE__ */ e.createElement(
    se,
    {
      value: r,
      onWidgetChange: i
    },
    /* @__PURE__ */ e.createElement("div", { className: "lk-video-conference-inner" }, f ? /* @__PURE__ */ e.createElement("div", { className: "lk-focus-layout-wrapper" }, /* @__PURE__ */ e.createElement(ve, null, /* @__PURE__ */ e.createElement(ge, { tracks: N }, /* @__PURE__ */ e.createElement(Z, null)), f && /* @__PURE__ */ e.createElement(ke, { trackRef: f }))) : /* @__PURE__ */ e.createElement("div", { className: "lk-grid-layout-wrapper" }, /* @__PURE__ */ e.createElement(Ee, { tracks: g }, /* @__PURE__ */ e.createElement(Z, null))), /* @__PURE__ */ e.createElement(
      re,
      {
        variation: "minimal",
        onAddMember: u,
        onMemberList: m,
        controls: { chat: !0, settings: !!n, ...v },
        onScreenShareClick: l
      }
    )),
    /* @__PURE__ */ e.createElement(
      ie,
      {
        style: { display: d.showChat ? "grid" : "none" },
        messageFormatter: t,
        messageEncoder: s,
        messageDecoder: a
      }
    ),
    n && /* @__PURE__ */ e.createElement(
      "div",
      {
        className: "lk-settings-menu-modal",
        style: { display: d.showSettings ? "block" : "none" }
      },
      /* @__PURE__ */ e.createElement(n, null)
    )
  ), /* @__PURE__ */ e.createElement(Se, null), /* @__PURE__ */ e.createElement(be, null));
}
function jt({ ...t }) {
  const [a, s] = e.useState({
    showChat: !1,
    unreadMessages: 0
  }), n = F([C.Source.Microphone]);
  return ee(), /* @__PURE__ */ e.createElement(se, { onWidgetChange: s }, /* @__PURE__ */ e.createElement("div", { className: "lk-audio-conference", ...t }, /* @__PURE__ */ e.createElement("div", { className: "lk-audio-conference-stage" }, /* @__PURE__ */ e.createElement(je, { tracks: n }, /* @__PURE__ */ e.createElement(Ge, null))), /* @__PURE__ */ e.createElement(
    re,
    {
      controls: { microphone: !0, screenShare: !1, camera: !1, chat: !0 }
    }
  ), a.showChat && /* @__PURE__ */ e.createElement(ie, null)));
}
const xt = () => {
  const t = J(), a = (t == null ? void 0 : t.raiseHandList) ?? [], [s, n] = e.useState(!0), { renderParticipantPlaceholder: l, nameFormatter: u, cancelHand: m } = t ?? {}, v = e.useMemo(() => {
    const c = a.sort((d, p) => d.ts - p.ts);
    return s ? c.slice(0, 5) : c;
  }, [a, s]);
  return a.length === 0 ? null : /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list" }, /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list-header" }, /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list-header-icon" }, /* @__PURE__ */ e.createElement(ae, null)), /* @__PURE__ */ e.createElement("span", { className: "lk-raise-hand-list-header-text" }, "Raise hand (", a.length, ")")), /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list-content" }, v.map((c, d) => /* @__PURE__ */ e.createElement("div", { key: d, className: "lk-raise-hand-list-item" }, /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list-item-info" }, /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list-item-avatar" }, l == null ? void 0 : l(c, { size: 28 })), /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-list-item-info-name" }, /* @__PURE__ */ e.createElement("span", { className: "lk-raise-hand-list-item-info-name-text" }, u ? u(c) : c.identity))), /* @__PURE__ */ e.createElement(
    "div",
    {
      className: "lk-raise-hand-list-item-lower",
      onClick: () => m == null ? void 0 : m([c.identity])
    },
    "Lower"
  ))), a.length > 5 && /* @__PURE__ */ e.createElement(
    "div",
    {
      className: "lk-raise-hand-list-collapse-toggle",
      onClick: () => n((c) => !c)
    },
    s ? /* @__PURE__ */ e.createElement(Qe, null) : /* @__PURE__ */ e.createElement(Ye, null)
  )));
}, At = (t) => {
  const { open: a, onClose: s } = t, [n, l] = e.useState(""), u = Ne(), m = at(u), v = J(), { renderParticipantPlaceholder: c, nameFormatter: d, components: p } = v, S = (p == null ? void 0 : p.ContextMenu) ?? e.Fragment, g = e.useMemo(() => m.filter(
    (o) => ((d == null ? void 0 : d(o)) ?? o.identity).toLowerCase().includes(n.toLowerCase())
  ), [m, n]), [i] = F(
    [{ source: C.Source.ScreenShare, withPlaceholder: !1 }],
    { updateOnlyOn: [q.ActiveSpeakersChanged], onlySubscribed: !1 }
  ), { getContextMenuItems: r } = Ke();
  return a ? /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list" }, /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-header" }, /* @__PURE__ */ e.createElement("span", { className: "lk-participant-aside-list-header-title" }, "Attendees(", m.length, ")"), /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-close-button", onClick: s }, /* @__PURE__ */ e.createElement(Je, null))), /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-search" }, /* @__PURE__ */ e.createElement(
    "input",
    {
      type: "text",
      placeholder: "Search",
      value: n,
      onChange: (o) => l(o.target.value),
      className: "lk-participant-aside-list-input"
    }
  )), /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list" }, !n && /* @__PURE__ */ e.createElement(xt, null), g.map((o, f) => {
    var N;
    return /* @__PURE__ */ e.createElement("div", { key: f, className: "lk-participant-aside-list-list-item" }, /* @__PURE__ */ e.createElement(
      S,
      {
        menu: { items: r(o) },
        disabled: r(o).length === 0
      },
      /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list-item-info" }, /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list-item-avatar" }, c == null ? void 0 : c(o, { size: 28 })), /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list-item-info-name" }, /* @__PURE__ */ e.createElement("span", { className: "lk-participant-aside-list-list-item-info-name-text" }, d ? d(o) : o.identity), /* @__PURE__ */ e.createElement("span", { className: "lk-participant-aside-list-list-item-sharing" }, ((N = i == null ? void 0 : i.participant) == null ? void 0 : N.identity) === o.identity ? "Sharing" : "")))
    ), /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list-item-status" }, /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list-item-status-audio" }, /* @__PURE__ */ e.createElement(
      ue,
      {
        trackRef: {
          participant: o,
          source: C.Source.Microphone
        },
        show: "always",
        singleColor: !0
      }
    )), /* @__PURE__ */ e.createElement("div", { className: "lk-participant-aside-list-list-item-status-video" }, /* @__PURE__ */ e.createElement(
      ue,
      {
        trackRef: {
          participant: o,
          source: C.Source.Camera
        },
        show: "always",
        singleColor: !0
      }
    ))));
  }))) : null;
}, Bt = ({ onClick: t }) => {
  const a = J(), s = (a == null ? void 0 : a.raiseHandList) ?? [], n = e.useMemo(() => s.length === 0 ? "" : `${s.map((l) => l.displayName).join(",")}${s.length > 3 ? "..." : ""}`, [s]);
  return s.length === 0 ? null : /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-indicator", onClick: t }, /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-indicator-icon" }, /* @__PURE__ */ e.createElement(ae, null)), /* @__PURE__ */ e.createElement("div", { className: "lk-raise-hand-indicator-text" }, n));
};
function Gt({
  chatMessageFormatter: t,
  chatMessageDecoder: a,
  chatMessageEncoder: s,
  SettingsComponent: n,
  onScreenShareClick: l,
  onAddMember: u,
  onMemberList: m,
  filterLocalTracks: v,
  controls: c,
  onDeviceError: d,
  ...p
}) {
  var W, z;
  const [S, g] = e.useState({
    showChat: !1,
    unreadMessages: 0,
    showSettings: !1
  }), i = mt(), r = e.useRef(null), [o, f] = e.useState(!1), [N, E] = e.useState(!0), b = F(
    [
      { source: C.Source.Camera, withPlaceholder: !0 },
      { source: C.Source.ScreenShare, withPlaceholder: !1 }
    ],
    {
      updateOnlyOn: [q.ActiveSpeakersChanged, q.TrackMuted, q.TrackUnmuted],
      onlySubscribed: !1,
      filterLocalTracks: v
    }
  ), y = b.find((P) => P.source === C.Source.ScreenShare), x = (P) => {
    g(P);
  }, D = Te(), I = b.filter(K).filter((P) => P.publication.source === C.Source.ScreenShare), L = (W = we(D)) == null ? void 0 : W[0], H = b.filter((P) => !Me(P, L)), w = J();
  e.useEffect(() => {
    var B, T;
    if ((w == null ? void 0 : w.type) === "instant")
      return [...Array.from(i.remoteParticipants.values()), i.localParticipant].some(
        (R) => R.getTrackPublication(C.Source.ScreenShare)
      ) || (T = (B = D.pin).dispatch) == null ? void 0 : T.call(B, { msg: "clear_pin" });
    if (!i || (w == null ? void 0 : w.type) !== "1on1")
      return;
    const P = () => {
      var O, R;
      const V = i.remoteParticipants;
      if (!(V.size > 1))
        for (let [U, k] of V)
          (R = (O = D.pin).dispatch) == null || R.call(O, {
            msg: "set_pin",
            trackReference: {
              participant: k,
              publication: k.getTrackPublication(C.Source.Camera),
              source: C.Source.Camera
            }
          });
    }, h = (V) => {
      var O, R;
      i.remoteParticipants.size > 1 || y || (console.log("set pin when remote connected"), (R = (O = D.pin).dispatch) == null || R.call(O, {
        msg: "set_pin",
        trackReference: {
          participant: V,
          publication: V.getTrackPublication(C.Source.Camera),
          source: C.Source.Camera
        }
      }));
    };
    return i.on(q.Connected, P), i.on(q.ParticipantConnected, h), () => {
      i.off(q.Connected, P), i.off(q.ParticipantConnected, h);
    };
  }, [i, w == null ? void 0 : w.type, y]), e.useEffect(() => {
    if ((w == null ? void 0 : w.type) === "1on1" && !y) {
      const P = i.remoteParticipants.values().next().value;
      P && setTimeout(() => {
        var h, B;
        (B = (h = D.pin).dispatch) == null || B.call(h, {
          msg: "set_pin",
          trackReference: {
            participant: P,
            publication: P.getTrackPublication(C.Source.Camera),
            source: C.Source.Camera
          }
        });
      });
    }
  }, [w == null ? void 0 : w.type, y]), e.useEffect(() => {
    var P, h, B, T, V, O;
    if (I.some((R) => R.publication.isSubscribed) && r.current === null ? (_.debug("Auto set screen share focus:", { newScreenShareTrack: I[0] }), console.warn("set pin 5"), (h = (P = D.pin).dispatch) == null || h.call(P, { msg: "set_pin", trackReference: I[0] }), r.current = I[0]) : r.current && !I.some(
      (R) => {
        var U, k;
        return R.publication.trackSid === ((k = (U = r.current) == null ? void 0 : U.publication) == null ? void 0 : k.trackSid);
      }
    ) && (_.debug("Auto clearing screen share focus."), (T = (B = D.pin).dispatch) == null || T.call(B, { msg: "clear_pin" }), r.current = null), L && !K(L)) {
      const R = b.find(
        (U) => U.participant.identity === L.participant.identity && U.source === L.source
      );
      R !== L && K(R) && (console.warn("set pin 6"), (O = (V = D.pin).dispatch) == null || O.call(V, { msg: "set_pin", trackReference: R }));
    }
  }, [
    I.map((P) => `${P.publication.trackSid}_${P.publication.isSubscribed}`).join(),
    (z = L == null ? void 0 : L.publication) == null ? void 0 : z.trackSid,
    b
  ]), ee();
  const A = pe(() => {
    f(!0);
  });
  return /* @__PURE__ */ e.createElement(
    "div",
    {
      className: he("lk-video-conference", {
        "lk-show-aside-list": o,
        "lk-has-screen-share": I.length
      }),
      ...p
    },
    Ie() && /* @__PURE__ */ e.createElement(
      se,
      {
        value: D,
        onWidgetChange: x
      },
      /* @__PURE__ */ e.createElement("div", { className: "lk-video-conference-inner" }, L ? /* @__PURE__ */ e.createElement("div", { className: "lk-focus-layout-wrapper" }, /* @__PURE__ */ e.createElement(ve, null, L && /* @__PURE__ */ e.createElement(ke, { trackRef: L }), /* @__PURE__ */ e.createElement(Xe, null, /* @__PURE__ */ e.createElement(
        ge,
        {
          tracks: H,
          focusTrack: L,
          orientation: "vertical"
        },
        /* @__PURE__ */ e.createElement(Z, { renderPlaceholderExtraProps: { size: 64 } })
      )))) : /* @__PURE__ */ e.createElement("div", { className: "lk-grid-layout-wrapper" }, /* @__PURE__ */ e.createElement(Ee, { tracks: b }, /* @__PURE__ */ e.createElement(
        Z,
        {
          onRestPlaceholderClick: () => f((P) => !P)
        }
      ))), /* @__PURE__ */ e.createElement(
        re,
        {
          variation: "minimal",
          onAddMember: u,
          onMemberList: (...P) => {
            f((h) => !h), m == null || m(...P);
          },
          controls: { chat: !0, settings: !!n, ...c },
          onScreenShareClick: l,
          onDeviceError: d
        }
      )),
      /* @__PURE__ */ e.createElement(
        ie,
        {
          style: { display: S.showChat ? "grid" : "none" },
          messageFormatter: t,
          messageEncoder: s,
          messageDecoder: a
        }
      ),
      n && /* @__PURE__ */ e.createElement(
        "div",
        {
          className: "lk-settings-menu-modal",
          style: { display: S.showSettings ? "block" : "none" }
        },
        /* @__PURE__ */ e.createElement(n, null)
      )
    ),
    /* @__PURE__ */ e.createElement(Se, { filterLocalTracks: v }),
    /* @__PURE__ */ e.createElement(be, null),
    /* @__PURE__ */ e.createElement(
      At,
      {
        open: o,
        onClose: () => {
          f(!1), E(!0);
        }
      }
    ),
    N && /* @__PURE__ */ e.createElement(Bt, { onClick: A })
  );
}
function Kt({
  controls: t,
  saveUserChoices: a = !0,
  onDeviceError: s,
  ...n
}) {
  const l = { leave: !0, microphone: !0, ...t }, u = ye(), { microphoneTrack: m, localParticipant: v } = Ce(), c = e.useMemo(() => ({
    participant: v,
    source: C.Source.Microphone,
    publication: m
  }), [v, m]);
  u ? l.microphone ?? (l.microphone = u.canPublish) : l.microphone = !1;
  const d = X({ className: "lk-agent-control-bar" }, n), { saveAudioInputEnabled: p, saveAudioInputDeviceId: S } = ce({
    preventSave: !a
  }), g = e.useCallback(
    (i, r) => {
      r && p(i);
    },
    [p]
  );
  return /* @__PURE__ */ e.createElement("div", { ...d }, l.microphone && /* @__PURE__ */ e.createElement("div", { className: "lk-button-group" }, /* @__PURE__ */ e.createElement(
    G,
    {
      source: C.Source.Microphone,
      showIcon: !0,
      onChange: g,
      onDeviceError: (i) => s == null ? void 0 : s({ source: C.Source.Microphone, error: i })
    },
    /* @__PURE__ */ e.createElement(Ze, { trackRef: c, barCount: 7, options: { minHeight: 5 } })
  ), /* @__PURE__ */ e.createElement("div", { className: "lk-button-group-menu" }, /* @__PURE__ */ e.createElement(
    Y,
    {
      kind: "audioinput",
      onActiveDeviceChange: (i, r) => S(r ?? "")
    }
  ))), l.leave && /* @__PURE__ */ e.createElement(ne, null, "Disconnect"), /* @__PURE__ */ e.createElement(fe, null));
}
export {
  jt as AudioConference,
  ie as Chat,
  re as ControlBar,
  Y as MediaDeviceMenu,
  Gt as NewVideoConference,
  Wt as PreJoin,
  qt as VideoConference,
  Kt as VoiceAssistantControlBar,
  zt as usePreviewDevice,
  St as usePreviewTracks
};
//# sourceMappingURL=prefabs.mjs.map
