@gamifyio/react 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var Pe=require('react'),core=require('@gamifyio/core'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Pe__default=/*#__PURE__*/_interopDefault(Pe);var fe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(o,s)=>(typeof require<"u"?require:o)[s]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var de=Pe.createContext(null),O=Pe.createContext(core.defaultTheme);function xe(){return typeof window>"u"}function me({config:e,theme:o,children:s}){let i=Pe.useRef(null),d=Pe.useMemo(()=>o?{...core.defaultTheme,...o}:core.defaultTheme,[o]),p=Pe.useMemo(()=>{if(xe())return null;if(i.current)return i.current;let a=new core.Gamify(e);return i.current=a,a},[e.apiKey,e.endpoint]);Pe.useEffect(()=>()=>{i.current&&(i.current.shutdown(),i.current=null);},[]);let t=Pe.useMemo(()=>p?{client:p,track:(a,n)=>p.track(a,n),identify:(a,n)=>p.identify(a,n),reset:()=>p.reset(),getUserId:()=>p.getUserId(),getAnonymousId:()=>p.getAnonymousId()}:null,[p]);return t?jsxRuntime.jsx(O.Provider,{value:d,children:jsxRuntime.jsx(de.Provider,{value:t,children:s})}):jsxRuntime.jsx(O.Provider,{value:d,children:s})}function N(){return Pe.useContext(de)}function V(){return Pe.useContext(O)}function be(){let e=N();if(!e)throw new Error("useGamify must be used within a GamifyProvider. Make sure your component is wrapped with <GamifyProvider>.");return e}function H(){let e=N();return Pe.useCallback((o,s)=>{e&&e.track(o,s);},[e])}function Ce(){let e=N();return Pe.useCallback((o,s)=>{e&&e.identify(o,s);},[e])}function Re(){let e=N(),[o,s]=Pe.useState({session:e?.client?.session?.getCachedSession()??null,loading:false,error:null}),i=Pe.useCallback(async(n,c,u)=>{if(!e?.client){s(g=>({...g,error:"SDK not initialized"}));return}s(g=>({...g,loading:true,error:null}));try{let g=await e.client.updateCart(n,c,u);s({session:g,loading:!1,error:null});}catch(g){let m=g instanceof Error?g.message:"Unknown error";s(b=>({...b,loading:false,error:m}));}},[e]),d=Pe.useCallback(async n=>{if(!e?.client?.session){s(c=>({...c,error:"SDK not initialized"}));return}s(c=>({...c,loading:true,error:null}));try{let c=await e.client.session.applyCoupon(n);s({session:c,loading:!1,error:null});}catch(c){let u=c instanceof Error?c.message:"Unknown error";s(g=>({...g,loading:false,error:u}));}},[e]),p=Pe.useCallback(async()=>{if(!e?.client?.session){s(n=>({...n,error:"SDK not initialized"}));return}s(n=>({...n,loading:true,error:null}));try{let n=await e.client.session.complete();s({session:n,loading:!1,error:null});}catch(n){let c=n instanceof Error?n.message:"Unknown error";s(u=>({...u,loading:false,error:c}));}},[e]),t=Pe.useCallback(()=>{e?.client?.session&&(e.client.session.clearSession(),s({session:null,loading:false,error:null}));},[e]),a=Pe.useCallback(async()=>{if(e?.client?.session){s(n=>({...n,loading:true,error:null}));try{let n=await e.client.session.getSession();s({session:n,loading:!1,error:null});}catch(n){let c=n instanceof Error?n.message:"Unknown error";s(u=>({...u,loading:false,error:c}));}}},[e]);return {...o,updateCart:i,applyCoupon:d,complete:p,clearSession:t,refresh:a}}function ee(e){let o=N(),[s,i]=Pe.useState({profile:o?.client?.loyalty?.getCachedProfile()??null,history:null,loading:false,error:null}),d=Pe.useCallback(async()=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getLoyaltyProfile();i(a=>({...a,profile:t,loading:!1,error:null}));}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]),p=Pe.useCallback(async(t,a)=>{if(!o?.client){i(n=>({...n,error:"SDK not initialized"}));return}i(n=>({...n,loading:true,error:null}));try{let n=await o.client.getLoyaltyHistory(t,a);i(c=>({...c,history:n,loading:!1,error:null}));}catch(n){let c=n instanceof Error?n.message:"Unknown error";i(u=>({...u,loading:false,error:c}));}},[o]);return Pe.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refreshProfile:d,refreshHistory:p}}function ve(){let e=N(),[o,s]=Pe.useState({referrerCode:e?.client?.referral?.getReferrer()??null,hasReferrer:e?.client?.referral?.hasReferrer()??false}),i=Pe.useCallback(t=>{e?.client?.referral&&(e.client.referral.setReferrer(t),s({referrerCode:t,hasReferrer:true}));},[e]),d=Pe.useCallback(()=>{e?.client?.referral&&(e.client.referral.clearReferrer(),s({referrerCode:null,hasReferrer:false}));},[e]),p=Pe.useCallback(()=>{if(e?.client?.referral){let t=e.client.referral.detectReferrerFromUrl();return t&&s({referrerCode:t,hasReferrer:true}),t}return null},[e]);return Pe.useEffect(()=>{if(e?.client?.referral){let t=e.client.referral.getReferrer();s({referrerCode:t,hasReferrer:t!==null});}},[e]),{...o,setReferrer:i,clearReferrer:d,detectFromUrl:p}}function K(e){let o=N(),[s,i]=Pe.useState({stats:o?.client?.affiliate?.getCachedStats()??null,loading:false,error:null}),d=Pe.useCallback(async(p=false)=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getAffiliateStats(p);i({stats:t,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]);return Pe.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refreshStats:d}}function re(e=10){let o=N(),[s,i]=Pe.useState({leaderboard:null,loading:false,error:null}),d=Pe.useCallback(async p=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getLeaderboard(p??e);i({leaderboard:t,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o,e]);return {...s,refresh:d}}function te(e){let o=N(),[s,i]=Pe.useState({quests:[],loading:false,error:null}),d=Pe.useCallback(async()=>{if(!o?.client){i(p=>({...p,error:"SDK not initialized"}));return}i(p=>({...p,loading:true,error:null}));try{let p=await o.client.getQuests();i({quests:p.quests,loading:!1,error:null});}catch(p){let t=p instanceof Error?p.message:"Unknown error";i(a=>({...a,loading:false,error:t}));}},[o]);return Pe.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d}}function oe(e){let o=N(),[s,i]=Pe.useState({streaks:[],stats:null,loading:false,error:null}),d=Pe.useCallback(async()=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getStreaks();i({streaks:t.streaks,stats:t.stats,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]),p=Pe.useCallback(async t=>{if(!o?.client)return i(a=>({...a,error:"SDK not initialized"})),null;try{let a=await o.client.useStreakFreeze(t);return await d(),a}catch(a){let n=a instanceof Error?a.message:"Unknown error";return i(c=>({...c,error:n})),null}},[o,d]);return Pe.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d,freeze:p}}function ne(e){let o=N(),[s,i]=Pe.useState({badges:[],stats:null,earned:[],locked:[],loading:false,error:null}),d=Pe.useCallback(async p=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getBadges(p??e?.category),a=t.badges.filter(c=>c.isUnlocked),n=t.badges.filter(c=>!c.isUnlocked);i({badges:t.badges,stats:t.stats,earned:a,locked:n,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o,e?.category]);return Pe.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d}}function ae(e){let o=N(),[s,i]=Pe.useState({items:[],userPoints:0,available:[],unavailable:[],loading:false,error:null}),d=Pe.useCallback(async()=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getRewardsStore(),a=t.items.filter(c=>c.isAvailable),n=t.items.filter(c=>!c.isAvailable);i({items:t.items,userPoints:t.userPoints,available:a,unavailable:n,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]),p=Pe.useCallback(async t=>{if(!o?.client)return i(a=>({...a,error:"SDK not initialized"})),null;i(a=>({...a,loading:true,error:null}));try{let a=await o.client.redeemReward(t);return await d(),a}catch(a){let n=a instanceof Error?a.message:"Unknown error";return i(c=>({...c,loading:false,error:n})),null}},[o,d]);return Pe.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d,redeem:p}}var Q="div",Y=({children:e})=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:e});try{let e=fe("framer-motion");e?.motion?.div&&(Q=e.motion.div),e?.AnimatePresence&&(Y=e.AnimatePresence);}catch{}var se=class extends Pe__default.default.Component{constructor(o){super(o),this.state={hasError:false,error:null};}static getDerivedStateFromError(o){return {hasError:true,error:o}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:jsxRuntime.jsx("div",{style:{padding:"16px",color:"#6c757d",fontSize:"14px",textAlign:"center"},children:"Unable to load this section. Please try refreshing the page."}):this.props.children}};function D(e,o){let s=i=>jsxRuntime.jsx(se,{fallback:o,children:jsxRuntime.jsx(e,{...i})});return s.displayName=`WithErrorBoundary(${e.displayName||e.name||"Component"})`,s}function he({pageName:e,properties:o,pathname:s}){let i=H(),d=Pe.useRef(null);return Pe.useEffect(()=>{if(typeof window>"u")return;if(s!==void 0){if(d.current===s)return;d.current=s;}let p=e??(typeof document<"u"?document.title:null)??(typeof window<"u"?window.location.pathname:"unknown");i("page_view",{page:p,url:typeof window<"u"?window.location.href:void 0,referrer:typeof document<"u"?document.referrer:void 0,...o});},[i,e,s,o]),null}function we({eventType:e,properties:o,children:s}){let i=H();return Pe.cloneElement(s,{onClick:p=>{i(e,o),s.props.onClick&&s.props.onClick(p);}})}function _(e){return {statsContainer:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:"16px",padding:"16px"},statsCard:{backgroundColor:e.cardBackground??e.background,borderRadius:"8px",padding:"16px",textAlign:"center",border:`1px solid ${e.cardBorder??e.border}`},statsValue:{fontSize:"24px",fontWeight:"bold",color:e.foreground,marginBottom:"4px"},statsLabel:{fontSize:"14px",color:e.foregroundSecondary},leaderboardContainer:{padding:"16px"},leaderboardList:{listStyle:"none",padding:0,margin:0},leaderboardRow:{display:"flex",alignItems:"center",padding:"12px",borderBottom:`1px solid ${e.border}`},leaderboardRowHighlighted:{display:"flex",alignItems:"center",padding:"12px",borderBottom:`1px solid ${e.border}`,backgroundColor:`${e.primary}20`},leaderboardRank:{fontWeight:"bold",width:"40px",color:e.foreground},leaderboardName:{flex:1,marginLeft:"12px",color:e.foreground},leaderboardStats:{color:e.foregroundSecondary,fontSize:"14px"},leaderboardEmpty:{textAlign:"center",padding:"32px",color:e.foregroundSecondary},referralContainer:{display:"flex",gap:"8px",padding:"8px"},referralInput:{flex:1,padding:"10px 12px",border:`1px solid ${e.inputBorder??e.border}`,borderRadius:"6px",fontSize:"14px",backgroundColor:e.inputBackground??e.backgroundSecondary,color:e.foreground},referralButton:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:e.buttonBackground??e.primary,color:e.buttonForeground??e.primaryForeground,cursor:"pointer",fontSize:"14px",fontWeight:"500"},tierBadge:{display:"flex",alignItems:"center",gap:"8px",padding:"12px",borderRadius:"8px",marginBottom:"12px"},tierBadgeIcon:{width:"20px",height:"20px"},tierBadgeText:{flex:1},tierBadgeName:{fontWeight:"500",fontSize:"14px"},tierBadgeRate:{fontSize:"12px",opacity:.8},referralCodeRow:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px",backgroundColor:e.backgroundSecondary,borderRadius:"8px",marginBottom:"12px"},referralCodeLabel:{fontSize:"12px",color:e.foregroundSecondary,marginBottom:"2px"},referralCodeValue:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.foreground},referralCodeCopyButton:{padding:"6px 10px",border:"none",borderRadius:"4px",backgroundColor:"transparent",color:e.foregroundSecondary,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},statsGrid2Col:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"12px",marginBottom:"12px"},earningsBreakdown:{borderTop:`1px solid ${e.border}`,paddingTop:"12px",marginTop:"12px"},earningsTitle:{fontSize:"14px",fontWeight:"500",color:e.foreground,marginBottom:"8px"},earningsRow:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 0"},earningsLabel:{fontSize:"14px",color:e.foregroundSecondary},earningsValue:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.foreground},earningsValueGreen:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.success},earningsValueYellow:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.warning},medalIcon:{width:"24px",height:"24px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"18px"},referrerSection:{borderTop:`1px solid ${e.border}`,paddingTop:"12px",marginTop:"12px"},referrerTitle:{fontSize:"14px",fontWeight:"500",color:e.foreground,marginBottom:"8px"},referrerBadge:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px",backgroundColor:`${e.success}15`,border:`1px solid ${e.success}30`,borderRadius:"8px"},referrerBadgeInfo:{display:"flex",alignItems:"center",gap:"8px",fontSize:"14px",color:e.foreground},referrerBadgeIcon:{color:e.success},referrerClearButton:{padding:"4px 8px",border:"none",borderRadius:"4px",backgroundColor:"transparent",color:e.foregroundSecondary,cursor:"pointer"},referrerInputRow:{display:"flex",gap:"8px",marginBottom:"8px"},referrerDetectButton:{width:"100%",padding:"10px 16px",border:`1px solid ${e.border}`,borderRadius:"6px",backgroundColor:e.backgroundSecondary,color:e.foreground,cursor:"pointer",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},filterTabs:{display:"flex",gap:"8px",marginBottom:"16px"},filterTab:{padding:"6px 12px",fontSize:"12px",borderRadius:"9999px",border:"none",cursor:"pointer",backgroundColor:e.backgroundSecondary,color:e.foregroundSecondary,transition:"all 0.2s"},filterTabActive:{padding:"6px 12px",fontSize:"12px",borderRadius:"9999px",border:"none",cursor:"pointer",backgroundColor:e.primary,color:e.primaryForeground},progressSummary:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px",backgroundColor:e.backgroundSecondary,borderRadius:"8px",marginBottom:"16px"},progressSummaryLeft:{display:"flex",alignItems:"center",gap:"12px"},progressSummaryIcon:{width:"40px",height:"40px",borderRadius:"50%",backgroundColor:`${e.primary}20`,display:"flex",alignItems:"center",justifyContent:"center",color:e.primary,fontSize:"18px"},progressSummaryText:{fontWeight:"500",fontSize:"16px",color:e.foreground},progressSummarySubtext:{fontSize:"12px",color:e.foregroundSecondary},progressSummaryBar:{width:"80px",height:"8px",backgroundColor:e.border,borderRadius:"4px",overflow:"hidden"},progressSummaryBarFill:{height:"100%",backgroundColor:e.primary,borderRadius:"4px"},badgeProgressBar:{width:"100%",height:"4px",backgroundColor:e.border,borderRadius:"2px",overflow:"hidden",marginTop:"8px"},badgeProgressFill:{height:"100%",backgroundColor:e.foregroundSecondary,borderRadius:"2px"},badgeProgressText:{fontSize:"10px",color:e.foregroundSecondary,marginTop:"4px"},badgeCheckmark:{position:"absolute",top:"8px",right:"8px",color:e.success}}}function Be({className:e,style:o,theme:s,autoRefresh:i=true,showTierBadge:d=true,showReferralCode:p=true,showEarningsBreakdown:t=true,renderLoading:a,renderError:n}){let c=V(),u=_(c),{stats:g,loading:m,error:b,refreshStats:C}=K({autoRefresh:i}),[B,I]=Pe.useState(false);if(Pe.useEffect(()=>{i&&C();},[i,C]),m)return a?a():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:c.foregroundSecondary},children:"Loading..."});if(b)return n?n(b):jsxRuntime.jsx("div",{style:{color:c.error,padding:"16px"},children:b});if(!g||!g.earnings)return null;let k={...u.statsCard,...s?.cardBackground&&{backgroundColor:s.cardBackground},...s?.cardBorder&&{border:`1px solid ${s.cardBorder}`}},P={...u.statsValue,...s?.valueColor&&{color:s.valueColor}},x=f=>new Intl.NumberFormat("en-US",{style:"currency",currency:g.earnings?.currency??"USD"}).format(f/100),v=async()=>{if(g.referralCode)try{await navigator.clipboard.writeText(g.referralCode),I(!0),setTimeout(()=>I(!1),2e3);}catch(f){console.error("Failed to copy:",f);}},h=(f=>{if(!f)return "#6c757d";let z=f.toLowerCase();return z.includes("elite")||z.includes("diamond")||z.includes("platinum")||z.includes("gold")||z.includes("vip")?"#FFD700":z.includes("silver")||z.includes("pro")?"#C0C0C0":z.includes("bronze")||z.includes("starter")?"#CD7F32":"#0d6efd"})(g.tier?.name),y={padding:"16px",...s?.cardBackground&&{backgroundColor:s.cardBackground},...s?.cardBorder&&{border:`1px solid ${s.cardBorder}`},...o};return jsxRuntime.jsxs("div",{className:e,style:y,children:[d&&jsxRuntime.jsxs("div",{style:{...u.tierBadge,backgroundColor:g.tier?`${h}20`:c.backgroundSecondary},children:[jsxRuntime.jsx("span",{style:{...u.tierBadgeIcon,color:h},children:"\u{1F451}"}),jsxRuntime.jsxs("div",{style:u.tierBadgeText,children:[jsxRuntime.jsx("div",{style:{...u.tierBadgeName,color:g.tier?h:c.foregroundSecondary},children:g.tier?`${g.tier.name} Affiliate`:"No Tier"}),jsxRuntime.jsx("div",{style:{...u.tierBadgeRate,color:g.tier?h:c.foregroundSecondary},children:g.tier?`${g.tier.value}% commission rate`:"Refer users to unlock affiliate status"})]})]}),p&&g.referralCode&&jsxRuntime.jsxs("div",{style:u.referralCodeRow,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:u.referralCodeLabel,children:"Your referral code"}),jsxRuntime.jsx("div",{style:u.referralCodeValue,children:g.referralCode})]}),jsxRuntime.jsx("button",{type:"button",onClick:v,style:u.referralCodeCopyButton,"aria-label":"Copy referral code",children:B?"\u2713":"\u{1F4CB}"})]}),jsxRuntime.jsxs("div",{style:u.statsGrid2Col,children:[jsxRuntime.jsxs("div",{style:k,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:c.foregroundSecondary,marginBottom:"4px"},children:[jsxRuntime.jsx("span",{children:"\u{1F465}"}),jsxRuntime.jsx("span",{style:{fontSize:"12px"},children:"Referrals"})]}),jsxRuntime.jsx("div",{style:{...P,fontFamily:"monospace"},children:g.referralCount})]}),jsxRuntime.jsxs("div",{style:k,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:c.foregroundSecondary,marginBottom:"4px"},children:[jsxRuntime.jsx("span",{children:"\u{1F4B0}"}),jsxRuntime.jsx("span",{style:{fontSize:"12px"},children:"Commissions"})]}),jsxRuntime.jsx("div",{style:{...P,fontFamily:"monospace"},children:g.earnings.transactionCount})]})]}),t&&jsxRuntime.jsxs("div",{style:u.earningsBreakdown,children:[jsxRuntime.jsx("div",{style:u.earningsTitle,children:"Earnings"}),jsxRuntime.jsxs("div",{style:u.earningsRow,children:[jsxRuntime.jsx("span",{style:u.earningsLabel,children:"Total Earned"}),jsxRuntime.jsx("span",{style:u.earningsValueGreen,children:x(g.earnings.totalEarned)})]}),jsxRuntime.jsxs("div",{style:u.earningsRow,children:[jsxRuntime.jsx("span",{style:u.earningsLabel,children:"Pending"}),jsxRuntime.jsx("span",{style:u.earningsValueYellow,children:x(g.earnings.totalPending)})]}),jsxRuntime.jsxs("div",{style:u.earningsRow,children:[jsxRuntime.jsx("span",{style:u.earningsLabel,children:"Paid Out"}),jsxRuntime.jsx("span",{style:{...u.earningsValue,color:c.foregroundSecondary},children:x(g.earnings.totalPaid)})]})]})]})}var Ie=D(Be);function ze({limit:e=10,className:o,style:s,currentUserId:i,emptyMessage:d="No leaderboard data available yet.",showMedals:p=true,showTierInfo:t=true,showEarnings:a=true,theme:n,renderRow:c,renderLoading:u,renderError:g}){let m=V(),b=_(m),{leaderboard:C,loading:B,error:I,refresh:k}=re(e);if(Pe.useEffect(()=>{k();},[k]),B)return u?u():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:m.foregroundSecondary},children:"Loading..."});if(I)return g?g(I):jsxRuntime.jsx("div",{style:{color:m.error,padding:"16px"},children:I});if(!C||C.entries.length===0)return jsxRuntime.jsx("div",{className:o,style:{...b.leaderboardEmpty,...s},children:d});let P=f=>{if(!p)return null;switch(f){case 1:return m.medalGold;case 2:return m.medalSilver;case 3:return m.medalBronze;default:return null}},x=f=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(f/100),v=f=>({...f?b.leaderboardRowHighlighted:b.leaderboardRow,...n?.rowBackground&&!f&&{backgroundColor:n.rowBackground},...n?.highlightBackground&&f&&{backgroundColor:n.highlightBackground},...f&&{backgroundColor:`${m.primary}15`,border:`1px solid ${m.primary}40`,borderRadius:"8px"}}),A=n?.textColor?{color:n.textColor}:{},h=n?.secondaryColor?{...b.leaderboardStats,color:n.secondaryColor}:b.leaderboardStats,y=i?C.entries.find(f=>f.userId===i)?.rank:null;return jsxRuntime.jsxs("div",{className:o,style:{...b.leaderboardContainer,...s},children:[y&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"8px"},children:jsxRuntime.jsxs("span",{style:{fontSize:"12px",backgroundColor:`${m.primary}30`,color:m.primary,padding:"4px 8px",borderRadius:"9999px"},children:["Your rank: #",y]})}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:jsxRuntime.jsx(Y,{mode:"popLayout",children:C.entries.map((f,z)=>{let L=i===f.userId,E=P(f.rank);if(c)return jsxRuntime.jsx("div",{children:c(f,L)},f.userId);let w=jsxRuntime.jsxs("div",{style:v(L),children:[jsxRuntime.jsx("div",{style:b.medalIcon,children:E?jsxRuntime.jsx("span",{style:{color:E},children:"\u{1F3C5}"}):jsxRuntime.jsxs("span",{style:{fontSize:"14px",fontFamily:"monospace",color:m.foregroundSecondary},children:["#",f.rank]})}),jsxRuntime.jsxs("div",{style:{flex:1,marginLeft:"12px"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{...b.leaderboardName,...A,marginLeft:0},children:f.displayName??`User ${f.userId.slice(0,8)}`}),L&&jsxRuntime.jsx("span",{style:{fontSize:"12px",color:m.primary},children:"(You)"})]}),t&&f.tier&&jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:m.foregroundSecondary},children:[f.tier.name," (",f.tier.value,"%)"]})]}),jsxRuntime.jsxs("div",{style:{textAlign:"right"},children:[jsxRuntime.jsxs("div",{style:{fontFamily:"monospace",fontSize:"14px",fontWeight:"500",color:m.foreground},children:[f.referralCount," referrals"]}),a&&f.totalEarnings!==void 0&&jsxRuntime.jsx("div",{style:{...h,fontFamily:"monospace"},children:x(f.totalEarnings)})]})]});return Q!=="div"?jsxRuntime.jsx(Q,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},transition:{delay:z*.05},children:w},f.userId):jsxRuntime.jsx("div",{children:w},f.userId)})})}),jsxRuntime.jsx("p",{style:{fontSize:"12px",color:"#6c757d",textAlign:"center",marginTop:"12px"},children:"Rankings based on total referrals"})]})}var Te=D(ze);function Ae({baseUrl:e,className:o,style:s,copyButtonText:i="Copy",copiedText:d="Copied!",shareButtonText:p="Share",shareTitle:t="Check this out!",shareText:a="Join using my referral link",showShareButton:n=true,showReferrerAttribution:c=true,referrerCode:u,onSetReferrer:g,onDetectFromUrl:m,onClearReferrer:b,theme:C,onCopy:B,onShare:I}){let k=V(),P=_(k),{stats:x}=K({autoRefresh:true}),[v,A]=Pe.useState(false),[h,y]=Pe.useState(""),f=x?.referralCode;if(!f)return null;let z=typeof window<"u"?window.location.origin:"",L=`${e??z}?ref=${f}`,E=async()=>{try{await navigator.clipboard.writeText(L),A(!0),B?.(L),setTimeout(()=>A(!1),2e3);}catch(U){console.error("Failed to copy:",U);}},w=async()=>{if(typeof navigator<"u"&&navigator.share)try{await navigator.share({title:t,text:a,url:L}),I?.(L);}catch(U){U.name!=="AbortError"&&console.error("Failed to share:",U);}},R=()=>{h.trim()&&g&&(g(h.trim()),y(""));},G=typeof navigator<"u"&&"share"in navigator,j={...P.referralInput,...C?.inputBackground&&{backgroundColor:C.inputBackground},...C?.inputBorder&&{border:`1px solid ${C.inputBorder}`},...C?.inputColor&&{color:C.inputColor}},q={...P.referralButton,...C?.buttonBackground&&{backgroundColor:C.buttonBackground},...C?.buttonColor&&{color:C.buttonColor}},ue={padding:"16px",...s};return jsxRuntime.jsxs("div",{className:o,style:ue,children:[jsxRuntime.jsxs("div",{style:{marginBottom:"8px"},children:[jsxRuntime.jsx("p",{style:{fontSize:"14px",color:k.foregroundSecondary,marginBottom:"8px"},children:"Your unique referral link:"}),jsxRuntime.jsxs("div",{style:P.referralContainer,children:[jsxRuntime.jsx("input",{type:"text",readOnly:true,value:L,style:{...j,fontFamily:"monospace",fontSize:"12px"},onClick:U=>U.target.select()}),jsxRuntime.jsx("button",{type:"button",onClick:E,style:q,children:v?"\u2713":"\u{1F4CB}"}),n&&G&&jsxRuntime.jsx("button",{type:"button",onClick:w,style:q,children:p})]}),jsxRuntime.jsxs("p",{style:{fontSize:"12px",color:k.foregroundSecondary,marginTop:"4px"},children:["Code: ",jsxRuntime.jsx("span",{style:{fontFamily:"monospace",fontWeight:"500",color:k.foreground},children:f})]})]}),c&&jsxRuntime.jsxs("div",{style:P.referrerSection,children:[jsxRuntime.jsx("p",{style:P.referrerTitle,children:"Referrer Attribution"}),u?jsxRuntime.jsxs("div",{style:P.referrerBadge,children:[jsxRuntime.jsxs("div",{style:P.referrerBadgeInfo,children:[jsxRuntime.jsx("span",{style:P.referrerBadgeIcon,children:"\u{1F464}"}),jsxRuntime.jsxs("span",{children:["Referred by: ",jsxRuntime.jsx("span",{style:{fontFamily:"monospace",fontWeight:"500"},children:u})]})]}),b&&jsxRuntime.jsx("button",{type:"button",onClick:b,style:P.referrerClearButton,"aria-label":"Clear referrer",children:"\u2715"})]}):jsxRuntime.jsxs("div",{children:[g&&jsxRuntime.jsxs("div",{style:P.referrerInputRow,children:[jsxRuntime.jsx("input",{type:"text",value:h,onChange:U=>y(U.target.value),placeholder:"Enter referrer code...",style:{...j,fontFamily:"monospace",fontSize:"12px"}}),jsxRuntime.jsx("button",{type:"button",onClick:R,disabled:!h.trim(),style:{...q,opacity:h.trim()?1:.5,cursor:h.trim()?"pointer":"not-allowed"},children:"Set"})]}),m&&jsxRuntime.jsxs("button",{type:"button",onClick:m,style:P.referrerDetectButton,children:[jsxRuntime.jsx("span",{children:"\u{1F517}"}),"Detect from URL"]})]})]})]})}var Le=D(Ae),S={questProgressBar:{width:"100%",height:"8px",backgroundColor:"#e9ecef",borderRadius:"4px",overflow:"hidden",marginBottom:"12px"},questProgressFill:{height:"100%",backgroundColor:"#0d6efd",borderRadius:"4px",transition:"width 0.3s ease"},streakContainer:{display:"flex",alignItems:"center",padding:"16px",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef"},streakFlame:{fontSize:"32px",marginRight:"12px"},streakCount:{fontSize:"28px",fontWeight:"bold",color:"#212529",marginRight:"8px"},streakLabel:{fontSize:"14px",color:"#6c757d"},streakInfo:{flex:1},streakName:{fontSize:"16px",fontWeight:"600",color:"#212529"},streakStatus:{fontSize:"12px",padding:"2px 8px",borderRadius:"10px",marginLeft:"8px"},freezeButton:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#17a2b8",color:"white",cursor:"pointer",fontSize:"14px",display:"flex",alignItems:"center",gap:"6px"},freezeButtonDisabled:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#6c757d",color:"white",cursor:"not-allowed",fontSize:"14px",opacity:.6},levelContainer:{padding:"16px",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef"},levelHeader:{display:"flex",alignItems:"center",marginBottom:"12px"},levelIcon:{width:"48px",height:"48px",borderRadius:"50%",marginRight:"12px",backgroundColor:"#e9ecef",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"24px"},levelInfo:{flex:1},levelTierName:{fontSize:"18px",fontWeight:"600",color:"#212529"},levelPoints:{fontSize:"14px",color:"#6c757d"},levelProgressContainer:{marginTop:"12px"},levelProgressHeader:{display:"flex",justifyContent:"space-between",marginBottom:"6px",fontSize:"13px"},levelProgressBar:{width:"100%",height:"10px",backgroundColor:"#e9ecef",borderRadius:"5px",overflow:"hidden"},levelProgressFill:{height:"100%",background:"linear-gradient(90deg, #667eea 0%, #764ba2 100%)",borderRadius:"5px",transition:"width 0.3s ease"},levelBenefits:{marginTop:"16px",padding:"12px",backgroundColor:"#f8f9fa",borderRadius:"6px"},levelBenefitsTitle:{fontSize:"14px",fontWeight:"600",color:"#212529",marginBottom:"8px"},levelBenefitsList:{listStyle:"none",padding:0,margin:0,fontSize:"13px",color:"#495057"},levelBenefitItem:{padding:"4px 0",display:"flex",alignItems:"center"},rewardStoreGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:"16px",padding:"16px"},rewardCard:{display:"flex",flexDirection:"column",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef",overflow:"hidden"},rewardCardUnavailable:{display:"flex",flexDirection:"column",backgroundColor:"#f8f9fa",borderRadius:"8px",border:"1px solid #e9ecef",overflow:"hidden",opacity:.7},rewardImage:{width:"100%",height:"120px",objectFit:"cover",backgroundColor:"#e9ecef"},rewardContent:{padding:"12px",flex:1,display:"flex",flexDirection:"column"},rewardName:{fontSize:"16px",fontWeight:"600",color:"#212529",marginBottom:"4px"},rewardDescription:{fontSize:"13px",color:"#6c757d",marginBottom:"8px",flex:1},rewardCost:{fontSize:"14px",fontWeight:"600",color:"#0d6efd",marginBottom:"8px"},rewardButton:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:"#0d6efd",color:"white",cursor:"pointer",fontSize:"14px",fontWeight:"500",width:"100%"},rewardButtonDisabled:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:"#6c757d",color:"white",cursor:"not-allowed",fontSize:"14px",fontWeight:"500",width:"100%"},rewardPointsHeader:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",backgroundColor:"#f8f9fa",borderRadius:"8px",marginBottom:"16px"},rewardPointsLabel:{fontSize:"14px",color:"#6c757d"},rewardPointsValue:{fontSize:"24px",fontWeight:"bold",color:"#212529"},questAccordion:{borderRadius:"8px",overflow:"hidden",marginBottom:"8px"},questAccordionHeader:{width:"100%",padding:"12px",display:"flex",alignItems:"center",gap:"12px",border:"none",backgroundColor:"transparent",cursor:"pointer",textAlign:"left"},questAccordionIcon:{width:"40px",height:"40px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"20px",flexShrink:0},questAccordionInfo:{flex:1,minWidth:0},questAccordionTitle:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},questAccordionName:{fontWeight:"500",fontSize:"14px",color:"#212529"},questAccordionStatusBadge:{fontSize:"11px",padding:"2px 8px",borderRadius:"9999px",fontWeight:"500"},questAccordionMeta:{display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",color:"#6c757d"},questAccordionChevron:{color:"#6c757d",transition:"transform 0.2s",flexShrink:0},questAccordionContent:{padding:"0 12px 12px",overflow:"hidden"}};function Ne(e){switch(e){case "completed":return {bg:"#d4edda",color:"#155724"};case "in_progress":return {bg:"#cce5ff",color:"#004085"};case "active":return {bg:"#cce5ff",color:"#004085"};case "frozen":return {bg:"#cce5ff",color:"#17a2b8"};case "at_risk":return {bg:"#fff3cd",color:"#856404"};case "broken":return {bg:"#f8d7da",color:"#721c24"};default:return {bg:"#e9ecef",color:"#6c757d"}}}function Ee({questId:e,hideCompleted:o=false,className:s,style:i,expandable:d=true,defaultExpandedId:p,showXpReward:t=true,onComplete:a,theme:n,renderLoading:c,renderError:u,renderQuest:g}){let{quests:m,loading:b,error:C,refresh:B}=te({autoRefresh:true}),I=Pe.useRef(new Map),[k,P]=Pe.useState(null);if(Pe.useEffect(()=>{B();},[B]),Pe.useEffect(()=>{a&&m.forEach(f=>{let z=I.current.get(f.id);z&&z.status!=="completed"&&f.status==="completed"&&a(f);});let y=new Map;m.forEach(f=>y.set(f.id,f)),I.current=y;},[m,a]),Pe.useEffect(()=>{if(m.length>0&&k===null)if(p)P(p);else {let y=m.find(f=>f.status==="in_progress");P(y?.id??null);}},[m,p,k]),b)return c?c():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(C)return u?u(C):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:C});let x=m;if(e&&(x=m.filter(y=>y.id===e)),o&&(x=x.filter(y=>y.status!=="completed")),x.length===0)return jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"24px",color:"#6c757d"},children:[jsxRuntime.jsx("span",{style:{fontSize:"40px",display:"block",marginBottom:"8px",opacity:.5},children:"\u{1F3AF}"}),jsxRuntime.jsx("p",{children:"No quests available"})]});let v=y=>{switch(y){case "completed":return {backgroundColor:"rgba(40, 167, 69, 0.2)",color:"#28a745"};case "in_progress":return {backgroundColor:"rgba(13, 110, 253, 0.2)",color:"#0d6efd"};default:return {backgroundColor:"#f8f9fa",color:"#6c757d"}}},A=y=>{switch(y){case "completed":return {backgroundColor:"rgba(40, 167, 69, 0.05)",borderColor:"rgba(40, 167, 69, 0.2)"};case "in_progress":return {backgroundColor:"rgba(13, 110, 253, 0.05)",borderColor:"rgba(13, 110, 253, 0.2)"};default:return {backgroundColor:"#f8f9fa",borderColor:"#e9ecef"}}},h=y=>{d&&P(k===y?null:y);};return jsxRuntime.jsx("div",{className:s,style:{...i,display:"flex",flexDirection:"column",gap:"12px"},children:jsxRuntime.jsx(Y,{mode:"popLayout",children:x.map(y=>{if(g)return jsxRuntime.jsx("div",{children:g(y)},y.id);let f=!d||k===y.id,z=v(y.status),L=A(y.status),E=jsxRuntime.jsxs("div",{style:{...S.questAccordion,border:"1px solid",...L,...n?.cardBackground&&{backgroundColor:n.cardBackground},...n?.cardBorder&&{borderColor:n.cardBorder}},children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>h(y.id),style:{...S.questAccordionHeader,cursor:d?"pointer":"default"},children:[jsxRuntime.jsx("div",{style:{...S.questAccordionIcon,backgroundColor:y.status==="completed"?"rgba(40, 167, 69, 0.2)":"rgba(13, 110, 253, 0.2)"},children:y.status==="completed"?jsxRuntime.jsx("span",{style:{color:"#28a745"},children:"\u2713"}):jsxRuntime.jsx("span",{style:{color:"#0d6efd"},children:"\u{1F3AF}"})}),jsxRuntime.jsxs("div",{style:S.questAccordionInfo,children:[jsxRuntime.jsxs("div",{style:S.questAccordionTitle,children:[jsxRuntime.jsx("span",{style:{...S.questAccordionName,...n?.textColor&&{color:n.textColor}},children:y.name}),jsxRuntime.jsx("span",{style:{...S.questAccordionStatusBadge,...z},children:y.status==="completed"?"Complete":y.status==="in_progress"?`${y.percentComplete}%`:"Not Started"})]}),jsxRuntime.jsxs("div",{style:S.questAccordionMeta,children:[t&&y.xpReward>0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:"\u2B50"}),jsxRuntime.jsxs("span",{children:["+",y.xpReward," XP"]}),jsxRuntime.jsx("span",{style:{color:"#e9ecef"},children:"|"})]}),jsxRuntime.jsxs("span",{children:[y.steps.length," steps"]})]})]}),d&&jsxRuntime.jsx("span",{style:{...S.questAccordionChevron,transform:f?"rotate(90deg)":"rotate(0deg)"},children:"\u25B6"})]}),f&&jsxRuntime.jsxs("div",{style:S.questAccordionContent,children:[y.status!=="completed"&&jsxRuntime.jsx("div",{style:{...S.questProgressBar,marginBottom:"12px",height:"6px"},children:jsxRuntime.jsx("div",{style:{...S.questProgressFill,width:`${y.percentComplete}%`,...n?.progressColor&&{backgroundColor:n.progressColor}}})}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:y.steps.map((w,R)=>jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px",padding:"8px",borderRadius:"6px",opacity:w.completed?.6:1},children:[jsxRuntime.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:"bold",flexShrink:0,backgroundColor:w.completed?"rgba(40, 167, 69, 0.2)":"#f8f9fa",color:w.completed?"#28a745":"#6c757d"},children:w.completed?"\u2713":R+1}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:{fontSize:"14px",fontWeight:"500",textDecoration:w.completed?"line-through":"none",color:w.completed?"#6c757d":"#212529"},children:w.name}),jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:"#6c757d"},children:[w.currentCount,"/",w.requiredCount,w.requiredCount>1&&!w.completed&&jsxRuntime.jsxs("span",{style:{marginLeft:"8px"},children:["(",Math.round(w.currentCount/w.requiredCount*100),"%)"]})]})]})]},w.id))})]})]});return Q!=="div"?jsxRuntime.jsx(Q,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},children:E},y.id):jsxRuntime.jsx("div",{children:E},y.id)})})})}var Fe=D(Ee);function We({ruleId:e,size:o="md",showFreezeButton:s=true,className:i,style:d,onFreeze:p,theme:t,renderLoading:a,renderError:n}){let{streaks:c,stats:u,loading:g,error:m,freeze:b,refresh:C}=oe({autoRefresh:true}),[B,I]=Pe.useState(false);if(Pe.useEffect(()=>{C();},[C]),g)return a?a():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return n?n(m):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:m});let k=c;if(e&&(k=c.filter(v=>v.id===e)),k.length===0)return jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:"#6c757d"},children:"No streaks available"});let P={sm:{flame:"24px",count:"20px",container:"12px"},md:{flame:"32px",count:"28px",container:"16px"},lg:{flame:"48px",count:"40px",container:"20px"}},x=async v=>{I(true);try{let A=await b(v);A&&p&&p(v,A.remainingFreezes);}finally{I(false);}};return jsxRuntime.jsx("div",{className:i,style:d,children:k.map(v=>{let A=Ne(v.status),h=v.freezeInventory>0&&!v.freezeUsedToday;return jsxRuntime.jsxs("div",{style:{...S.streakContainer,padding:P[o].container,...t?.cardBackground&&{backgroundColor:t.cardBackground}},children:[jsxRuntime.jsx("span",{style:{...S.streakFlame,fontSize:P[o].flame,...t?.flameColor&&{color:t.flameColor}},children:"\u{1F525}"}),jsxRuntime.jsx("span",{style:{...S.streakCount,fontSize:P[o].count,...t?.countColor&&{color:t.countColor}},children:v.currentCount}),jsxRuntime.jsxs("div",{style:S.streakInfo,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx("span",{style:S.streakName,children:v.name}),jsxRuntime.jsx("span",{style:{...S.streakStatus,backgroundColor:A.bg,color:A.color},children:v.status})]}),jsxRuntime.jsxs("span",{style:S.streakLabel,children:["Best: ",v.maxStreak," days"]})]}),s&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{x(v.id);},disabled:!h||B,style:h?S.freezeButton:S.freezeButtonDisabled,children:[jsxRuntime.jsx("span",{children:"\u2744\uFE0F"}),jsxRuntime.jsx("span",{children:v.freezeInventory})]})]},v.id)})})}var Ge=D(We);function Ue({showLocked:e=true,category:o,columns:s=2,className:i,style:d,showProgressSummary:p=true,showFilterTabs:t=true,showStats:a,onBadgeClick:n,theme:c,renderLoading:u,renderError:g,renderBadge:m}){let b=V(),C=_(b),{badges:B,stats:I,loading:k,error:P,refresh:x}=ne({autoRefresh:true,category:o}),[v,A]=Pe.useState("all"),h=p??a??true;if(Pe.useEffect(()=>{x(o);},[x,o]),k)return u?u():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:b.foregroundSecondary},children:"Loading..."});if(P)return g?g(P):jsxRuntime.jsx("div",{style:{color:b.error,padding:"16px"},children:P});let y=B;v==="unlocked"?y=B.filter(R=>R.isUnlocked):v==="locked"?y=B.filter(R=>!R.isUnlocked):e||(y=B.filter(R=>R.isUnlocked));let f=R=>{switch(R){case "LEGENDARY":return {color:b.rarityLegendary,bg:`${b.rarityLegendary}15`};case "EPIC":return {color:b.rarityEpic,bg:`${b.rarityEpic}15`};case "RARE":return {color:b.rarityRare,bg:`${b.rarityRare}15`};case "COMMON":default:return {color:b.rarityCommon,bg:`${b.rarityCommon}15`}}},z={display:"grid",gridTemplateColumns:`repeat(${s}, 1fr)`,gap:"12px",padding:"0"},L=I?.unlocked??B.filter(R=>R.isUnlocked).length,E=I?.total??B.length,w=E>0?L/E*100:0;return jsxRuntime.jsxs("div",{className:i,style:{...d,padding:"16px"},children:[h&&jsxRuntime.jsxs("div",{style:C.progressSummary,children:[jsxRuntime.jsxs("div",{style:C.progressSummaryLeft,children:[jsxRuntime.jsx("div",{style:C.progressSummaryIcon,children:"\u2728"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:C.progressSummaryText,children:[L," / ",E]}),jsxRuntime.jsx("div",{style:C.progressSummarySubtext,children:"Badges Earned"})]})]}),jsxRuntime.jsx("div",{style:C.progressSummaryBar,children:jsxRuntime.jsx("div",{style:{...C.progressSummaryBarFill,width:`${w}%`}})})]}),t&&jsxRuntime.jsx("div",{style:C.filterTabs,children:["all","unlocked","locked"].map(R=>jsxRuntime.jsx("button",{type:"button",onClick:()=>A(R),style:v===R?C.filterTabActive:C.filterTab,children:R==="all"?"All":R==="unlocked"?"Earned":"Locked"},R))}),jsxRuntime.jsx("div",{style:z,children:jsxRuntime.jsx(Y,{mode:"popLayout",children:y.map(R=>{if(m)return jsxRuntime.jsx("div",{children:m(R)},R.id);let G=f(R.rarity),j=jsxRuntime.jsxs("div",{style:{position:"relative",padding:"12px",borderRadius:"8px",border:"1px solid",cursor:n?"pointer":"default",transition:"all 0.2s",...R.isUnlocked?{backgroundColor:G.bg,borderColor:`${G.color}40`,...c?.cardBackground&&{backgroundColor:c.cardBackground},...c?.cardBorder&&{borderColor:c.cardBorder}}:{backgroundColor:b.backgroundSecondary,borderColor:b.border,opacity:.6}},onClick:()=>n?.(R),onKeyDown:q=>q.key==="Enter"&&n?.(R),role:n?"button":void 0,tabIndex:n?0:void 0,children:[R.isUnlocked&&jsxRuntime.jsx("div",{style:C.badgeCheckmark,children:"\u2713"}),jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:jsxRuntime.jsx("div",{style:{width:"32px",height:"32px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:R.isUnlocked?`${G.color}20`:b.backgroundSecondary},children:R.iconUrl?jsxRuntime.jsx("img",{src:R.iconUrl,alt:R.name,style:{width:"16px",height:"16px",objectFit:"contain"}}):R.isUnlocked?jsxRuntime.jsx("span",{style:{color:G.color},children:"\u{1F3C5}"}):jsxRuntime.jsx("span",{style:{color:b.foregroundSecondary},children:"\u{1F512}"})})}),jsxRuntime.jsx("h4",{style:{fontSize:"14px",fontWeight:"500",marginBottom:"4px",color:b.foreground},children:R.name}),R.description&&jsxRuntime.jsx("p",{style:{fontSize:"12px",color:b.foregroundSecondary,marginBottom:"8px",lineHeight:1.4},children:R.description}),jsxRuntime.jsx("span",{style:{fontSize:"10px",padding:"2px 6px",borderRadius:"9999px",fontWeight:"500",backgroundColor:`${G.color}20`,color:G.color},children:R.rarity})]});return Q!=="div"?jsxRuntime.jsx(Q,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},children:j},R.id):jsxRuntime.jsx("div",{children:j},R.id)})})}),y.length===0&&jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"24px",color:"#6c757d"},children:[jsxRuntime.jsx("span",{style:{fontSize:"40px",display:"block",marginBottom:"8px",opacity:.5},children:"\u{1F3C5}"}),jsxRuntime.jsx("p",{children:"No badges found"})]})]})}var De=D(Ue);function Me({showNextTier:e=true,showBenefits:o=false,className:s,style:i,theme:d,renderLoading:p,renderError:t}){let{profile:a,loading:n,error:c,refreshProfile:u}=ee({autoRefresh:true});if(Pe.useEffect(()=>{u();},[u]),n)return p?p():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(c)return t?t(c):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:c});if(!a)return null;let g=a.nextTier?Math.min(100,a.points/a.nextTier.minPoints*100):100,m={...S.levelContainer,...d?.cardBackground&&{backgroundColor:d.cardBackground}},b={...S.levelProgressFill,width:`${g}%`,...d?.progressGradient&&{background:d.progressGradient}};return jsxRuntime.jsxs("div",{className:s,style:{...m,...i},children:[jsxRuntime.jsxs("div",{style:S.levelHeader,children:[jsxRuntime.jsx("div",{style:{...S.levelIcon,...a.tier?.color&&{backgroundColor:a.tier.color}},children:a.tier?.iconUrl?jsxRuntime.jsx("img",{src:a.tier.iconUrl,alt:a.tier.name,style:{width:"100%",height:"100%",borderRadius:"50%"}}):"\u2B50"}),jsxRuntime.jsxs("div",{style:S.levelInfo,children:[jsxRuntime.jsx("div",{style:{...S.levelTierName,...d?.textColor&&{color:d.textColor}},children:a.tier?.name??"No Tier"}),jsxRuntime.jsxs("div",{style:S.levelPoints,children:[a.points.toLocaleString()," points"]})]})]}),e&&a.nextTier&&jsxRuntime.jsxs("div",{style:S.levelProgressContainer,children:[jsxRuntime.jsxs("div",{style:S.levelProgressHeader,children:[jsxRuntime.jsxs("span",{style:{color:"#6c757d"},children:["Progress to ",a.nextTier.name]}),jsxRuntime.jsxs("span",{style:{fontWeight:"500"},children:[a.nextTier.pointsNeeded.toLocaleString()," points needed"]})]}),jsxRuntime.jsx("div",{style:S.levelProgressBar,children:jsxRuntime.jsx("div",{style:b})})]}),o&&a.tier?.benefits&&Object.keys(a.tier.benefits).length>0&&jsxRuntime.jsxs("div",{style:S.levelBenefits,children:[jsxRuntime.jsx("div",{style:S.levelBenefitsTitle,children:"Your Benefits"}),jsxRuntime.jsx("ul",{style:S.levelBenefitsList,children:Object.entries(a.tier.benefits).map(([C,B])=>jsxRuntime.jsxs("li",{style:S.levelBenefitItem,children:[jsxRuntime.jsx("span",{style:{marginRight:"8px",color:"#28a745"},children:"\u2713"}),String(B)]},C))})]})]})}var $e=D(Me);function Qe({showUnavailable:e=true,className:o,style:s,showPointsHeader:i=true,onRedeem:d,theme:p,renderLoading:t,renderError:a,renderItem:n}){let{items:c,userPoints:u,loading:g,error:m,redeem:b,refresh:C}=ae({autoRefresh:true}),[B,I]=Pe.useState(null);if(Pe.useEffect(()=>{C();},[C]),g&&c.length===0)return t?t():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return a?a(m):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:m});let k=c;e||(k=c.filter(x=>x.isAvailable));let P=async x=>{I(x.id);try{let v=await b(x.id);v&&d&&d(x,v);}finally{I(null);}};return jsxRuntime.jsxs("div",{className:o,style:s,children:[i&&jsxRuntime.jsxs("div",{style:S.rewardPointsHeader,children:[jsxRuntime.jsx("span",{style:S.rewardPointsLabel,children:"Your Points"}),jsxRuntime.jsx("span",{style:S.rewardPointsValue,children:u.toLocaleString()})]}),jsxRuntime.jsx("div",{style:S.rewardStoreGrid,children:k.map(x=>{if(n)return jsxRuntime.jsx("div",{children:n(x,()=>{P(x);})},x.id);let v=x.isAvailable?{...S.rewardCard,...p?.cardBackground&&{backgroundColor:p.cardBackground}}:S.rewardCardUnavailable,A=x.isAvailable&&x.canAfford?{...S.rewardButton,...p?.buttonColor&&{backgroundColor:p.buttonColor}}:S.rewardButtonDisabled,h=B===x.id;return jsxRuntime.jsxs("div",{style:v,children:[x.imageUrl?jsxRuntime.jsx("img",{src:x.imageUrl,alt:x.name,style:S.rewardImage}):jsxRuntime.jsx("div",{style:{...S.rewardImage,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"32px"},children:"\u{1F381}"}),jsxRuntime.jsxs("div",{style:S.rewardContent,children:[jsxRuntime.jsx("span",{style:S.rewardName,children:x.name}),x.description&&jsxRuntime.jsx("span",{style:S.rewardDescription,children:x.description}),jsxRuntime.jsxs("span",{style:S.rewardCost,children:[x.pointsCost.toLocaleString()," points"]}),x.requiredBadgeName&&!x.hasBadge&&jsxRuntime.jsxs("span",{style:{fontSize:"12px",color:"#dc3545",marginBottom:"8px"},children:["Requires: ",x.requiredBadgeName]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{P(x);},disabled:!x.isAvailable||!x.canAfford||h,style:A,children:h?"Redeeming...":x.canAfford?"Redeem":`Need ${(x.pointsCost-u).toLocaleString()} more`})]})]},x.id)})})]})}var qe=D(Qe);Object.defineProperty(exports,"defaultTheme",{enumerable:true,get:function(){return core.defaultTheme}});exports.AffiliateStats=Ie;exports.BadgeGrid=De;exports.GamifyPageView=he;exports.GamifyProvider=me;exports.GamifyTrackClick=we;exports.Leaderboard=Te;exports.LevelProgress=$e;exports.QuestProgress=Fe;exports.ReferralLink=Le;exports.RewardStore=qe;exports.StreakFlame=Ge;exports.useAffiliateStats=K;exports.useBadges=ne;exports.useGamify=be;exports.useGamifyTheme=V;exports.useIdentify=Ce;exports.useLeaderboard=re;exports.useLoyalty=ee;exports.useQuests=te;exports.useReferral=ve;exports.useRewards=ae;exports.useSession=Re;exports.useStreaks=oe;exports.useTrack=H;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var ke=require('react'),core=require('@gamifyio/core'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ke__default=/*#__PURE__*/_interopDefault(ke);var ge=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(o,s)=>(typeof require<"u"?require:o)[s]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var pe=ke.createContext(null),ee=ke.createContext(core.defaultTheme);function me(){return typeof window>"u"}function be({config:e,theme:o,children:s}){let i=ke.useRef(null),d=ke.useMemo(()=>o?{...core.defaultTheme,...o}:core.defaultTheme,[o]),p=ke.useMemo(()=>{if(me())return null;if(i.current)return i.current;let a=new core.Gamify(e);return i.current=a,a},[e.apiKey,e.endpoint]);ke.useEffect(()=>()=>{i.current&&(i.current.shutdown(),i.current=null);},[]);let t=ke.useMemo(()=>p?{client:p,track:(a,n)=>p.track(a,n),identify:(a,n)=>p.identify(a,n),reset:()=>p.reset(),getUserId:()=>p.getUserId(),getAnonymousId:()=>p.getAnonymousId()}:null,[p]);return t?jsxRuntime.jsx(ee.Provider,{value:d,children:jsxRuntime.jsx(pe.Provider,{value:t,children:s})}):jsxRuntime.jsx(ee.Provider,{value:d,children:s})}function N(){return ke.useContext(pe)}function V(){return ke.useContext(ee)}function Ce(){let e=N();if(!e)throw new Error("useGamify must be used within a GamifyProvider. Make sure your component is wrapped with <GamifyProvider>.");return e}function K(){let e=N();return ke.useCallback((o,s)=>{e&&e.track(o,s);},[e])}function Re(){let e=N();return ke.useCallback((o,s)=>{e&&e.identify(o,s);},[e])}function ve(){let e=N(),[o,s]=ke.useState({session:e?.client?.session?.getCachedSession()??null,loading:false,error:null}),i=ke.useCallback(async(n,c,f)=>{if(!e?.client){s(g=>({...g,error:"SDK not initialized"}));return}s(g=>({...g,loading:true,error:null}));try{let g=await e.client.updateCart(n,c,f);s({session:g,loading:!1,error:null});}catch(g){let m=g instanceof Error?g.message:"Unknown error";s(b=>({...b,loading:false,error:m}));}},[e]),d=ke.useCallback(async n=>{if(!e?.client?.session){s(c=>({...c,error:"SDK not initialized"}));return}s(c=>({...c,loading:true,error:null}));try{let c=await e.client.session.applyCoupon(n);s({session:c,loading:!1,error:null});}catch(c){let f=c instanceof Error?c.message:"Unknown error";s(g=>({...g,loading:false,error:f}));}},[e]),p=ke.useCallback(async()=>{if(!e?.client?.session){s(n=>({...n,error:"SDK not initialized"}));return}s(n=>({...n,loading:true,error:null}));try{let n=await e.client.session.complete();s({session:n,loading:!1,error:null});}catch(n){let c=n instanceof Error?n.message:"Unknown error";s(f=>({...f,loading:false,error:c}));}},[e]),t=ke.useCallback(()=>{e?.client?.session&&(e.client.session.clearSession(),s({session:null,loading:false,error:null}));},[e]),a=ke.useCallback(async()=>{if(e?.client?.session){s(n=>({...n,loading:true,error:null}));try{let n=await e.client.session.getSession();s({session:n,loading:!1,error:null});}catch(n){let c=n instanceof Error?n.message:"Unknown error";s(f=>({...f,loading:false,error:c}));}}},[e]);return {...o,updateCart:i,applyCoupon:d,complete:p,clearSession:t,refresh:a}}function re(e){let o=N(),[s,i]=ke.useState({profile:o?.client?.loyalty?.getCachedProfile()??null,history:null,loading:false,error:null}),d=ke.useCallback(async()=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getLoyaltyProfile();i(a=>({...a,profile:t,loading:!1,error:null}));}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]),p=ke.useCallback(async(t,a)=>{if(!o?.client){i(n=>({...n,error:"SDK not initialized"}));return}i(n=>({...n,loading:true,error:null}));try{let n=await o.client.getLoyaltyHistory(t,a);i(c=>({...c,history:n,loading:!1,error:null}));}catch(n){let c=n instanceof Error?n.message:"Unknown error";i(f=>({...f,loading:false,error:c}));}},[o]);return ke.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refreshProfile:d,refreshHistory:p}}function Pe(){let e=N(),[o,s]=ke.useState({referrerCode:e?.client?.referral?.getReferrer()??null,hasReferrer:e?.client?.referral?.hasReferrer()??false}),i=ke.useCallback(t=>{e?.client?.referral&&(e.client.referral.setReferrer(t),s({referrerCode:t,hasReferrer:true}));},[e]),d=ke.useCallback(()=>{e?.client?.referral&&(e.client.referral.clearReferrer(),s({referrerCode:null,hasReferrer:false}));},[e]),p=ke.useCallback(()=>{if(e?.client?.referral){let t=e.client.referral.detectReferrerFromUrl();return t&&s({referrerCode:t,hasReferrer:true}),t}return null},[e]);return ke.useEffect(()=>{if(e?.client?.referral){let t=e.client.referral.getReferrer();s({referrerCode:t,hasReferrer:t!==null});}},[e]),{...o,setReferrer:i,clearReferrer:d,detectFromUrl:p}}function Y(e){let o=N(),[s,i]=ke.useState({stats:o?.client?.affiliate?.getCachedStats()??null,loading:false,error:null}),d=ke.useCallback(async(p=false)=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getAffiliateStats(p);i({stats:t,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]);return ke.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refreshStats:d}}function te(e=10){let o=N(),[s,i]=ke.useState({leaderboard:null,loading:false,error:null}),d=ke.useCallback(async p=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getLeaderboard(p??e);i({leaderboard:t,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o,e]);return {...s,refresh:d}}function oe(e){let o=N(),[s,i]=ke.useState({quests:[],loading:false,error:null}),d=ke.useCallback(async()=>{if(!o?.client){i(p=>({...p,error:"SDK not initialized"}));return}i(p=>({...p,loading:true,error:null}));try{let p=await o.client.getQuests();i({quests:p.quests,loading:!1,error:null});}catch(p){let t=p instanceof Error?p.message:"Unknown error";i(a=>({...a,loading:false,error:t}));}},[o]);return ke.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d}}function ne(e){let o=N(),[s,i]=ke.useState({streaks:[],stats:null,loading:false,error:null}),d=ke.useCallback(async()=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getStreaks();i({streaks:t.streaks,stats:t.stats,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]),p=ke.useCallback(async t=>{if(!o?.client)return i(a=>({...a,error:"SDK not initialized"})),null;try{let a=await o.client.useStreakFreeze(t);return await d(),a}catch(a){let n=a instanceof Error?a.message:"Unknown error";return i(c=>({...c,error:n})),null}},[o,d]);return ke.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d,freeze:p}}function ae(e){let o=N(),[s,i]=ke.useState({badges:[],stats:null,earned:[],locked:[],loading:false,error:null}),d=ke.useCallback(async p=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getBadges(p??e?.category),a=t.badges.filter(c=>c.isUnlocked),n=t.badges.filter(c=>!c.isUnlocked);i({badges:t.badges,stats:t.stats,earned:a,locked:n,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o,e?.category]);return ke.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d}}function se(e){let o=N(),[s,i]=ke.useState({items:[],userPoints:0,available:[],unavailable:[],loading:false,error:null}),d=ke.useCallback(async()=>{if(!o?.client){i(t=>({...t,error:"SDK not initialized"}));return}i(t=>({...t,loading:true,error:null}));try{let t=await o.client.getRewardsStore(),a=t.items.filter(c=>c.isAvailable),n=t.items.filter(c=>!c.isAvailable);i({items:t.items,userPoints:t.userPoints,available:a,unavailable:n,loading:!1,error:null});}catch(t){let a=t instanceof Error?t.message:"Unknown error";i(n=>({...n,loading:false,error:a}));}},[o]),p=ke.useCallback(async t=>{if(!o?.client)return i(a=>({...a,error:"SDK not initialized"})),null;i(a=>({...a,loading:true,error:null}));try{let a=await o.client.redeemReward(t);return await d(),a}catch(a){let n=a instanceof Error?a.message:"Unknown error";return i(c=>({...c,loading:false,error:n})),null}},[o,d]);return ke.useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d,redeem:p}}var q="div",_=({children:e})=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:e});try{let e=ge("framer-motion");e?.motion?.div&&(q=e.motion.div),e?.AnimatePresence&&(_=e.AnimatePresence);}catch{}var ie=class extends ke__default.default.Component{constructor(o){super(o),this.state={hasError:false,error:null};}static getDerivedStateFromError(o){return {hasError:true,error:o}}render(){return this.state.hasError?this.props.fallback?this.props.fallback:jsxRuntime.jsx("div",{style:{padding:"16px",color:"#6c757d",fontSize:"14px",textAlign:"center"},children:"Unable to load this section. Please try refreshing the page."}):this.props.children}};function D(e,o){let s=i=>jsxRuntime.jsx(ie,{fallback:o,children:jsxRuntime.jsx(e,{...i})});return s.displayName=`WithErrorBoundary(${e.displayName||e.name||"Component"})`,s}function we({pageName:e,properties:o,pathname:s}){let i=K(),d=ke.useRef(null);return ke.useEffect(()=>{if(typeof window>"u")return;if(s!==void 0){if(d.current===s)return;d.current=s;}let p=e??(typeof document<"u"?document.title:null)??(typeof window<"u"?window.location.pathname:"unknown");i("page_view",{page:p,url:typeof window<"u"?window.location.href:void 0,referrer:typeof document<"u"?document.referrer:void 0,...o});},[i,e,s,o]),null}function Be({eventType:e,properties:o,children:s}){let i=K();return ke.cloneElement(s,{onClick:p=>{i(e,o),s.props.onClick&&s.props.onClick(p);}})}function X(e){return {statsContainer:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:"16px",padding:"16px"},statsCard:{backgroundColor:e.cardBackground??e.background,borderRadius:"8px",padding:"16px",textAlign:"center",border:`1px solid ${e.cardBorder??e.border}`},statsValue:{fontSize:"24px",fontWeight:"bold",color:e.foreground,marginBottom:"4px"},statsLabel:{fontSize:"14px",color:e.foregroundSecondary},leaderboardContainer:{padding:"16px"},leaderboardList:{listStyle:"none",padding:0,margin:0},leaderboardRow:{display:"flex",alignItems:"center",padding:"12px",borderBottom:`1px solid ${e.border}`},leaderboardRowHighlighted:{display:"flex",alignItems:"center",padding:"12px",borderBottom:`1px solid ${e.border}`,backgroundColor:`${e.primary}20`},leaderboardRank:{fontWeight:"bold",width:"40px",color:e.foreground},leaderboardName:{flex:1,marginLeft:"12px",color:e.foreground},leaderboardStats:{color:e.foregroundSecondary,fontSize:"14px"},leaderboardEmpty:{textAlign:"center",padding:"32px",color:e.foregroundSecondary},referralContainer:{display:"flex",gap:"8px",padding:"8px"},referralInput:{flex:1,padding:"10px 12px",border:`1px solid ${e.inputBorder??e.border}`,borderRadius:"6px",fontSize:"14px",backgroundColor:e.inputBackground??e.backgroundSecondary,color:e.foreground},referralButton:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:e.buttonBackground??e.primary,color:e.buttonForeground??e.primaryForeground,cursor:"pointer",fontSize:"14px",fontWeight:"500"},tierBadge:{display:"flex",alignItems:"center",gap:"8px",padding:"12px",borderRadius:"8px",marginBottom:"12px"},tierBadgeIcon:{width:"20px",height:"20px"},tierBadgeText:{flex:1},tierBadgeName:{fontWeight:"500",fontSize:"14px"},tierBadgeRate:{fontSize:"12px",opacity:.8},referralCodeRow:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px",backgroundColor:e.backgroundSecondary,borderRadius:"8px",marginBottom:"12px"},referralCodeLabel:{fontSize:"12px",color:e.foregroundSecondary,marginBottom:"2px"},referralCodeValue:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.foreground},referralCodeCopyButton:{padding:"6px 10px",border:"none",borderRadius:"4px",backgroundColor:"transparent",color:e.foregroundSecondary,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},statsGrid2Col:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"12px",marginBottom:"12px"},earningsBreakdown:{borderTop:`1px solid ${e.border}`,paddingTop:"12px",marginTop:"12px"},earningsTitle:{fontSize:"14px",fontWeight:"500",color:e.foreground,marginBottom:"8px"},earningsRow:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 0"},earningsLabel:{fontSize:"14px",color:e.foregroundSecondary},earningsValue:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.foreground},earningsValueGreen:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.success},earningsValueYellow:{fontFamily:"monospace",fontWeight:"500",fontSize:"14px",color:e.warning},medalIcon:{width:"24px",height:"24px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"18px"},referrerSection:{borderTop:`1px solid ${e.border}`,paddingTop:"12px",marginTop:"12px"},referrerTitle:{fontSize:"14px",fontWeight:"500",color:e.foreground,marginBottom:"8px"},referrerBadge:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px",backgroundColor:`${e.success}15`,border:`1px solid ${e.success}30`,borderRadius:"8px"},referrerBadgeInfo:{display:"flex",alignItems:"center",gap:"8px",fontSize:"14px",color:e.foreground},referrerBadgeIcon:{color:e.success},referrerClearButton:{padding:"4px 8px",border:"none",borderRadius:"4px",backgroundColor:"transparent",color:e.foregroundSecondary,cursor:"pointer"},referrerInputRow:{display:"flex",gap:"8px",marginBottom:"8px"},referrerDetectButton:{width:"100%",padding:"10px 16px",border:`1px solid ${e.border}`,borderRadius:"6px",backgroundColor:e.backgroundSecondary,color:e.foreground,cursor:"pointer",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},filterTabs:{display:"flex",gap:"8px",marginBottom:"16px"},filterTab:{padding:"6px 12px",fontSize:"12px",borderRadius:"9999px",border:"none",cursor:"pointer",backgroundColor:e.backgroundSecondary,color:e.foregroundSecondary,transition:"all 0.2s"},filterTabActive:{padding:"6px 12px",fontSize:"12px",borderRadius:"9999px",border:"none",cursor:"pointer",backgroundColor:e.primary,color:e.primaryForeground},progressSummary:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px",backgroundColor:e.backgroundSecondary,borderRadius:"8px",marginBottom:"16px"},progressSummaryLeft:{display:"flex",alignItems:"center",gap:"12px"},progressSummaryIcon:{width:"40px",height:"40px",borderRadius:"50%",backgroundColor:`${e.primary}20`,display:"flex",alignItems:"center",justifyContent:"center",color:e.primary,fontSize:"18px"},progressSummaryText:{fontWeight:"500",fontSize:"16px",color:e.foreground},progressSummarySubtext:{fontSize:"12px",color:e.foregroundSecondary},progressSummaryBar:{width:"80px",height:"8px",backgroundColor:e.border,borderRadius:"4px",overflow:"hidden"},progressSummaryBarFill:{height:"100%",backgroundColor:e.primary,borderRadius:"4px"},badgeProgressBar:{width:"100%",height:"4px",backgroundColor:e.border,borderRadius:"2px",overflow:"hidden",marginTop:"8px"},badgeProgressFill:{height:"100%",backgroundColor:e.foregroundSecondary,borderRadius:"2px"},badgeProgressText:{fontSize:"10px",color:e.foregroundSecondary,marginTop:"4px"},badgeCheckmark:{position:"absolute",top:"8px",right:"8px",color:e.success}}}function Ie({className:e,style:o,theme:s,autoRefresh:i=true,showTierBadge:d=true,showReferralCode:p=true,showEarningsBreakdown:t=true,renderLoading:a,renderError:n}){let c=V(),f=X(c),{stats:g,loading:m,error:b,refreshStats:C}=Y({autoRefresh:i}),[B,I]=ke.useState(false);if(ke.useEffect(()=>{i&&C();},[i,C]),m)return a?a():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:c.foregroundSecondary},children:"Loading..."});if(b)return n?n(b):jsxRuntime.jsx("div",{style:{color:c.error,padding:"16px"},children:b});if(!g||!g.earnings)return null;let k={...f.statsCard,...s?.cardBackground&&{backgroundColor:s.cardBackground},...s?.cardBorder&&{border:`1px solid ${s.cardBorder}`}},P={...f.statsValue,...s?.valueColor&&{color:s.valueColor}},x=y=>new Intl.NumberFormat("en-US",{style:"currency",currency:g.earnings?.currency??"USD"}).format(y/100),v=async()=>{if(g.referralCode)try{await navigator.clipboard.writeText(g.referralCode),I(!0),setTimeout(()=>I(!1),2e3);}catch(y){console.error("Failed to copy:",y);}},T=(y=>{if(!y)return "#6c757d";let h=y.toLowerCase();return h.includes("elite")||h.includes("diamond")||h.includes("platinum")||h.includes("gold")||h.includes("vip")?"#FFD700":h.includes("silver")||h.includes("pro")?"#C0C0C0":h.includes("bronze")||h.includes("starter")?"#CD7F32":"#0d6efd"})(g.tier?.name),u={padding:"16px",...s?.cardBackground&&{backgroundColor:s.cardBackground},...s?.cardBorder&&{border:`1px solid ${s.cardBorder}`},...o};return jsxRuntime.jsxs("div",{className:e,style:u,children:[d&&jsxRuntime.jsxs("div",{style:{...f.tierBadge,backgroundColor:g.tier?`${T}20`:c.backgroundSecondary},children:[jsxRuntime.jsx("span",{style:{...f.tierBadgeIcon,color:T},children:"\u{1F451}"}),jsxRuntime.jsxs("div",{style:f.tierBadgeText,children:[jsxRuntime.jsx("div",{style:{...f.tierBadgeName,color:g.tier?T:c.foregroundSecondary},children:g.tier?`${g.tier.name} Affiliate`:"No Tier"}),jsxRuntime.jsx("div",{style:{...f.tierBadgeRate,color:g.tier?T:c.foregroundSecondary},children:g.tier?`${g.tier.value}% commission rate`:"Refer users to unlock affiliate status"})]})]}),p&&g.referralCode&&jsxRuntime.jsxs("div",{style:f.referralCodeRow,children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{style:f.referralCodeLabel,children:"Your referral code"}),jsxRuntime.jsx("div",{style:f.referralCodeValue,children:g.referralCode})]}),jsxRuntime.jsx("button",{type:"button",onClick:v,style:f.referralCodeCopyButton,"aria-label":"Copy referral code",children:B?"\u2713":"\u{1F4CB}"})]}),jsxRuntime.jsxs("div",{style:f.statsGrid2Col,children:[jsxRuntime.jsxs("div",{style:k,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:c.foregroundSecondary,marginBottom:"4px"},children:[jsxRuntime.jsx("span",{children:"\u{1F465}"}),jsxRuntime.jsx("span",{style:{fontSize:"12px"},children:"Referrals"})]}),jsxRuntime.jsx("div",{style:{...P,fontFamily:"monospace"},children:g.referralCount})]}),jsxRuntime.jsxs("div",{style:k,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:c.foregroundSecondary,marginBottom:"4px"},children:[jsxRuntime.jsx("span",{children:"\u{1F4B0}"}),jsxRuntime.jsx("span",{style:{fontSize:"12px"},children:"Commissions"})]}),jsxRuntime.jsx("div",{style:{...P,fontFamily:"monospace"},children:g.earnings.transactionCount})]})]}),t&&jsxRuntime.jsxs("div",{style:f.earningsBreakdown,children:[jsxRuntime.jsx("div",{style:f.earningsTitle,children:"Earnings"}),jsxRuntime.jsxs("div",{style:f.earningsRow,children:[jsxRuntime.jsx("span",{style:f.earningsLabel,children:"Total Earned"}),jsxRuntime.jsx("span",{style:f.earningsValueGreen,children:x(g.earnings.totalEarned)})]}),jsxRuntime.jsxs("div",{style:f.earningsRow,children:[jsxRuntime.jsx("span",{style:f.earningsLabel,children:"Pending"}),jsxRuntime.jsx("span",{style:f.earningsValueYellow,children:x(g.earnings.totalPending)})]}),jsxRuntime.jsxs("div",{style:f.earningsRow,children:[jsxRuntime.jsx("span",{style:f.earningsLabel,children:"Paid Out"}),jsxRuntime.jsx("span",{style:{...f.earningsValue,color:c.foregroundSecondary},children:x(g.earnings.totalPaid)})]})]})]})}var ze=D(Ie);function Te({limit:e=10,className:o,style:s,currentUserId:i,emptyMessage:d="No leaderboard data available yet.",showMedals:p=true,showTierInfo:t=true,showEarnings:a=true,theme:n,renderRow:c,renderLoading:f,renderError:g}){let m=V(),b=X(m),{leaderboard:C,loading:B,error:I,refresh:k}=te(e);if(ke.useEffect(()=>{k();},[k]),B)return f?f():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:m.foregroundSecondary},children:"Loading..."});if(I)return g?g(I):jsxRuntime.jsx("div",{style:{color:m.error,padding:"16px"},children:I});if(!C||C.entries.length===0)return jsxRuntime.jsx("div",{className:o,style:{...b.leaderboardEmpty,...s},children:d});let P=y=>{if(!p)return null;switch(y){case 1:return m.medalGold;case 2:return m.medalSilver;case 3:return m.medalBronze;default:return null}},x=y=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0}).format(y/100),v=y=>({...y?b.leaderboardRowHighlighted:b.leaderboardRow,...n?.rowBackground&&!y&&{backgroundColor:n.rowBackground},...n?.highlightBackground&&y&&{backgroundColor:n.highlightBackground},...y&&{backgroundColor:`${m.primary}15`,border:`1px solid ${m.primary}40`,borderRadius:"8px"}}),A=n?.textColor?{color:n.textColor}:{},T=n?.secondaryColor?{...b.leaderboardStats,color:n.secondaryColor}:b.leaderboardStats,u=i?C.entries.find(y=>y.userId===i)?.rank:null;return jsxRuntime.jsxs("div",{className:o,style:{...b.leaderboardContainer,...s},children:[u&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"8px"},children:jsxRuntime.jsxs("span",{style:{fontSize:"12px",backgroundColor:`${m.primary}30`,color:m.primary,padding:"4px 8px",borderRadius:"9999px"},children:["Your rank: #",u]})}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:jsxRuntime.jsx(_,{mode:"popLayout",children:C.entries.map((y,h)=>{let E=i===y.userId,L=P(y.rank);if(c)return jsxRuntime.jsx("div",{children:c(y,E)},y.userId);let w=jsxRuntime.jsxs("div",{style:v(E),children:[jsxRuntime.jsx("div",{style:b.medalIcon,children:L?jsxRuntime.jsx("span",{style:{color:L},children:"\u{1F3C5}"}):jsxRuntime.jsxs("span",{style:{fontSize:"14px",fontFamily:"monospace",color:m.foregroundSecondary},children:["#",y.rank]})}),jsxRuntime.jsxs("div",{style:{flex:1,marginLeft:"12px"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{...b.leaderboardName,...A,marginLeft:0},children:y.displayName??`User ${y.userId.slice(0,8)}`}),E&&jsxRuntime.jsx("span",{style:{fontSize:"12px",color:m.primary},children:"(You)"})]}),t&&y.tier&&jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:m.foregroundSecondary},children:[y.tier.name," (",y.tier.value,"%)"]})]}),jsxRuntime.jsxs("div",{style:{textAlign:"right"},children:[jsxRuntime.jsxs("div",{style:{fontFamily:"monospace",fontSize:"14px",fontWeight:"500",color:m.foreground},children:[y.referralCount," referrals"]}),a&&y.totalEarnings!==void 0&&jsxRuntime.jsx("div",{style:{...T,fontFamily:"monospace"},children:x(y.totalEarnings)})]})]});return q!=="div"?jsxRuntime.jsx(q,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},transition:{delay:h*.05},children:w},y.userId):jsxRuntime.jsx("div",{children:w},y.userId)})})}),jsxRuntime.jsx("p",{style:{fontSize:"12px",color:"#6c757d",textAlign:"center",marginTop:"12px"},children:"Rankings based on total referrals"})]})}var Ae=D(Te);function Le({baseUrl:e,className:o,style:s,copyButtonText:i="Copy",copiedText:d="Copied!",shareButtonText:p="Share",shareTitle:t="Check this out!",shareText:a="Join using my referral link",showShareButton:n=true,showReferrerAttribution:c=true,referrerCode:f,onSetReferrer:g,onDetectFromUrl:m,onClearReferrer:b,theme:C,onCopy:B,onShare:I}){let k=V(),P=X(k),{stats:x,loading:v}=Y({autoRefresh:true}),[A,T]=ke.useState(false),[u,y]=ke.useState(""),h=x?.referralCode,E=typeof window<"u"?window.location.origin:"",L=`${e??E}?ref=${h}`,w=async()=>{try{await navigator.clipboard.writeText(L),T(!0),B?.(L),setTimeout(()=>T(!1),2e3);}catch(U){console.error("Failed to copy:",U);}},R=async()=>{if(typeof navigator<"u"&&navigator.share)try{await navigator.share({title:t,text:a,url:L}),I?.(L);}catch(U){U.name!=="AbortError"&&console.error("Failed to share:",U);}},G=()=>{u.trim()&&g&&(g(u.trim()),y(""));},j=typeof navigator<"u"&&"share"in navigator,Q={...P.referralInput,...C?.inputBackground&&{backgroundColor:C.inputBackground},...C?.inputBorder&&{border:`1px solid ${C.inputBorder}`},...C?.inputColor&&{color:C.inputColor}},H={...P.referralButton,...C?.buttonBackground&&{backgroundColor:C.buttonBackground},...C?.buttonColor&&{color:C.buttonColor}},le={padding:"16px",...s};return v||!h?jsxRuntime.jsx("div",{className:o,style:le,children:jsxRuntime.jsxs("div",{style:{marginBottom:"8px"},children:[jsxRuntime.jsx("p",{style:{fontSize:"14px",color:k.foregroundSecondary,marginBottom:"8px"},children:"Your unique referral link:"}),jsxRuntime.jsxs("div",{style:P.referralContainer,children:[jsxRuntime.jsx("input",{type:"text",readOnly:true,value:v?"Loading...":"No referral code assigned",disabled:true,style:{...Q,fontFamily:"monospace",fontSize:"12px",opacity:.6}}),jsxRuntime.jsx("button",{type:"button",disabled:true,style:{...H,opacity:.5,cursor:"not-allowed"},children:"\u{1F4CB}"})]}),!v&&!h&&jsxRuntime.jsx("p",{style:{fontSize:"12px",color:k.foregroundSecondary,marginTop:"8px"},children:"Complete a referral action to get your unique code."})]})}):jsxRuntime.jsxs("div",{className:o,style:le,children:[jsxRuntime.jsxs("div",{style:{marginBottom:"8px"},children:[jsxRuntime.jsx("p",{style:{fontSize:"14px",color:k.foregroundSecondary,marginBottom:"8px"},children:"Your unique referral link:"}),jsxRuntime.jsxs("div",{style:P.referralContainer,children:[jsxRuntime.jsx("input",{type:"text",readOnly:true,value:L,style:{...Q,fontFamily:"monospace",fontSize:"12px"},onClick:U=>U.target.select()}),jsxRuntime.jsx("button",{type:"button",onClick:w,style:H,children:A?"\u2713":"\u{1F4CB}"}),n&&j&&jsxRuntime.jsx("button",{type:"button",onClick:R,style:H,children:p})]}),jsxRuntime.jsxs("p",{style:{fontSize:"12px",color:k.foregroundSecondary,marginTop:"4px"},children:["Code: ",jsxRuntime.jsx("span",{style:{fontFamily:"monospace",fontWeight:"500",color:k.foreground},children:h})]})]}),c&&jsxRuntime.jsxs("div",{style:P.referrerSection,children:[jsxRuntime.jsx("p",{style:P.referrerTitle,children:"Referrer Attribution"}),f?jsxRuntime.jsxs("div",{style:P.referrerBadge,children:[jsxRuntime.jsxs("div",{style:P.referrerBadgeInfo,children:[jsxRuntime.jsx("span",{style:P.referrerBadgeIcon,children:"\u{1F464}"}),jsxRuntime.jsxs("span",{children:["Referred by: ",jsxRuntime.jsx("span",{style:{fontFamily:"monospace",fontWeight:"500"},children:f})]})]}),b&&jsxRuntime.jsx("button",{type:"button",onClick:b,style:P.referrerClearButton,"aria-label":"Clear referrer",children:"\u2715"})]}):jsxRuntime.jsxs("div",{children:[g&&jsxRuntime.jsxs("div",{style:P.referrerInputRow,children:[jsxRuntime.jsx("input",{type:"text",value:u,onChange:U=>y(U.target.value),placeholder:"Enter referrer code...",style:{...Q,fontFamily:"monospace",fontSize:"12px"}}),jsxRuntime.jsx("button",{type:"button",onClick:G,disabled:!u.trim(),style:{...H,opacity:u.trim()?1:.5,cursor:u.trim()?"pointer":"not-allowed"},children:"Set"})]}),m&&jsxRuntime.jsxs("button",{type:"button",onClick:m,style:P.referrerDetectButton,children:[jsxRuntime.jsx("span",{children:"\u{1F517}"}),"Detect from URL"]})]})]})]})}var Ne=D(Le),S={questProgressBar:{width:"100%",height:"8px",backgroundColor:"#e9ecef",borderRadius:"4px",overflow:"hidden",marginBottom:"12px"},questProgressFill:{height:"100%",backgroundColor:"#0d6efd",borderRadius:"4px",transition:"width 0.3s ease"},streakContainer:{display:"flex",alignItems:"center",padding:"16px",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef"},streakFlame:{fontSize:"32px",marginRight:"12px"},streakCount:{fontSize:"28px",fontWeight:"bold",color:"#212529",marginRight:"8px"},streakLabel:{fontSize:"14px",color:"#6c757d"},streakInfo:{flex:1},streakName:{fontSize:"16px",fontWeight:"600",color:"#212529"},streakStatus:{fontSize:"12px",padding:"2px 8px",borderRadius:"10px",marginLeft:"8px"},freezeButton:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#17a2b8",color:"white",cursor:"pointer",fontSize:"14px",display:"flex",alignItems:"center",gap:"6px"},freezeButtonDisabled:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#6c757d",color:"white",cursor:"not-allowed",fontSize:"14px",opacity:.6},levelContainer:{padding:"16px",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef"},levelHeader:{display:"flex",alignItems:"center",marginBottom:"12px"},levelIcon:{width:"48px",height:"48px",borderRadius:"50%",marginRight:"12px",backgroundColor:"#e9ecef",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"24px"},levelInfo:{flex:1},levelTierName:{fontSize:"18px",fontWeight:"600",color:"#212529"},levelPoints:{fontSize:"14px",color:"#6c757d"},levelProgressContainer:{marginTop:"12px"},levelProgressHeader:{display:"flex",justifyContent:"space-between",marginBottom:"6px",fontSize:"13px"},levelProgressBar:{width:"100%",height:"10px",backgroundColor:"#e9ecef",borderRadius:"5px",overflow:"hidden"},levelProgressFill:{height:"100%",background:"linear-gradient(90deg, #667eea 0%, #764ba2 100%)",borderRadius:"5px",transition:"width 0.3s ease"},levelBenefits:{marginTop:"16px",padding:"12px",backgroundColor:"#f8f9fa",borderRadius:"6px"},levelBenefitsTitle:{fontSize:"14px",fontWeight:"600",color:"#212529",marginBottom:"8px"},levelBenefitsList:{listStyle:"none",padding:0,margin:0,fontSize:"13px",color:"#495057"},levelBenefitItem:{padding:"4px 0",display:"flex",alignItems:"center"},rewardStoreGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(200px, 1fr))",gap:"16px",padding:"16px"},rewardCard:{display:"flex",flexDirection:"column",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef",overflow:"hidden"},rewardCardUnavailable:{display:"flex",flexDirection:"column",backgroundColor:"#f8f9fa",borderRadius:"8px",border:"1px solid #e9ecef",overflow:"hidden",opacity:.7},rewardImage:{width:"100%",height:"120px",objectFit:"cover",backgroundColor:"#e9ecef"},rewardContent:{padding:"12px",flex:1,display:"flex",flexDirection:"column"},rewardName:{fontSize:"16px",fontWeight:"600",color:"#212529",marginBottom:"4px"},rewardDescription:{fontSize:"13px",color:"#6c757d",marginBottom:"8px",flex:1},rewardCost:{fontSize:"14px",fontWeight:"600",color:"#0d6efd",marginBottom:"8px"},rewardButton:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:"#0d6efd",color:"white",cursor:"pointer",fontSize:"14px",fontWeight:"500",width:"100%"},rewardButtonDisabled:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:"#6c757d",color:"white",cursor:"not-allowed",fontSize:"14px",fontWeight:"500",width:"100%"},rewardPointsHeader:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",backgroundColor:"#f8f9fa",borderRadius:"8px",marginBottom:"16px"},rewardPointsLabel:{fontSize:"14px",color:"#6c757d"},rewardPointsValue:{fontSize:"24px",fontWeight:"bold",color:"#212529"},questAccordion:{borderRadius:"8px",overflow:"hidden",marginBottom:"8px"},questAccordionHeader:{width:"100%",padding:"12px",display:"flex",alignItems:"center",gap:"12px",border:"none",backgroundColor:"transparent",cursor:"pointer",textAlign:"left"},questAccordionIcon:{width:"40px",height:"40px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"20px",flexShrink:0},questAccordionInfo:{flex:1,minWidth:0},questAccordionTitle:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"4px"},questAccordionName:{fontWeight:"500",fontSize:"14px",color:"#212529"},questAccordionStatusBadge:{fontSize:"11px",padding:"2px 8px",borderRadius:"9999px",fontWeight:"500"},questAccordionMeta:{display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",color:"#6c757d"},questAccordionChevron:{color:"#6c757d",transition:"transform 0.2s",flexShrink:0},questAccordionContent:{padding:"0 12px 12px",overflow:"hidden"}};function Ee(e){switch(e){case "completed":return {bg:"#d4edda",color:"#155724"};case "in_progress":return {bg:"#cce5ff",color:"#004085"};case "active":return {bg:"#cce5ff",color:"#004085"};case "frozen":return {bg:"#cce5ff",color:"#17a2b8"};case "at_risk":return {bg:"#fff3cd",color:"#856404"};case "broken":return {bg:"#f8d7da",color:"#721c24"};default:return {bg:"#e9ecef",color:"#6c757d"}}}function Fe({questId:e,hideCompleted:o=false,className:s,style:i,expandable:d=true,defaultExpandedId:p,showXpReward:t=true,onComplete:a,theme:n,renderLoading:c,renderError:f,renderQuest:g}){let{quests:m,loading:b,error:C,refresh:B}=oe({autoRefresh:true}),I=ke.useRef(new Map),[k,P]=ke.useState(null);if(ke.useEffect(()=>{B();},[B]),ke.useEffect(()=>{a&&m.forEach(y=>{let h=I.current.get(y.id);h&&h.status!=="completed"&&y.status==="completed"&&a(y);});let u=new Map;m.forEach(y=>u.set(y.id,y)),I.current=u;},[m,a]),ke.useEffect(()=>{if(m.length>0&&k===null)if(p)P(p);else {let u=m.find(y=>y.status==="in_progress");P(u?.id??null);}},[m,p,k]),b)return c?c():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(C)return f?f(C):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:C});let x=m;if(e&&(x=m.filter(u=>u.id===e)),o&&(x=x.filter(u=>u.status!=="completed")),x.length===0)return jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"24px",color:"#6c757d"},children:[jsxRuntime.jsx("span",{style:{fontSize:"40px",display:"block",marginBottom:"8px",opacity:.5},children:"\u{1F3AF}"}),jsxRuntime.jsx("p",{children:"No quests available"})]});let v=u=>{switch(u){case "completed":return {backgroundColor:"rgba(40, 167, 69, 0.2)",color:"#28a745"};case "in_progress":return {backgroundColor:"rgba(13, 110, 253, 0.2)",color:"#0d6efd"};default:return {backgroundColor:"#f8f9fa",color:"#6c757d"}}},A=u=>{switch(u){case "completed":return {backgroundColor:"rgba(40, 167, 69, 0.05)",borderColor:"rgba(40, 167, 69, 0.2)"};case "in_progress":return {backgroundColor:"rgba(13, 110, 253, 0.05)",borderColor:"rgba(13, 110, 253, 0.2)"};default:return {backgroundColor:"#f8f9fa",borderColor:"#e9ecef"}}},T=u=>{d&&P(k===u?null:u);};return jsxRuntime.jsx("div",{className:s,style:{...i,display:"flex",flexDirection:"column",gap:"12px"},children:jsxRuntime.jsx(_,{mode:"popLayout",children:x.map(u=>{if(g)return jsxRuntime.jsx("div",{children:g(u)},u.id);let y=!d||k===u.id,h=v(u.status),E=A(u.status),L=jsxRuntime.jsxs("div",{style:{...S.questAccordion,border:"1px solid",...E,...n?.cardBackground&&{backgroundColor:n.cardBackground},...n?.cardBorder&&{borderColor:n.cardBorder}},children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>T(u.id),style:{...S.questAccordionHeader,cursor:d?"pointer":"default"},children:[jsxRuntime.jsx("div",{style:{...S.questAccordionIcon,backgroundColor:u.status==="completed"?"rgba(40, 167, 69, 0.2)":"rgba(13, 110, 253, 0.2)"},children:u.status==="completed"?jsxRuntime.jsx("span",{style:{color:"#28a745"},children:"\u2713"}):jsxRuntime.jsx("span",{style:{color:"#0d6efd"},children:"\u{1F3AF}"})}),jsxRuntime.jsxs("div",{style:S.questAccordionInfo,children:[jsxRuntime.jsxs("div",{style:S.questAccordionTitle,children:[jsxRuntime.jsx("span",{style:{...S.questAccordionName,...n?.textColor&&{color:n.textColor}},children:u.name}),jsxRuntime.jsx("span",{style:{...S.questAccordionStatusBadge,...h},children:u.status==="completed"?"Complete":u.status==="in_progress"?`${u.percentComplete}%`:"Not Started"})]}),jsxRuntime.jsxs("div",{style:S.questAccordionMeta,children:[t&&u.xpReward>0&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{children:"\u2B50"}),jsxRuntime.jsxs("span",{children:["+",u.xpReward," XP"]}),jsxRuntime.jsx("span",{style:{color:"#e9ecef"},children:"|"})]}),jsxRuntime.jsxs("span",{children:[u.steps.length," steps"]})]})]}),d&&jsxRuntime.jsx("span",{style:{...S.questAccordionChevron,transform:y?"rotate(90deg)":"rotate(0deg)"},children:"\u25B6"})]}),y&&jsxRuntime.jsxs("div",{style:S.questAccordionContent,children:[u.status!=="completed"&&jsxRuntime.jsx("div",{style:{...S.questProgressBar,marginBottom:"12px",height:"6px"},children:jsxRuntime.jsx("div",{style:{...S.questProgressFill,width:`${u.percentComplete}%`,...n?.progressColor&&{backgroundColor:n.progressColor}}})}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:u.steps.map((w,R)=>jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px",padding:"8px",borderRadius:"6px",opacity:w.completed?.6:1},children:[jsxRuntime.jsx("div",{style:{width:"20px",height:"20px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:"bold",flexShrink:0,backgroundColor:w.completed?"rgba(40, 167, 69, 0.2)":"#f8f9fa",color:w.completed?"#28a745":"#6c757d"},children:w.completed?"\u2713":R+1}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:{fontSize:"14px",fontWeight:"500",textDecoration:w.completed?"line-through":"none",color:w.completed?"#6c757d":"#212529"},children:w.name}),jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:"#6c757d"},children:[w.currentCount,"/",w.requiredCount,w.requiredCount>1&&!w.completed&&jsxRuntime.jsxs("span",{style:{marginLeft:"8px"},children:["(",Math.round(w.currentCount/w.requiredCount*100),"%)"]})]})]})]},w.id))})]})]});return q!=="div"?jsxRuntime.jsx(q,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},children:L},u.id):jsxRuntime.jsx("div",{children:L},u.id)})})})}var We=D(Fe);function Ge({ruleId:e,size:o="md",showFreezeButton:s=true,className:i,style:d,onFreeze:p,theme:t,renderLoading:a,renderError:n}){let{streaks:c,stats:f,loading:g,error:m,freeze:b,refresh:C}=ne({autoRefresh:true}),[B,I]=ke.useState(false);if(ke.useEffect(()=>{C();},[C]),g)return a?a():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return n?n(m):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:m});let k=c;if(e&&(k=c.filter(v=>v.id===e)),k.length===0)return jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:"#6c757d"},children:"No streaks available"});let P={sm:{flame:"24px",count:"20px",container:"12px"},md:{flame:"32px",count:"28px",container:"16px"},lg:{flame:"48px",count:"40px",container:"20px"}},x=async v=>{I(true);try{let A=await b(v);A&&p&&p(v,A.remainingFreezes);}finally{I(false);}};return jsxRuntime.jsx("div",{className:i,style:d,children:k.map(v=>{let A=Ee(v.status),T=v.freezeInventory>0&&!v.freezeUsedToday;return jsxRuntime.jsxs("div",{style:{...S.streakContainer,padding:P[o].container,...t?.cardBackground&&{backgroundColor:t.cardBackground}},children:[jsxRuntime.jsx("span",{style:{...S.streakFlame,fontSize:P[o].flame,...t?.flameColor&&{color:t.flameColor}},children:"\u{1F525}"}),jsxRuntime.jsx("span",{style:{...S.streakCount,fontSize:P[o].count,...t?.countColor&&{color:t.countColor}},children:v.currentCount}),jsxRuntime.jsxs("div",{style:S.streakInfo,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx("span",{style:S.streakName,children:v.name}),jsxRuntime.jsx("span",{style:{...S.streakStatus,backgroundColor:A.bg,color:A.color},children:v.status})]}),jsxRuntime.jsxs("span",{style:S.streakLabel,children:["Best: ",v.maxStreak," days"]})]}),s&&jsxRuntime.jsxs("button",{type:"button",onClick:()=>{x(v.id);},disabled:!T||B,style:T?S.freezeButton:S.freezeButtonDisabled,children:[jsxRuntime.jsx("span",{children:"\u2744\uFE0F"}),jsxRuntime.jsx("span",{children:v.freezeInventory})]})]},v.id)})})}var Ue=D(Ge);function De({showLocked:e=true,category:o,columns:s=2,className:i,style:d,showProgressSummary:p=true,showFilterTabs:t=true,showStats:a,onBadgeClick:n,theme:c,renderLoading:f,renderError:g,renderBadge:m}){let b=V(),C=X(b),{badges:B,stats:I,loading:k,error:P,refresh:x}=ae({autoRefresh:true,category:o}),[v,A]=ke.useState("all"),T=p??a??true;if(ke.useEffect(()=>{x(o);},[x,o]),k)return f?f():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px",color:b.foregroundSecondary},children:"Loading..."});if(P)return g?g(P):jsxRuntime.jsx("div",{style:{color:b.error,padding:"16px"},children:P});let u=B;v==="unlocked"?u=B.filter(R=>R.isUnlocked):v==="locked"?u=B.filter(R=>!R.isUnlocked):e||(u=B.filter(R=>R.isUnlocked));let y=R=>{switch(R){case "LEGENDARY":return {color:b.rarityLegendary,bg:`${b.rarityLegendary}15`};case "EPIC":return {color:b.rarityEpic,bg:`${b.rarityEpic}15`};case "RARE":return {color:b.rarityRare,bg:`${b.rarityRare}15`};case "COMMON":default:return {color:b.rarityCommon,bg:`${b.rarityCommon}15`}}},h={display:"grid",gridTemplateColumns:`repeat(${s}, 1fr)`,gap:"12px",padding:"0"},E=I?.unlocked??B.filter(R=>R.isUnlocked).length,L=I?.total??B.length,w=L>0?E/L*100:0;return jsxRuntime.jsxs("div",{className:i,style:{...d,padding:"16px"},children:[T&&jsxRuntime.jsxs("div",{style:C.progressSummary,children:[jsxRuntime.jsxs("div",{style:C.progressSummaryLeft,children:[jsxRuntime.jsx("div",{style:C.progressSummaryIcon,children:"\u2728"}),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:C.progressSummaryText,children:[E," / ",L]}),jsxRuntime.jsx("div",{style:C.progressSummarySubtext,children:"Badges Earned"})]})]}),jsxRuntime.jsx("div",{style:C.progressSummaryBar,children:jsxRuntime.jsx("div",{style:{...C.progressSummaryBarFill,width:`${w}%`}})})]}),t&&jsxRuntime.jsx("div",{style:C.filterTabs,children:["all","unlocked","locked"].map(R=>jsxRuntime.jsx("button",{type:"button",onClick:()=>A(R),style:v===R?C.filterTabActive:C.filterTab,children:R==="all"?"All":R==="unlocked"?"Earned":"Locked"},R))}),jsxRuntime.jsx("div",{style:h,children:jsxRuntime.jsx(_,{mode:"popLayout",children:u.map(R=>{if(m)return jsxRuntime.jsx("div",{children:m(R)},R.id);let G=y(R.rarity),j=jsxRuntime.jsxs("div",{style:{position:"relative",padding:"12px",borderRadius:"8px",border:"1px solid",cursor:n?"pointer":"default",transition:"all 0.2s",...R.isUnlocked?{backgroundColor:G.bg,borderColor:`${G.color}40`,...c?.cardBackground&&{backgroundColor:c.cardBackground},...c?.cardBorder&&{borderColor:c.cardBorder}}:{backgroundColor:b.backgroundSecondary,borderColor:b.border,opacity:.6}},onClick:()=>n?.(R),onKeyDown:Q=>Q.key==="Enter"&&n?.(R),role:n?"button":void 0,tabIndex:n?0:void 0,children:[R.isUnlocked&&jsxRuntime.jsx("div",{style:C.badgeCheckmark,children:"\u2713"}),jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:jsxRuntime.jsx("div",{style:{width:"32px",height:"32px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:R.isUnlocked?`${G.color}20`:b.backgroundSecondary},children:R.iconUrl?jsxRuntime.jsx("img",{src:R.iconUrl,alt:R.name,style:{width:"16px",height:"16px",objectFit:"contain"}}):R.isUnlocked?jsxRuntime.jsx("span",{style:{color:G.color},children:"\u{1F3C5}"}):jsxRuntime.jsx("span",{style:{color:b.foregroundSecondary},children:"\u{1F512}"})})}),jsxRuntime.jsx("h4",{style:{fontSize:"14px",fontWeight:"500",marginBottom:"4px",color:b.foreground},children:R.name}),R.description&&jsxRuntime.jsx("p",{style:{fontSize:"12px",color:b.foregroundSecondary,marginBottom:"8px",lineHeight:1.4},children:R.description}),jsxRuntime.jsx("span",{style:{fontSize:"10px",padding:"2px 6px",borderRadius:"9999px",fontWeight:"500",backgroundColor:`${G.color}20`,color:G.color},children:R.rarity})]});return q!=="div"?jsxRuntime.jsx(q,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},children:j},R.id):jsxRuntime.jsx("div",{children:j},R.id)})})}),u.length===0&&jsxRuntime.jsxs("div",{style:{textAlign:"center",padding:"24px",color:"#6c757d"},children:[jsxRuntime.jsx("span",{style:{fontSize:"40px",display:"block",marginBottom:"8px",opacity:.5},children:"\u{1F3C5}"}),jsxRuntime.jsx("p",{children:"No badges found"})]})]})}var Me=D(De);function $e({showNextTier:e=true,showBenefits:o=false,className:s,style:i,theme:d,renderLoading:p,renderError:t}){let{profile:a,loading:n,error:c,refreshProfile:f}=re({autoRefresh:true});if(ke.useEffect(()=>{f();},[f]),n)return p?p():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(c)return t?t(c):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:c});if(!a)return null;let g=a.nextTier?Math.min(100,a.points/a.nextTier.minPoints*100):100,m={...S.levelContainer,...d?.cardBackground&&{backgroundColor:d.cardBackground}},b={...S.levelProgressFill,width:`${g}%`,...d?.progressGradient&&{background:d.progressGradient}};return jsxRuntime.jsxs("div",{className:s,style:{...m,...i},children:[jsxRuntime.jsxs("div",{style:S.levelHeader,children:[jsxRuntime.jsx("div",{style:{...S.levelIcon,...a.tier?.color&&{backgroundColor:a.tier.color}},children:a.tier?.iconUrl?jsxRuntime.jsx("img",{src:a.tier.iconUrl,alt:a.tier.name,style:{width:"100%",height:"100%",borderRadius:"50%"}}):"\u2B50"}),jsxRuntime.jsxs("div",{style:S.levelInfo,children:[jsxRuntime.jsx("div",{style:{...S.levelTierName,...d?.textColor&&{color:d.textColor}},children:a.tier?.name??"No Tier"}),jsxRuntime.jsxs("div",{style:S.levelPoints,children:[a.points.toLocaleString()," points"]})]})]}),e&&a.nextTier&&jsxRuntime.jsxs("div",{style:S.levelProgressContainer,children:[jsxRuntime.jsxs("div",{style:S.levelProgressHeader,children:[jsxRuntime.jsxs("span",{style:{color:"#6c757d"},children:["Progress to ",a.nextTier.name]}),jsxRuntime.jsxs("span",{style:{fontWeight:"500"},children:[a.nextTier.pointsNeeded.toLocaleString()," points needed"]})]}),jsxRuntime.jsx("div",{style:S.levelProgressBar,children:jsxRuntime.jsx("div",{style:b})})]}),o&&a.tier?.benefits&&Object.keys(a.tier.benefits).length>0&&jsxRuntime.jsxs("div",{style:S.levelBenefits,children:[jsxRuntime.jsx("div",{style:S.levelBenefitsTitle,children:"Your Benefits"}),jsxRuntime.jsx("ul",{style:S.levelBenefitsList,children:Object.entries(a.tier.benefits).map(([C,B])=>jsxRuntime.jsxs("li",{style:S.levelBenefitItem,children:[jsxRuntime.jsx("span",{style:{marginRight:"8px",color:"#28a745"},children:"\u2713"}),String(B)]},C))})]})]})}var qe=D($e);function Qe({showUnavailable:e=true,className:o,style:s,showPointsHeader:i=true,onRedeem:d,theme:p,renderLoading:t,renderError:a,renderItem:n}){let{items:c,userPoints:f,loading:g,error:m,redeem:b,refresh:C}=se({autoRefresh:true}),[B,I]=ke.useState(null);if(ke.useEffect(()=>{C();},[C]),g&&c.length===0)return t?t():jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return a?a(m):jsxRuntime.jsx("div",{style:{color:"red",padding:"16px"},children:m});let k=c;e||(k=c.filter(x=>x.isAvailable));let P=async x=>{I(x.id);try{let v=await b(x.id);v&&d&&d(x,v);}finally{I(null);}};return jsxRuntime.jsxs("div",{className:o,style:s,children:[i&&jsxRuntime.jsxs("div",{style:S.rewardPointsHeader,children:[jsxRuntime.jsx("span",{style:S.rewardPointsLabel,children:"Your Points"}),jsxRuntime.jsx("span",{style:S.rewardPointsValue,children:f.toLocaleString()})]}),jsxRuntime.jsx("div",{style:S.rewardStoreGrid,children:k.map(x=>{if(n)return jsxRuntime.jsx("div",{children:n(x,()=>{P(x);})},x.id);let v=x.isAvailable?{...S.rewardCard,...p?.cardBackground&&{backgroundColor:p.cardBackground}}:S.rewardCardUnavailable,A=x.isAvailable&&x.canAfford?{...S.rewardButton,...p?.buttonColor&&{backgroundColor:p.buttonColor}}:S.rewardButtonDisabled,T=B===x.id;return jsxRuntime.jsxs("div",{style:v,children:[x.imageUrl?jsxRuntime.jsx("img",{src:x.imageUrl,alt:x.name,style:S.rewardImage}):jsxRuntime.jsx("div",{style:{...S.rewardImage,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"32px"},children:"\u{1F381}"}),jsxRuntime.jsxs("div",{style:S.rewardContent,children:[jsxRuntime.jsx("span",{style:S.rewardName,children:x.name}),x.description&&jsxRuntime.jsx("span",{style:S.rewardDescription,children:x.description}),jsxRuntime.jsxs("span",{style:S.rewardCost,children:[x.pointsCost.toLocaleString()," points"]}),x.requiredBadgeName&&!x.hasBadge&&jsxRuntime.jsxs("span",{style:{fontSize:"12px",color:"#dc3545",marginBottom:"8px"},children:["Requires: ",x.requiredBadgeName]}),jsxRuntime.jsx("button",{type:"button",onClick:()=>{P(x);},disabled:!x.isAvailable||!x.canAfford||T,style:A,children:T?"Redeeming...":x.canAfford?"Redeem":`Need ${(x.pointsCost-f).toLocaleString()} more`})]})]},x.id)})})]})}var Ve=D(Qe);Object.defineProperty(exports,"defaultTheme",{enumerable:true,get:function(){return core.defaultTheme}});exports.AffiliateStats=ze;exports.BadgeGrid=Me;exports.GamifyPageView=we;exports.GamifyProvider=be;exports.GamifyTrackClick=Be;exports.Leaderboard=Ae;exports.LevelProgress=qe;exports.QuestProgress=We;exports.ReferralLink=Ne;exports.RewardStore=Ve;exports.StreakFlame=Ue;exports.useAffiliateStats=Y;exports.useBadges=ae;exports.useGamify=Ce;exports.useGamifyTheme=V;exports.useIdentify=Re;exports.useLeaderboard=te;exports.useLoyalty=re;exports.useQuests=oe;exports.useReferral=Pe;exports.useRewards=se;exports.useSession=ve;exports.useStreaks=ne;exports.useTrack=K;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map