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