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