import { jsxs, jsx } from "react/jsx-runtime";
import { q, B, z, h, t as te, W, a as anonymous, u as useStore, g as ge, Z } from "./index2.js";
import { F } from "./index2.js";
import { useRef, useEffect } from "react";
const plugins = /* @__PURE__ */ new Set([anonymous]);
const RegisterVideoPlayerController = ({
  videoPlayerController
}) => {
  const sdk = B();
  const ref = useRef();
  useEffect(() => {
    if (sdk) {
      ref.current = videoPlayerController;
      sdk.addVideoPlayerController(ref.current);
      return () => {
        if (ref.current) {
          sdk.removeVideoPlayerController(ref.current);
        }
      };
    }
  }, [sdk]);
  return null;
};
const StreamLayerProvider = ({
  children,
  videoPlayerController,
  ...props
}) => {
  return /* @__PURE__ */ jsxs(
    q,
    {
      ...props,
      themeMode: "dark",
      withAd: true,
      skipOnboarding: true,
      withAdNotification: true,
      autoEnable: true,
      plugins,
      friendsTab: "disabled",
      hideFriends: true,
      webOS: true,
      children: [
        children,
        videoPlayerController && /* @__PURE__ */ jsx(RegisterVideoPlayerController, { videoPlayerController })
      ]
    }
  );
};
const AnonymousLogin = ({ sdk }) => {
  useEffect(() => {
    sdk.anonymousAuthorization();
  }, [sdk]);
  return null;
};
const StreamLayerSDKTvContentPure = ({ persistent, notification, banner, sdk }) => {
  const uiState = useStore(sdk.uiState);
  if (uiState.exposedPauseAd) {
    return null;
  }
  if (banner) {
    return /* @__PURE__ */ jsx(ge, { sdk, persistent, banner: "bottom" });
  }
  if (notification) {
    if (!!uiState.promotionNotification) {
      return /* @__PURE__ */ jsx(ge, { sdk, notification: true, persistent, sidebar: "right" });
    }
    return /* @__PURE__ */ jsx(Z, { sdk, notification: true, persistent });
  }
  if (!!uiState.promotionSidebar) {
    return /* @__PURE__ */ jsx(ge, { sdk, persistent, sidebar: "right" });
  }
  return /* @__PURE__ */ jsx(Z, { sdk, persistent });
};
const StreamLayerSDKTvContent = (props) => {
  const sdk = B();
  const baseTheme = z();
  if (!sdk) {
    return null;
  }
  return /* @__PURE__ */ jsx("div", { className: "StreamLayerSDK", children: /* @__PURE__ */ jsx(
    h,
    {
      style: { position: "relative" },
      customTheme: baseTheme.theme,
      themeMode: baseTheme.themeMode,
      children: /* @__PURE__ */ jsx(StreamLayerSDKTvContentPure, { sdk, ...props })
    }
  ) });
};
const StreamLayerSDKTvPauseAd = (props) => {
  const sdk = B();
  const baseTheme = z();
  if (!sdk) {
    return null;
  }
  return /* @__PURE__ */ jsx("div", { className: "StreamLayerSDK", children: /* @__PURE__ */ jsx(
    h,
    {
      style: { position: "relative" },
      customTheme: baseTheme.theme,
      themeMode: baseTheme.themeMode,
      children: /* @__PURE__ */ jsx(te, { ...props, sdk, isDesktop: false })
    }
  ) });
};
const StreamLayerSDKTv = ({
  persistent,
  children,
  showPauseAd,
  pauseAdVastUrl,
  videoPlayerController,
  onRenderPauseAd,
  onClosePauseAd,
  options
}) => {
  const sdk = B();
  const baseTheme = z();
  const ref = useRef();
  useEffect(() => {
    if (sdk) {
      if (videoPlayerController) {
        ref.current = videoPlayerController;
        sdk.addVideoPlayerController(ref.current);
      }
      return () => {
        if (ref.current) {
          sdk.removeVideoPlayerController(ref.current);
        }
      };
    }
  }, [sdk]);
  if (!sdk) {
    return null;
  }
  return /* @__PURE__ */ jsx("div", { className: "StreamLayerSDK", children: /* @__PURE__ */ jsxs(h, { customTheme: baseTheme.theme, themeMode: baseTheme.themeMode, children: [
    /* @__PURE__ */ jsx(
      W,
      {
        sdk,
        persistent,
        showPauseAd,
        onRenderPauseAd,
        pauseAdVastUrl,
        onClosePauseAd,
        options,
        children
      }
    ),
    /* @__PURE__ */ jsx(AnonymousLogin, { sdk })
  ] }) });
};
export {
  StreamLayerProvider,
  StreamLayerSDKTv,
  StreamLayerSDKTvContent,
  StreamLayerSDKTvPauseAd,
  B as useStreamLayer,
  z as useStreamLayerTheme,
  F as useStreamLayerUI
};
