import { createContext as g, useEffect as i, useRef as w, useMemo as A, useContext as u, useState as h } from "react";
import { jsxs as N, jsx as O } from "react/jsx-runtime";
import { $ as T } from "./useStreamLayerApp2.js";
const L = ({
  event: e,
  internal: r
}) => {
  const o = H(), n = j();
  return i(() => {
    o && (e && (o.createEventSession(e, r), n && (n.current = e)), !e && n != null && n.current && (o.createEventSession("", r), n.current = ""));
  }, [e, r, n, o]), null;
};
var x = /* @__PURE__ */ ((e) => (e[e.UNSET = 0] = "UNSET", e[e.CONNECTED = 1] = "CONNECTED", e[e.READY = 2] = "READY", e))(x || {});
const M = {
  status: 0,
  sdk: null
}, d = g(M), U = ({
  sdkKey: e,
  theme: r,
  themeMode: o,
  plugins: n,
  children: a,
  event: m,
  production: y = !0,
  autoEnable: C = !0,
  withAdNotification: E,
  withAd: S = !0,
  betPack: c = !1,
  hideFriends: f,
  skipOnboarding: v,
  friendsTab: p = "enabled",
  onDeepLinkHandled: s,
  videoPlayerController: l,
  onContentActivate: D,
  containerId: k,
  webOS: K
}) => {
  const t = T({
    sdkKey: e,
    plugins: n,
    production: y,
    autoEnable: C,
    onDeepLinkHandled: s,
    videoPlayerController: l,
    onContentActivate: D,
    hideFriends: f,
    skipOnboarding: v,
    withAdNotification: E,
    withAd: S,
    friendsTab: p,
    betPack: c,
    webOS: K
  }), b = w(""), P = A(() => t ? { sdk: t, status: 2, event: b } : { status: 1, sdk: null, event: b }, [t]);
  return i(() => {
    t && (t.options.setKey("friendsTab", p), t.options.setKey("theme", r), t.options.setKey("themeMode", o), t.options.setKey("skipOnboarding", v), t.options.setKey("betPack", c), t.options.setKey("containerId", k));
  }, [t, p, r, o, v, c, k]), i(() => () => {
    s && (t == null || t.removeDeepLinkHandler(s)), l && (t == null || t.removeVideoPlayerController(l));
  }, [t]), i(() => {
    localStorage.getItem("SL_DEBUG") && console.log("StreamLayerProvider mounted with props:", {
      sdkKey: !!e,
      onDeepLinkHandled: !!s,
      videoPlayerController: !!l
    });
  }, [e, s, l]), /* @__PURE__ */ N(d.Provider, { value: P, children: [
    m !== void 0 && /* @__PURE__ */ O(L, { event: m }),
    a
  ] });
}, H = () => {
  const { sdk: e } = u(d);
  return e;
}, j = () => {
  const { event: e } = u(d);
  return e;
}, Y = () => {
  const { sdk: e } = u(d), [r, o] = h({});
  return i(() => {
    var n;
    return e != null && e.options ? (n = e == null ? void 0 : e.options) == null ? void 0 : n.subscribe((a) => {
      o({ theme: a.theme, themeMode: a.themeMode });
    }) : () => {
    };
  }, [e == null ? void 0 : e.options]), r;
}, B = () => {
  const { sdk: e } = u(d), [r, o] = h({});
  return i(() => e != null && e.uiState ? e == null ? void 0 : e.uiState.subscribe((n) => {
    o({ ...n });
  }) : () => {
  }, [e == null ? void 0 : e.uiState]), r;
};
export {
  H as B,
  B as F,
  x as Y,
  d as i,
  L as j,
  U as q,
  Y as z
};
