import { jsx as s, jsxs as g, Fragment as k } from "react/jsx-runtime";
import { A as y, M as $, s as I, u as l, T as L, S as M, C as D, p as T, k as E, O as A, m as h, a as F, l as O, c as P, b as R, d as V, e as Q, f as H, n as K, g as U } from "./masters.js";
import { useRef as j, useState as w, useEffect as v } from "react";
const q = (e, t, o) => {
  const r = t >= y.lg && t < y.xl ? 75 : 52;
  e.current && window.scrollTo({
    top: e.current.offsetTop - r,
    ...o
  });
}, z = /* @__PURE__ */ I("div")({
  name: "InviteFriendsContainer",
  class: "i1c9dygq",
  propsAsIs: !1
}), B = ({
  deepLink: e
}) => /* @__PURE__ */ s(z, {
  children: /* @__PURE__ */ s($, {
    inviteLink: e,
    inviteCardTitle: "It’s More Fun With Friends",
    inviteCardSubtext: "Invite and compete against your friends for the top spot on the leaderboard."
  })
}), W = /* @__PURE__ */ I("div")({
  name: "InviteLinkContainer",
  class: "i1odbhm4",
  propsAsIs: !1
}), _ = ({
  gamification: e,
  scrollNode: t,
  scrollStore: o
}) => {
  const r = j(null), {
    data: n,
    hasMore: i,
    loading: c,
    key: p
  } = l(e.leaderboardList.$store), {
    data: a
  } = l(e.deepLink.$store), [d, m] = L(r);
  return !n.length && !c ? /* @__PURE__ */ s(B, {
    deepLink: a
  }) : /* @__PURE__ */ g(k, {
    children: [/* @__PURE__ */ s(M, {
      items: n,
      scrollNode: t,
      scrollStore: o,
      fetchMore: e.leaderboardList.fetchMore,
      hasMore: i,
      openItemDetail: e.openUser,
      currentUserId: e.currentUserId.get()
    }, p), a && /* @__PURE__ */ s(W, {
      ref: r,
      children: /* @__PURE__ */ s(D, {
        onClick: () => d(a),
        title: "Invite Friends",
        description: "Challenge them now!"
      })
    }), m]
  });
}, G = ({ store: e, openQuestion: t }) => {
  const { sdk: o } = T(), r = l(e);
  return /* @__PURE__ */ s(E, { openQuestion: t, questions: r.data, controlVideo: o == null ? void 0 : o.controlVideoPlayer });
}, J = ({ userSummary: e }) => {
  var t;
  const [o, r] = w(void 0);
  return v(() => {
    const n = e.$store.subscribe((i) => {
      i && r(i);
    });
    return () => {
      n();
    };
  }, [e]), /* @__PURE__ */ s(A, { loading: !(o != null && o.summary), ...o == null ? void 0 : o.summary, successRate: (t = o == null ? void 0 : o.percentage) == null ? void 0 : t.correct });
}, X = ({ gamification: e, className: t, scrollStore: o, scrollNode: r, appNode: n, style: i, responsiveStore: c }) => {
  const { tabsShown: p } = l(o, { keys: ["tabsShown"] }), a = l(e.friendsTabEnabled), [d, m] = w(h.HOME), [, N] = F(), { sdkInDesktopView: S, screen: x } = l(c, { keys: ["sdkInDesktopView"] }), C = (u) => {
    N(() => {
      var b;
      m(u), S === !1 && (((b = n.current) == null ? void 0 : b.getBoundingClientRect().y) || 0) < 0 && q(n, x.size, { behavior: "instant" });
    });
  };
  v(() => o.subscribe((u) => {
    if (u.scrollPosition === 0) {
      o.setKey("tabsShown", !0);
      return;
    }
    c.get().sdkInDesktopView ? o.setKey("tabsShown", u.scrollDirection === "backward") : o.setKey("tabsShown", u.scrollDirection === "forward");
  }), [o, c]), v(() => {
    a || m(h.HOME);
  }, [a]);
  let f = "0px";
  return S ? f = p ? "0px" : "calc(0px - var(--header-height))" : f = p ? "var(--header-height)" : "0px", /* @__PURE__ */ g(O, { className: P(t, "SL-Tabs"), style: i, children: [
    a && /* @__PURE__ */ s(
      R,
      {
        style: {
          top: f
        },
        children: /* @__PURE__ */ s(V, { activePage: d, toggleActivePage: C })
      }
    ),
    d === h.HOME && /* @__PURE__ */ g(k, { children: [
      /* @__PURE__ */ s(Q, { children: /* @__PURE__ */ s(H, { children: /* @__PURE__ */ s(J, { userSummary: e.userSummary }) }) }),
      /* @__PURE__ */ s(K, { style: { flex: 1 }, children: /* @__PURE__ */ s(G, { openQuestion: e.openQuestion, store: e.feedList.getStore() }) })
    ] }),
    d === h.LEADERBOARD && /* @__PURE__ */ s(U, { children: /* @__PURE__ */ s(_, { scrollStore: o, scrollNode: r, gamification: e }) })
  ] });
}, oe = ({
  gamification: e,
  scrollStore: t,
  className: o,
  appNode: r,
  scrollNode: n,
  responsiveStore: i
}) => /* @__PURE__ */ s(X, {
  appNode: r,
  scrollStore: t,
  scrollNode: n,
  className: o,
  gamification: e,
  responsiveStore: i
});
export {
  oe as default
};
