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