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