import { SessionExpiredDialog as m } from "./accelbyte-widgets75.mjs";
import { Alerts as c } from "./accelbyte-widgets76.mjs";
import { LoadingPage as s } from "./accelbyte-widgets77.mjs";
import { AppName as f } from "./accelbyte-widgets78.mjs";
import { Ctx as r } from "./accelbyte-widgets33.mjs";
import { AppState as g } from "./accelbyte-widgets79.mjs";
import "./accelbyte-widgets80.mjs";
import "./accelbyte-widgets81.mjs";
import "./accelbyte-widgets82.mjs";
import { Buffer as S } from "buffer";
import t from "react";
import { Router as d, Switch as h } from "react-router-dom";
import { Provider as u, Subscribe as E } from "unstated";
import { ConfigsUtils as o } from "./accelbyte-widgets83.mjs";
window.Buffer = S;
class L extends t.Component {
  constructor(e) {
    super(e), this.state = {
      initialized: !1
    };
  }
  async componentDidMount() {
    try {
      const { widgetOptions: e } = this.props;
      this.props.onInitializeSDK && this.props.onInitializeSDK(r.getAppState().getSdk()), await Promise.all([
        r.fetchConfigs(f.WIDGET, {
          configs: o.createPlayerPortalConfigs(e == null ? void 0 : e.playerPortalConfigs),
          discovery: o.createDiscoveryConfigs(e == null ? void 0 : e.generalConfigs),
          twitchDropConfigs: o.createTwitchDropConfigs(e == null ? void 0 : e.twitchDropConfigs)
        }),
        r.registerUserFetch()
      ]);
      const i = r.getAppState().getGameId();
      r.getAppState().isSingleGame() && i && (r.getGameState().setActiveGame(i), await r.getGameState().fetchGamesInfo([i]));
    } catch (e) {
      console.error(e);
    } finally {
      this.setState({ initialized: !0 });
    }
  }
  render() {
    const { children: e, sdkOptions: i, basePath: a } = this.props, { initialized: p } = this.state, n = r.getAppState(i, a), l = !p;
    return /* @__PURE__ */ t.createElement(u, { inject: [n] }, /* @__PURE__ */ t.createElement(d, { history: n.state.appHistory }, /* @__PURE__ */ t.createElement(E, { to: [g] }, () => /* @__PURE__ */ t.createElement("div", { id: "sdk-widget-app" }, /* @__PURE__ */ t.createElement(m, null), /* @__PURE__ */ t.createElement(c, null), /* @__PURE__ */ t.createElement(t.Suspense, { fallback: /* @__PURE__ */ t.createElement(s, null) }, /* @__PURE__ */ t.createElement(h, null, l && /* @__PURE__ */ t.createElement(s, null), e))))));
  }
}
export {
  L as SdkWidget
};
