import { jsx as u, jsxs as c } from "react/jsx-runtime";
import { useRef as l, useEffect as h } from "react";
import { f as m, s as p, z as f, u as S, d as I, h as g, a as v } from "./provider.js";
import { S as y } from "./useStreamLayerApp2.js";
const Q = () => f, k = /* @__PURE__ */ p(Q())({
  name: "QuestionWrap",
  class: "q10hhsxv",
  propsAsIs: !0
}), A = ({
  gamification: e,
  persistent: r,
  skipAutoClose: n,
  hideHeader: o,
  insightId: s
}) => {
  const t = l(""), d = m(e.openedQuestion.$store);
  return h(() => s ? (!r || e.isOpenedQuestion(s) || (t.current = s, e.getFeedItem(s).then((i) => {
    var a;
    t.current === s && ((a = i == null ? void 0 : i.attributes) == null ? void 0 : a.attributes.case) === "insight" && e.openQuestion(s, i);
  })), () => {
    t.current = "";
  }) : (e.activeQuestionId.subscribe(({
    data: i
  }) => {
    var a;
    i && ((a = i.feedItem) == null ? void 0 : a.type) === "insight" && (!r || e.isOpenedQuestion(i.feedItem.id) || (t.current = i.feedItem.id, e.openQuestion(i.feedItem.id, i.feedItem))), !i && t.current && (e.closeQuestion(t.current), t.current = "");
  }), () => {
  }), [e, r, s]), d ? /* @__PURE__ */ u(k, {
    skipAutoClose: n,
    hideHeader: o,
    gamification: e,
    hideSponsor: !0
  }) : null;
}, L = ({
  sdk: e,
  persistent: r,
  skipAutoClose: n,
  insightId: o,
  hideHeader: s
}) => {
  if (!m(e.featuresList.getStore()))
    return null;
  const t = e.getFeature(y.GAMES);
  return t ? /* @__PURE__ */ u(A, {
    insightId: o,
    persistent: r,
    hideHeader: s,
    gamification: t,
    skipAutoClose: n
  }) : null;
}, H = ({
  event: e,
  theme: r,
  hideHeader: n,
  skipAutoClose: o,
  persistent: s
}) => {
  const t = S(), d = I();
  return t ? /* @__PURE__ */ c("div", { className: "StreamLayerSDK", children: [
    /* @__PURE__ */ u(g, { customTheme: r ?? d.theme, themeMode: d.themeMode, children: /* @__PURE__ */ u(
      L,
      {
        skipAutoClose: o,
        sdk: t,
        hideHeader: n,
        persistent: s
      }
    ) }),
    e !== void 0 && /* @__PURE__ */ u(v, { event: e })
  ] }) : null;
};
export {
  H as StreamLayerSDKInsight,
  L as StreamLayerSDKInsightUI
};
