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