@gamifyio/react 0.1.3 → 0.1.5
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -122
- package/dist/index.d.ts +67 -122
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -2
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {createContext,useRef,useMemo,useEffect,useCallback,useState,cloneElement,useContext}from'react';import {Gamify}from'@gamifyio/core';import {jsx,Fragment,jsxs}from'react/jsx-runtime';var K=createContext(null);function X(){return typeof window>"u"}function Z({config:r,children:t}){let o=useRef(null),a=useMemo(()=>{if(X())return null;if(o.current)return o.current;let i=new Gamify(r);return o.current=i,i},[r.apiKey,r.endpoint]);useEffect(()=>()=>{o.current&&(o.current.shutdown(),o.current=null);},[]);let u=useMemo(()=>a?{client:a,track:(i,e)=>a.track(i,e),identify:(i,e)=>a.identify(i,e),reset:()=>a.reset(),getUserId:()=>a.getUserId(),getAnonymousId:()=>a.getAnonymousId()}:null,[a]);return u?jsx(K.Provider,{value:u,children:t}):jsx(Fragment,{children:t})}function w(){return useContext(K)}function re(){let r=w();if(!r)throw new Error("useGamify must be used within a GamifyProvider. Make sure your component is wrapped with <GamifyProvider>.");return r}function G(){let r=w();return useCallback((t,o)=>{r&&r.track(t,o);},[r])}function te(){let r=w();return useCallback((t,o)=>{r&&r.identify(t,o);},[r])}function oe(){let r=w(),[t,o]=useState({session:r?.client?.session?.getCachedSession()??null,loading:false,error:null}),a=useCallback(async(l,d,R)=>{if(!r?.client){o(S=>({...S,error:"SDK not initialized"}));return}o(S=>({...S,loading:true,error:null}));try{let S=await r.client.updateCart(l,d,R);o({session:S,loading:!1,error:null});}catch(S){let x=S instanceof Error?S.message:"Unknown error";o(P=>({...P,loading:false,error:x}));}},[r]),u=useCallback(async l=>{if(!r?.client?.session){o(d=>({...d,error:"SDK not initialized"}));return}o(d=>({...d,loading:true,error:null}));try{let d=await r.client.session.applyCoupon(l);o({session:d,loading:!1,error:null});}catch(d){let R=d instanceof Error?d.message:"Unknown error";o(S=>({...S,loading:false,error:R}));}},[r]),i=useCallback(async()=>{if(!r?.client?.session){o(l=>({...l,error:"SDK not initialized"}));return}o(l=>({...l,loading:true,error:null}));try{let l=await r.client.session.complete();o({session:l,loading:!1,error:null});}catch(l){let d=l instanceof Error?l.message:"Unknown error";o(R=>({...R,loading:false,error:d}));}},[r]),e=useCallback(()=>{r?.client?.session&&(r.client.session.clearSession(),o({session:null,loading:false,error:null}));},[r]),s=useCallback(async()=>{if(r?.client?.session){o(l=>({...l,loading:true,error:null}));try{let l=await r.client.session.getSession();o({session:l,loading:!1,error:null});}catch(l){let d=l instanceof Error?l.message:"Unknown error";o(R=>({...R,loading:false,error:d}));}}},[r]);return {...t,updateCart:a,applyCoupon:u,complete:i,clearSession:e,refresh:s}}function U(r){let t=w(),[o,a]=useState({profile:t?.client?.loyalty?.getCachedProfile()??null,history:null,loading:false,error:null}),u=useCallback(async()=>{if(!t?.client){a(e=>({...e,error:"SDK not initialized"}));return}a(e=>({...e,loading:true,error:null}));try{let e=await t.client.getLoyaltyProfile();a(s=>({...s,profile:e,loading:!1,error:null}));}catch(e){let s=e instanceof Error?e.message:"Unknown error";a(l=>({...l,loading:false,error:s}));}},[t]),i=useCallback(async(e,s)=>{if(!t?.client){a(l=>({...l,error:"SDK not initialized"}));return}a(l=>({...l,loading:true,error:null}));try{let l=await t.client.getLoyaltyHistory(e,s);a(d=>({...d,history:l,loading:!1,error:null}));}catch(l){let d=l instanceof Error?l.message:"Unknown error";a(R=>({...R,loading:false,error:d}));}},[t]);return useEffect(()=>{r?.autoRefresh&&t?.client?.getUserId()&&u();},[r?.autoRefresh,t,u]),{...o,refreshProfile:u,refreshHistory:i}}function ae(){let r=w(),[t,o]=useState({referrerCode:r?.client?.referral?.getReferrer()??null,hasReferrer:r?.client?.referral?.hasReferrer()??false}),a=useCallback(e=>{r?.client?.referral&&(r.client.referral.setReferrer(e),o({referrerCode:e,hasReferrer:true}));},[r]),u=useCallback(()=>{r?.client?.referral&&(r.client.referral.clearReferrer(),o({referrerCode:null,hasReferrer:false}));},[r]),i=useCallback(()=>{if(r?.client?.referral){let e=r.client.referral.detectReferrerFromUrl();return e&&o({referrerCode:e,hasReferrer:true}),e}return null},[r]);return useEffect(()=>{if(r?.client?.referral){let e=r.client.referral.getReferrer();o({referrerCode:e,hasReferrer:e!==null});}},[r]),{...t,setReferrer:a,clearReferrer:u,detectFromUrl:i}}function T(r){let t=w(),[o,a]=useState({stats:t?.client?.affiliate?.getCachedStats()??null,loading:false,error:null}),u=useCallback(async(i=false)=>{if(!t?.client){a(e=>({...e,error:"SDK not initialized"}));return}a(e=>({...e,loading:true,error:null}));try{let e=await t.client.getAffiliateStats(i);a({stats:e,loading:!1,error:null});}catch(e){let s=e instanceof Error?e.message:"Unknown error";a(l=>({...l,loading:false,error:s}));}},[t]);return useEffect(()=>{r?.autoRefresh&&t?.client?.getUserId()&&u();},[r?.autoRefresh,t,u]),{...o,refreshStats:u}}function E(r=10){let t=w(),[o,a]=useState({leaderboard:null,loading:false,error:null}),u=useCallback(async i=>{if(!t?.client){a(e=>({...e,error:"SDK not initialized"}));return}a(e=>({...e,loading:true,error:null}));try{let e=await t.client.getLeaderboard(i??r);a({leaderboard:e,loading:!1,error:null});}catch(e){let s=e instanceof Error?e.message:"Unknown error";a(l=>({...l,loading:false,error:s}));}},[t,r]);return {...o,refresh:u}}function W(r){let t=w(),[o,a]=useState({quests:[],loading:false,error:null}),u=useCallback(async()=>{if(!t?.client){a(i=>({...i,error:"SDK not initialized"}));return}a(i=>({...i,loading:true,error:null}));try{let i=await t.client.getQuests();a({quests:i.quests,loading:!1,error:null});}catch(i){let e=i instanceof Error?i.message:"Unknown error";a(s=>({...s,loading:false,error:e}));}},[t]);return useEffect(()=>{r?.autoRefresh&&t?.client?.getUserId()&&u();},[r?.autoRefresh,t,u]),{...o,refresh:u}}function F(r){let t=w(),[o,a]=useState({streaks:[],stats:null,loading:false,error:null}),u=useCallback(async()=>{if(!t?.client){a(e=>({...e,error:"SDK not initialized"}));return}a(e=>({...e,loading:true,error:null}));try{let e=await t.client.getStreaks();a({streaks:e.streaks,stats:e.stats,loading:!1,error:null});}catch(e){let s=e instanceof Error?e.message:"Unknown error";a(l=>({...l,loading:false,error:s}));}},[t]),i=useCallback(async e=>{if(!t?.client)return a(s=>({...s,error:"SDK not initialized"})),null;try{let s=await t.client.useStreakFreeze(e);return await u(),s}catch(s){let l=s instanceof Error?s.message:"Unknown error";return a(d=>({...d,error:l})),null}},[t,u]);return useEffect(()=>{r?.autoRefresh&&t?.client?.getUserId()&&u();},[r?.autoRefresh,t,u]),{...o,refresh:u,freeze:i}}function D(r){let t=w(),[o,a]=useState({badges:[],stats:null,earned:[],locked:[],loading:false,error:null}),u=useCallback(async i=>{if(!t?.client){a(e=>({...e,error:"SDK not initialized"}));return}a(e=>({...e,loading:true,error:null}));try{let e=await t.client.getBadges(i??r?.category),s=e.badges.filter(d=>d.isUnlocked),l=e.badges.filter(d=>!d.isUnlocked);a({badges:e.badges,stats:e.stats,earned:s,locked:l,loading:!1,error:null});}catch(e){let s=e instanceof Error?e.message:"Unknown error";a(l=>({...l,loading:false,error:s}));}},[t,r?.category]);return useEffect(()=>{r?.autoRefresh&&t?.client?.getUserId()&&u();},[r?.autoRefresh,t,u]),{...o,refresh:u}}function Q(r){let t=w(),[o,a]=useState({items:[],userPoints:0,available:[],unavailable:[],loading:false,error:null}),u=useCallback(async()=>{if(!t?.client){a(e=>({...e,error:"SDK not initialized"}));return}a(e=>({...e,loading:true,error:null}));try{let e=await t.client.getRewardsStore(),s=e.items.filter(d=>d.isAvailable),l=e.items.filter(d=>!d.isAvailable);a({items:e.items,userPoints:e.userPoints,available:s,unavailable:l,loading:!1,error:null});}catch(e){let s=e instanceof Error?e.message:"Unknown error";a(l=>({...l,loading:false,error:s}));}},[t]),i=useCallback(async e=>{if(!t?.client)return a(s=>({...s,error:"SDK not initialized"})),null;a(s=>({...s,loading:true,error:null}));try{let s=await t.client.redeemReward(e);return await u(),s}catch(s){let l=s instanceof Error?s.message:"Unknown error";return a(d=>({...d,loading:false,error:l})),null}},[t,u]);return useEffect(()=>{r?.autoRefresh&&t?.client?.getUserId()&&u();},[r?.autoRefresh,t,u]),{...o,refresh:u,redeem:i}}function ne({pageName:r,properties:t,pathname:o}){let a=G(),u=useRef(null);return useEffect(()=>{if(typeof window>"u")return;if(o!==void 0){if(u.current===o)return;u.current=o;}let i=r??(typeof document<"u"?document.title:null)??(typeof window<"u"?window.location.pathname:"unknown");a("page_view",{page:i,url:typeof window<"u"?window.location.href:void 0,referrer:typeof document<"u"?document.referrer:void 0,...t});},[a,r,o,t]),null}function ie({eventType:r,properties:t,children:o}){let a=G();return cloneElement(o,{onClick:i=>{a(r,t),o.props.onClick&&o.props.onClick(i);}})}var k={statsContainer:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(150px, 1fr))",gap:"16px",padding:"16px"},statsCard:{backgroundColor:"#f8f9fa",borderRadius:"8px",padding:"16px",textAlign:"center",border:"1px solid #e9ecef"},statsValue:{fontSize:"24px",fontWeight:"bold",color:"#212529",marginBottom:"4px"},statsLabel:{fontSize:"14px",color:"#6c757d"},leaderboardContainer:{padding:"16px"},leaderboardList:{listStyle:"none",padding:0,margin:0},leaderboardRow:{display:"flex",alignItems:"center",padding:"12px",borderBottom:"1px solid #e9ecef"},leaderboardRowHighlighted:{display:"flex",alignItems:"center",padding:"12px",borderBottom:"1px solid #e9ecef",backgroundColor:"#fff3cd"},leaderboardRank:{fontWeight:"bold",width:"40px",color:"#212529"},leaderboardName:{flex:1,marginLeft:"12px",color:"#212529"},leaderboardStats:{color:"#6c757d",fontSize:"14px"},leaderboardEmpty:{textAlign:"center",padding:"32px",color:"#6c757d"},referralContainer:{display:"flex",gap:"8px",padding:"8px"},referralInput:{flex:1,padding:"10px 12px",border:"1px solid #ced4da",borderRadius:"6px",fontSize:"14px",backgroundColor:"#f8f9fa",color:"#212529"},referralButton:{padding:"10px 16px",border:"none",borderRadius:"6px",backgroundColor:"#0d6efd",color:"white",cursor:"pointer",fontSize:"14px",fontWeight:"500"}};function le({className:r,style:t,theme:o,autoRefresh:a=true,renderLoading:u,renderError:i}){let{stats:e,loading:s,error:l,refreshStats:d}=T({autoRefresh:a});if(useEffect(()=>{a&&d();},[a,d]),s)return u?u():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(l)return i?i(l):jsx("div",{style:{color:"red",padding:"16px"},children:l});if(!e)return null;let R={...k.statsCard,...o?.cardBackground&&{backgroundColor:o.cardBackground},...o?.cardBorder&&{border:`1px solid ${o.cardBorder}`}},S={...k.statsValue,...o?.valueColor&&{color:o.valueColor}},x={...k.statsLabel,...o?.labelColor&&{color:o.labelColor}},P=m=>`$${(m/100).toFixed(2)}`;return jsxs("div",{className:r,style:{...k.statsContainer,...t},children:[jsxs("div",{style:R,children:[jsx("div",{style:S,children:e.referralCount}),jsx("div",{style:x,children:"Referrals"})]}),jsxs("div",{style:R,children:[jsx("div",{style:S,children:e.earnings.transactionCount}),jsx("div",{style:x,children:"Commissions"})]}),jsxs("div",{style:R,children:[jsx("div",{style:S,children:P(e.earnings.totalEarned)}),jsx("div",{style:x,children:"Earnings"})]})]})}function de({limit:r=10,className:t,style:o,currentUserId:a,emptyMessage:u="No leaderboard data available yet.",theme:i,renderRow:e,renderLoading:s,renderError:l}){let{leaderboard:d,loading:R,error:S,refresh:x}=E(r);if(useEffect(()=>{x();},[x]),R)return s?s():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(S)return l?l(S):jsx("div",{style:{color:"red",padding:"16px"},children:S});if(!d||d.entries.length===0)return jsx("div",{className:t,style:{...k.leaderboardEmpty,...o},children:u});let P=f=>({...f?k.leaderboardRowHighlighted:k.leaderboardRow,...i?.rowBackground&&!f&&{backgroundColor:i.rowBackground},...i?.highlightBackground&&f&&{backgroundColor:i.highlightBackground}}),m=i?.textColor?{color:i.textColor}:{},h=i?.secondaryColor?{...k.leaderboardStats,color:i.secondaryColor}:k.leaderboardStats;return jsx("div",{className:t,style:{...k.leaderboardContainer,...o},children:jsx("ol",{style:k.leaderboardList,children:d.entries.map(f=>{let b=a===f.userId;return e?jsx("li",{children:e(f,b)},f.userId):jsxs("li",{style:P(b),children:[jsxs("span",{style:{...k.leaderboardRank,...m},children:["#",f.rank]}),jsx("span",{style:{...k.leaderboardName,...m},children:f.displayName??`User ${f.userId.slice(0,8)}`}),jsxs("span",{style:h,children:[f.referralCount," referrals"]})]},f.userId)})})})}function ce({baseUrl:r,className:t,style:o,copyButtonText:a="Copy",copiedText:u="Copied!",shareButtonText:i="Share",shareTitle:e="Check this out!",shareText:s="Join using my referral link",showShareButton:l=true,theme:d,onCopy:R,onShare:S}){let{stats:x}=T({autoRefresh:true}),[P,m]=useState(false),h=x?.referralCode;if(!h)return null;let f=typeof window<"u"?window.location.origin:"",b=`${r??f}?ref=${h}`,g=async()=>{try{await navigator.clipboard.writeText(b),m(!0),R?.(b),setTimeout(()=>m(!1),2e3);}catch(N){console.error("Failed to copy:",N);}},y=async()=>{if(typeof navigator<"u"&&navigator.share)try{await navigator.share({title:e,text:s,url:b}),S?.(b);}catch(N){N.name!=="AbortError"&&console.error("Failed to share:",N);}},v=typeof navigator<"u"&&"share"in navigator,B={...k.referralInput,...d?.inputBackground&&{backgroundColor:d.inputBackground},...d?.inputBorder&&{border:`1px solid ${d.inputBorder}`},...d?.inputColor&&{color:d.inputColor}},z={...k.referralButton,...d?.buttonBackground&&{backgroundColor:d.buttonBackground},...d?.buttonColor&&{color:d.buttonColor}};return jsxs("div",{className:t,style:{...k.referralContainer,...o},children:[jsx("input",{type:"text",readOnly:true,value:b,style:B,onClick:N=>N.target.select()}),jsx("button",{type:"button",onClick:g,style:z,children:P?u:a}),l&&v&&jsx("button",{type:"button",onClick:y,style:z,children:i})]})}var c={questContainer:{padding:"16px",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef",marginBottom:"12px"},questHeader:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"12px"},questTitle:{fontSize:"16px",fontWeight:"600",color:"#212529",margin:0},questDescription:{fontSize:"14px",color:"#6c757d",margin:"4px 0 0 0"},questBadge:{fontSize:"12px",padding:"4px 8px",borderRadius:"12px",fontWeight:"500"},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"},questStepList:{listStyle:"none",padding:0,margin:0},questStep:{display:"flex",alignItems:"center",padding:"8px 0",borderBottom:"1px solid #f8f9fa",fontSize:"14px"},questStepIcon:{width:"20px",height:"20px",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",marginRight:"12px",fontSize:"12px"},questStepText:{flex:1,color:"#212529"},questStepCount:{fontSize:"12px",color:"#6c757d"},questReward:{display:"flex",alignItems:"center",marginTop:"12px",padding:"8px 12px",backgroundColor:"#fff3cd",borderRadius:"6px",fontSize:"14px",color:"#856404"},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},badgeGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(120px, 1fr))",gap:"16px",padding:"16px"},badgeCard:{display:"flex",flexDirection:"column",alignItems:"center",padding:"16px",backgroundColor:"#fff",borderRadius:"8px",border:"1px solid #e9ecef",cursor:"pointer",transition:"transform 0.2s, box-shadow 0.2s"},badgeCardLocked:{display:"flex",flexDirection:"column",alignItems:"center",padding:"16px",backgroundColor:"#f8f9fa",borderRadius:"8px",border:"1px solid #e9ecef",cursor:"pointer",opacity:.6,filter:"grayscale(100%)"},badgeIcon:{width:"64px",height:"64px",borderRadius:"50%",objectFit:"cover",marginBottom:"8px",backgroundColor:"#e9ecef"},badgeName:{fontSize:"14px",fontWeight:"500",color:"#212529",textAlign:"center",marginBottom:"4px"},badgeRarity:{fontSize:"11px",padding:"2px 8px",borderRadius:"10px",fontWeight:"500",textTransform:"uppercase"},badgeStats:{display:"flex",justifyContent:"center",gap:"16px",padding:"12px",backgroundColor:"#f8f9fa",borderRadius:"8px",marginBottom:"16px"},badgeStat:{textAlign:"center"},badgeStatValue:{fontSize:"20px",fontWeight:"bold",color:"#212529"},badgeStatLabel:{fontSize:"12px",color:"#6c757d"},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"}};function $(r){switch(r){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 ue(r){switch(r){case "COMMON":return {bg:"#e9ecef",color:"#495057"};case "RARE":return {bg:"#cce5ff",color:"#004085"};case "EPIC":return {bg:"#e2d5f1",color:"#6f42c1"};case "LEGENDARY":return {bg:"#fff3cd",color:"#856404"};default:return {bg:"#e9ecef",color:"#6c757d"}}}function fe({questId:r,hideCompleted:t=false,className:o,style:a,onComplete:u,theme:i,renderLoading:e,renderError:s,renderQuest:l}){let{quests:d,loading:R,error:S,refresh:x}=W({autoRefresh:true}),P=useRef(new Map);if(useEffect(()=>{x();},[x]),useEffect(()=>{u&&d.forEach(b=>{let g=P.current.get(b.id);g&&g.status!=="completed"&&b.status==="completed"&&u(b);});let f=new Map;d.forEach(b=>f.set(b.id,b)),P.current=f;},[d,u]),R)return e?e():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(S)return s?s(S):jsx("div",{style:{color:"red",padding:"16px"},children:S});let m=d;if(r&&(m=d.filter(f=>f.id===r)),t&&(m=m.filter(f=>f.status!=="completed")),m.length===0)return jsx("div",{style:{textAlign:"center",padding:"16px",color:"#6c757d"},children:"No quests available"});let h={...c.questContainer,...i?.cardBackground&&{backgroundColor:i.cardBackground},...i?.cardBorder&&{border:`1px solid ${i.cardBorder}`}};return jsx("div",{className:o,style:a,children:m.map(f=>{if(l)return jsx("div",{children:l(f)},f.id);let b=$(f.status);return jsxs("div",{style:h,children:[jsxs("div",{style:c.questHeader,children:[jsxs("div",{children:[jsx("h3",{style:{...c.questTitle,...i?.textColor&&{color:i.textColor}},children:f.name}),f.description&&jsx("p",{style:c.questDescription,children:f.description})]}),jsx("span",{style:{...c.questBadge,backgroundColor:b.bg,color:b.color},children:f.status.replace("_"," ")})]}),jsx("div",{style:c.questProgressBar,children:jsx("div",{style:{...c.questProgressFill,width:`${f.percentComplete}%`,...i?.progressColor&&{backgroundColor:i.progressColor}}})}),jsx("ul",{style:c.questStepList,children:f.steps.map(g=>jsxs("li",{style:c.questStep,children:[jsx("span",{style:{...c.questStepIcon,backgroundColor:g.completed?"#d4edda":"#e9ecef",color:g.completed?"#155724":"#6c757d"},children:g.completed?"\u2713":g.order}),jsx("span",{style:{...c.questStepText,textDecoration:g.completed?"line-through":"none",color:g.completed?"#6c757d":"#212529"},children:g.name}),jsxs("span",{style:c.questStepCount,children:[g.currentCount,"/",g.requiredCount]})]},g.id))}),f.xpReward>0&&jsxs("div",{style:c.questReward,children:[jsx("span",{style:{marginRight:"6px"},children:"\u2B50"}),f.xpReward," XP reward",f.badgeReward&&" + Badge"]})]},f.id)})})}function pe({ruleId:r,size:t="md",showFreezeButton:o=true,className:a,style:u,onFreeze:i,theme:e,renderLoading:s,renderError:l}){let{streaks:d,stats:R,loading:S,error:x,freeze:P,refresh:m}=F({autoRefresh:true}),[h,f]=useState(false);if(useEffect(()=>{m();},[m]),S)return s?s():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(x)return l?l(x):jsx("div",{style:{color:"red",padding:"16px"},children:x});let b=d;if(r&&(b=d.filter(v=>v.id===r)),b.length===0)return jsx("div",{style:{textAlign:"center",padding:"16px",color:"#6c757d"},children:"No streaks available"});let g={sm:{flame:"24px",count:"20px",container:"12px"},md:{flame:"32px",count:"28px",container:"16px"},lg:{flame:"48px",count:"40px",container:"20px"}},y=async v=>{f(true);try{let B=await P(v);B&&i&&i(v,B.remainingFreezes);}finally{f(false);}};return jsx("div",{className:a,style:u,children:b.map(v=>{let B=$(v.status),z=v.freezeInventory>0&&!v.freezeUsedToday;return jsxs("div",{style:{...c.streakContainer,padding:g[t].container,...e?.cardBackground&&{backgroundColor:e.cardBackground}},children:[jsx("span",{style:{...c.streakFlame,fontSize:g[t].flame,...e?.flameColor&&{color:e.flameColor}},children:"\u{1F525}"}),jsx("span",{style:{...c.streakCount,fontSize:g[t].count,...e?.countColor&&{color:e.countColor}},children:v.currentCount}),jsxs("div",{style:c.streakInfo,children:[jsxs("div",{style:{display:"flex",alignItems:"center"},children:[jsx("span",{style:c.streakName,children:v.name}),jsx("span",{style:{...c.streakStatus,backgroundColor:B.bg,color:B.color},children:v.status})]}),jsxs("span",{style:c.streakLabel,children:["Best: ",v.maxStreak," days"]})]}),o&&jsxs("button",{type:"button",onClick:()=>{y(v.id);},disabled:!z||h,style:z?c.freezeButton:c.freezeButtonDisabled,children:[jsx("span",{children:"\u2744\uFE0F"}),jsx("span",{children:v.freezeInventory})]})]},v.id)})})}function ge({showLocked:r=true,category:t,columns:o=4,className:a,style:u,showStats:i=true,onBadgeClick:e,theme:s,renderLoading:l,renderError:d,renderBadge:R}){let{badges:S,stats:x,loading:P,error:m,refresh:h}=D({autoRefresh:true,category:t});if(useEffect(()=>{h(t);},[h,t]),P)return l?l():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return d?d(m):jsx("div",{style:{color:"red",padding:"16px"},children:m});let f=S;r||(f=S.filter(g=>g.isUnlocked));let b={...c.badgeGrid,gridTemplateColumns:`repeat(${o}, 1fr)`};return jsxs("div",{className:a,style:u,children:[i&&x&&jsxs("div",{style:c.badgeStats,children:[jsxs("div",{style:c.badgeStat,children:[jsx("div",{style:c.badgeStatValue,children:x.unlocked}),jsx("div",{style:c.badgeStatLabel,children:"Unlocked"})]}),jsxs("div",{style:c.badgeStat,children:[jsx("div",{style:c.badgeStatValue,children:x.total}),jsx("div",{style:c.badgeStatLabel,children:"Total"})]}),jsxs("div",{style:c.badgeStat,children:[jsxs("div",{style:c.badgeStatValue,children:[x.total>0?Math.round(x.unlocked/x.total*100):0,"%"]}),jsx("div",{style:c.badgeStatLabel,children:"Progress"})]})]}),jsx("div",{style:b,children:f.map(g=>{if(R)return jsx("div",{children:R(g)},g.id);let y=ue(g.rarity),v=g.isUnlocked?{...c.badgeCard,...s?.cardBackground&&{backgroundColor:s.cardBackground},...s?.cardBorder&&{border:`1px solid ${s.cardBorder}`}}:c.badgeCardLocked;return jsxs("div",{style:v,onClick:()=>e?.(g),onKeyDown:B=>B.key==="Enter"&&e?.(g),role:"button",tabIndex:0,children:[g.iconUrl?jsx("img",{src:g.iconUrl,alt:g.name,style:c.badgeIcon}):jsx("div",{style:c.badgeIcon,children:g.isUnlocked?"\u{1F3C6}":"\u{1F512}"}),jsx("span",{style:c.badgeName,children:g.name}),jsx("span",{style:{...c.badgeRarity,backgroundColor:y.bg,color:y.color},children:g.rarity})]},g.id)})})]})}function ye({showNextTier:r=true,showBenefits:t=false,className:o,style:a,theme:u,renderLoading:i,renderError:e}){let{profile:s,loading:l,error:d,refreshProfile:R}=U({autoRefresh:true});if(useEffect(()=>{R();},[R]),l)return i?i():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(d)return e?e(d):jsx("div",{style:{color:"red",padding:"16px"},children:d});if(!s)return null;let S=s.nextTier?Math.min(100,s.points/s.nextTier.minPoints*100):100,x={...c.levelContainer,...u?.cardBackground&&{backgroundColor:u.cardBackground}},P={...c.levelProgressFill,width:`${S}%`,...u?.progressGradient&&{background:u.progressGradient}};return jsxs("div",{className:o,style:{...x,...a},children:[jsxs("div",{style:c.levelHeader,children:[jsx("div",{style:{...c.levelIcon,...s.tier?.color&&{backgroundColor:s.tier.color}},children:s.tier?.iconUrl?jsx("img",{src:s.tier.iconUrl,alt:s.tier.name,style:{width:"100%",height:"100%",borderRadius:"50%"}}):"\u2B50"}),jsxs("div",{style:c.levelInfo,children:[jsx("div",{style:{...c.levelTierName,...u?.textColor&&{color:u.textColor}},children:s.tier?.name??"No Tier"}),jsxs("div",{style:c.levelPoints,children:[s.points.toLocaleString()," points"]})]})]}),r&&s.nextTier&&jsxs("div",{style:c.levelProgressContainer,children:[jsxs("div",{style:c.levelProgressHeader,children:[jsxs("span",{style:{color:"#6c757d"},children:["Progress to ",s.nextTier.name]}),jsxs("span",{style:{fontWeight:"500"},children:[s.nextTier.pointsNeeded.toLocaleString()," points needed"]})]}),jsx("div",{style:c.levelProgressBar,children:jsx("div",{style:P})})]}),t&&s.tier?.benefits&&Object.keys(s.tier.benefits).length>0&&jsxs("div",{style:c.levelBenefits,children:[jsx("div",{style:c.levelBenefitsTitle,children:"Your Benefits"}),jsx("ul",{style:c.levelBenefitsList,children:Object.entries(s.tier.benefits).map(([m,h])=>jsxs("li",{style:c.levelBenefitItem,children:[jsx("span",{style:{marginRight:"8px",color:"#28a745"},children:"\u2713"}),String(h)]},m))})]})]})}function Se({showUnavailable:r=true,className:t,style:o,showPointsHeader:a=true,onRedeem:u,theme:i,renderLoading:e,renderError:s,renderItem:l}){let{items:d,userPoints:R,loading:S,error:x,redeem:P,refresh:m}=Q({autoRefresh:true}),[h,f]=useState(null);if(useEffect(()=>{m();},[m]),S&&d.length===0)return e?e():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(x)return s?s(x):jsx("div",{style:{color:"red",padding:"16px"},children:x});let b=d;r||(b=d.filter(y=>y.isAvailable));let g=async y=>{f(y.id);try{let v=await P(y.id);v&&u&&u(y,v);}finally{f(null);}};return jsxs("div",{className:t,style:o,children:[a&&jsxs("div",{style:c.rewardPointsHeader,children:[jsx("span",{style:c.rewardPointsLabel,children:"Your Points"}),jsx("span",{style:c.rewardPointsValue,children:R.toLocaleString()})]}),jsx("div",{style:c.rewardStoreGrid,children:b.map(y=>{if(l)return jsx("div",{children:l(y,()=>{g(y);})},y.id);let v=y.isAvailable?{...c.rewardCard,...i?.cardBackground&&{backgroundColor:i.cardBackground}}:c.rewardCardUnavailable,B=y.isAvailable&&y.canAfford?{...c.rewardButton,...i?.buttonColor&&{backgroundColor:i.buttonColor}}:c.rewardButtonDisabled,z=h===y.id;return jsxs("div",{style:v,children:[y.imageUrl?jsx("img",{src:y.imageUrl,alt:y.name,style:c.rewardImage}):jsx("div",{style:{...c.rewardImage,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"32px"},children:"\u{1F381}"}),jsxs("div",{style:c.rewardContent,children:[jsx("span",{style:c.rewardName,children:y.name}),y.description&&jsx("span",{style:c.rewardDescription,children:y.description}),jsxs("span",{style:c.rewardCost,children:[y.pointsCost.toLocaleString()," points"]}),y.requiredBadgeName&&!y.hasBadge&&jsxs("span",{style:{fontSize:"12px",color:"#dc3545",marginBottom:"8px"},children:["Requires: ",y.requiredBadgeName]}),jsx("button",{type:"button",onClick:()=>{g(y);},disabled:!y.isAvailable||!y.canAfford||z,style:B,children:z?"Redeeming...":y.canAfford?"Redeem":`Need ${(y.pointsCost-R).toLocaleString()} more`})]})]},y.id)})})]})}export{le as AffiliateStats,ge as BadgeGrid,ne as GamifyPageView,Z as GamifyProvider,ie as GamifyTrackClick,de as Leaderboard,ye as LevelProgress,fe as QuestProgress,ce as ReferralLink,Se as RewardStore,pe as StreakFlame,T as useAffiliateStats,D as useBadges,re as useGamify,te as useIdentify,E as useLeaderboard,U as useLoyalty,W as useQuests,ae as useReferral,Q as useRewards,oe as useSession,F as useStreaks,G as useTrack};//# sourceMappingURL=index.js.map
|
|
1
|
+
import Pe,{createContext,useRef,useMemo,useEffect,useContext,useCallback,useState,cloneElement}from'react';import {defaultTheme,Gamify}from'@gamifyio/core';export{defaultTheme}from'@gamifyio/core';import {jsx,Fragment,jsxs}from'react/jsx-runtime';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=createContext(null),O=createContext(defaultTheme);function xe(){return typeof window>"u"}function me({config:e,theme:o,children:s}){let i=useRef(null),d=useMemo(()=>o?{...defaultTheme,...o}:defaultTheme,[o]),p=useMemo(()=>{if(xe())return null;if(i.current)return i.current;let a=new Gamify(e);return i.current=a,a},[e.apiKey,e.endpoint]);useEffect(()=>()=>{i.current&&(i.current.shutdown(),i.current=null);},[]);let t=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?jsx(O.Provider,{value:d,children:jsx(de.Provider,{value:t,children:s})}):jsx(O.Provider,{value:d,children:s})}function N(){return useContext(de)}function V(){return 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 useCallback((o,s)=>{e&&e.track(o,s);},[e])}function Ce(){let e=N();return useCallback((o,s)=>{e&&e.identify(o,s);},[e])}function Re(){let e=N(),[o,s]=useState({session:e?.client?.session?.getCachedSession()??null,loading:false,error:null}),i=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=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=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=useCallback(()=>{e?.client?.session&&(e.client.session.clearSession(),s({session:null,loading:false,error:null}));},[e]),a=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]=useState({profile:o?.client?.loyalty?.getCachedProfile()??null,history:null,loading:false,error:null}),d=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=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 useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refreshProfile:d,refreshHistory:p}}function ve(){let e=N(),[o,s]=useState({referrerCode:e?.client?.referral?.getReferrer()??null,hasReferrer:e?.client?.referral?.hasReferrer()??false}),i=useCallback(t=>{e?.client?.referral&&(e.client.referral.setReferrer(t),s({referrerCode:t,hasReferrer:true}));},[e]),d=useCallback(()=>{e?.client?.referral&&(e.client.referral.clearReferrer(),s({referrerCode:null,hasReferrer:false}));},[e]),p=useCallback(()=>{if(e?.client?.referral){let t=e.client.referral.detectReferrerFromUrl();return t&&s({referrerCode:t,hasReferrer:true}),t}return null},[e]);return 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]=useState({stats:o?.client?.affiliate?.getCachedStats()??null,loading:false,error:null}),d=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 useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refreshStats:d}}function re(e=10){let o=N(),[s,i]=useState({leaderboard:null,loading:false,error:null}),d=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]=useState({quests:[],loading:false,error:null}),d=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 useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d}}function oe(e){let o=N(),[s,i]=useState({streaks:[],stats:null,loading:false,error:null}),d=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=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 useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d,freeze:p}}function ne(e){let o=N(),[s,i]=useState({badges:[],stats:null,earned:[],locked:[],loading:false,error:null}),d=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 useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d}}function ae(e){let o=N(),[s,i]=useState({items:[],userPoints:0,available:[],unavailable:[],loading:false,error:null}),d=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=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 useEffect(()=>{e?.autoRefresh&&o?.client?.getUserId()&&d();},[e?.autoRefresh,o,d]),{...s,refresh:d,redeem:p}}var Q="div",Y=({children:e})=>jsx(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.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: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=>jsx(se,{fallback:o,children: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=useRef(null);return 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 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]=useState(false);if(useEffect(()=>{i&&C();},[i,C]),m)return a?a():jsx("div",{style:{textAlign:"center",padding:"16px",color:c.foregroundSecondary},children:"Loading..."});if(b)return n?n(b):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 jsxs("div",{className:e,style:y,children:[d&&jsxs("div",{style:{...u.tierBadge,backgroundColor:g.tier?`${h}20`:c.backgroundSecondary},children:[jsx("span",{style:{...u.tierBadgeIcon,color:h},children:"\u{1F451}"}),jsxs("div",{style:u.tierBadgeText,children:[jsx("div",{style:{...u.tierBadgeName,color:g.tier?h:c.foregroundSecondary},children:g.tier?`${g.tier.name} Affiliate`:"No Tier"}),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&&jsxs("div",{style:u.referralCodeRow,children:[jsxs("div",{children:[jsx("div",{style:u.referralCodeLabel,children:"Your referral code"}),jsx("div",{style:u.referralCodeValue,children:g.referralCode})]}),jsx("button",{type:"button",onClick:v,style:u.referralCodeCopyButton,"aria-label":"Copy referral code",children:B?"\u2713":"\u{1F4CB}"})]}),jsxs("div",{style:u.statsGrid2Col,children:[jsxs("div",{style:k,children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:c.foregroundSecondary,marginBottom:"4px"},children:[jsx("span",{children:"\u{1F465}"}),jsx("span",{style:{fontSize:"12px"},children:"Referrals"})]}),jsx("div",{style:{...P,fontFamily:"monospace"},children:g.referralCount})]}),jsxs("div",{style:k,children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",color:c.foregroundSecondary,marginBottom:"4px"},children:[jsx("span",{children:"\u{1F4B0}"}),jsx("span",{style:{fontSize:"12px"},children:"Commissions"})]}),jsx("div",{style:{...P,fontFamily:"monospace"},children:g.earnings.transactionCount})]})]}),t&&jsxs("div",{style:u.earningsBreakdown,children:[jsx("div",{style:u.earningsTitle,children:"Earnings"}),jsxs("div",{style:u.earningsRow,children:[jsx("span",{style:u.earningsLabel,children:"Total Earned"}),jsx("span",{style:u.earningsValueGreen,children:x(g.earnings.totalEarned)})]}),jsxs("div",{style:u.earningsRow,children:[jsx("span",{style:u.earningsLabel,children:"Pending"}),jsx("span",{style:u.earningsValueYellow,children:x(g.earnings.totalPending)})]}),jsxs("div",{style:u.earningsRow,children:[jsx("span",{style:u.earningsLabel,children:"Paid Out"}),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(useEffect(()=>{k();},[k]),B)return u?u():jsx("div",{style:{textAlign:"center",padding:"16px",color:m.foregroundSecondary},children:"Loading..."});if(I)return g?g(I):jsx("div",{style:{color:m.error,padding:"16px"},children:I});if(!C||C.entries.length===0)return 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 jsxs("div",{className:o,style:{...b.leaderboardContainer,...s},children:[y&&jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"8px"},children:jsxs("span",{style:{fontSize:"12px",backgroundColor:`${m.primary}30`,color:m.primary,padding:"4px 8px",borderRadius:"9999px"},children:["Your rank: #",y]})}),jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:jsx(Y,{mode:"popLayout",children:C.entries.map((f,z)=>{let L=i===f.userId,E=P(f.rank);if(c)return jsx("div",{children:c(f,L)},f.userId);let w=jsxs("div",{style:v(L),children:[jsx("div",{style:b.medalIcon,children:E?jsx("span",{style:{color:E},children:"\u{1F3C5}"}):jsxs("span",{style:{fontSize:"14px",fontFamily:"monospace",color:m.foregroundSecondary},children:["#",f.rank]})}),jsxs("div",{style:{flex:1,marginLeft:"12px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{...b.leaderboardName,...A,marginLeft:0},children:f.displayName??`User ${f.userId.slice(0,8)}`}),L&&jsx("span",{style:{fontSize:"12px",color:m.primary},children:"(You)"})]}),t&&f.tier&&jsxs("div",{style:{fontSize:"12px",color:m.foregroundSecondary},children:[f.tier.name," (",f.tier.value,"%)"]})]}),jsxs("div",{style:{textAlign:"right"},children:[jsxs("div",{style:{fontFamily:"monospace",fontSize:"14px",fontWeight:"500",color:m.foreground},children:[f.referralCount," referrals"]}),a&&f.totalEarnings!==void 0&&jsx("div",{style:{...h,fontFamily:"monospace"},children:x(f.totalEarnings)})]})]});return Q!=="div"?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):jsx("div",{children:w},f.userId)})})}),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]=useState(false),[h,y]=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 jsxs("div",{className:o,style:ue,children:[jsxs("div",{style:{marginBottom:"8px"},children:[jsx("p",{style:{fontSize:"14px",color:k.foregroundSecondary,marginBottom:"8px"},children:"Your unique referral link:"}),jsxs("div",{style:P.referralContainer,children:[jsx("input",{type:"text",readOnly:true,value:L,style:{...j,fontFamily:"monospace",fontSize:"12px"},onClick:U=>U.target.select()}),jsx("button",{type:"button",onClick:E,style:q,children:v?"\u2713":"\u{1F4CB}"}),n&&G&&jsx("button",{type:"button",onClick:w,style:q,children:p})]}),jsxs("p",{style:{fontSize:"12px",color:k.foregroundSecondary,marginTop:"4px"},children:["Code: ",jsx("span",{style:{fontFamily:"monospace",fontWeight:"500",color:k.foreground},children:f})]})]}),c&&jsxs("div",{style:P.referrerSection,children:[jsx("p",{style:P.referrerTitle,children:"Referrer Attribution"}),u?jsxs("div",{style:P.referrerBadge,children:[jsxs("div",{style:P.referrerBadgeInfo,children:[jsx("span",{style:P.referrerBadgeIcon,children:"\u{1F464}"}),jsxs("span",{children:["Referred by: ",jsx("span",{style:{fontFamily:"monospace",fontWeight:"500"},children:u})]})]}),b&&jsx("button",{type:"button",onClick:b,style:P.referrerClearButton,"aria-label":"Clear referrer",children:"\u2715"})]}):jsxs("div",{children:[g&&jsxs("div",{style:P.referrerInputRow,children:[jsx("input",{type:"text",value:h,onChange:U=>y(U.target.value),placeholder:"Enter referrer code...",style:{...j,fontFamily:"monospace",fontSize:"12px"}}),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&&jsxs("button",{type:"button",onClick:m,style:P.referrerDetectButton,children:[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=useRef(new Map),[k,P]=useState(null);if(useEffect(()=>{B();},[B]),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]),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():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(C)return u?u(C):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 jsxs("div",{style:{textAlign:"center",padding:"24px",color:"#6c757d"},children:[jsx("span",{style:{fontSize:"40px",display:"block",marginBottom:"8px",opacity:.5},children:"\u{1F3AF}"}),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 jsx("div",{className:s,style:{...i,display:"flex",flexDirection:"column",gap:"12px"},children:jsx(Y,{mode:"popLayout",children:x.map(y=>{if(g)return jsx("div",{children:g(y)},y.id);let f=!d||k===y.id,z=v(y.status),L=A(y.status),E=jsxs("div",{style:{...S.questAccordion,border:"1px solid",...L,...n?.cardBackground&&{backgroundColor:n.cardBackground},...n?.cardBorder&&{borderColor:n.cardBorder}},children:[jsxs("button",{type:"button",onClick:()=>h(y.id),style:{...S.questAccordionHeader,cursor:d?"pointer":"default"},children:[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"?jsx("span",{style:{color:"#28a745"},children:"\u2713"}):jsx("span",{style:{color:"#0d6efd"},children:"\u{1F3AF}"})}),jsxs("div",{style:S.questAccordionInfo,children:[jsxs("div",{style:S.questAccordionTitle,children:[jsx("span",{style:{...S.questAccordionName,...n?.textColor&&{color:n.textColor}},children:y.name}),jsx("span",{style:{...S.questAccordionStatusBadge,...z},children:y.status==="completed"?"Complete":y.status==="in_progress"?`${y.percentComplete}%`:"Not Started"})]}),jsxs("div",{style:S.questAccordionMeta,children:[t&&y.xpReward>0&&jsxs(Fragment,{children:[jsx("span",{children:"\u2B50"}),jsxs("span",{children:["+",y.xpReward," XP"]}),jsx("span",{style:{color:"#e9ecef"},children:"|"})]}),jsxs("span",{children:[y.steps.length," steps"]})]})]}),d&&jsx("span",{style:{...S.questAccordionChevron,transform:f?"rotate(90deg)":"rotate(0deg)"},children:"\u25B6"})]}),f&&jsxs("div",{style:S.questAccordionContent,children:[y.status!=="completed"&&jsx("div",{style:{...S.questProgressBar,marginBottom:"12px",height:"6px"},children:jsx("div",{style:{...S.questProgressFill,width:`${y.percentComplete}%`,...n?.progressColor&&{backgroundColor:n.progressColor}}})}),jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:y.steps.map((w,R)=>jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px",padding:"8px",borderRadius:"6px",opacity:w.completed?.6:1},children:[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}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:{fontSize:"14px",fontWeight:"500",textDecoration:w.completed?"line-through":"none",color:w.completed?"#6c757d":"#212529"},children:w.name}),jsxs("div",{style:{fontSize:"12px",color:"#6c757d"},children:[w.currentCount,"/",w.requiredCount,w.requiredCount>1&&!w.completed&&jsxs("span",{style:{marginLeft:"8px"},children:["(",Math.round(w.currentCount/w.requiredCount*100),"%)"]})]})]})]},w.id))})]})]});return Q!=="div"?jsx(Q,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},children:E},y.id):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]=useState(false);if(useEffect(()=>{C();},[C]),g)return a?a():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return n?n(m):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 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 jsx("div",{className:i,style:d,children:k.map(v=>{let A=Ne(v.status),h=v.freezeInventory>0&&!v.freezeUsedToday;return jsxs("div",{style:{...S.streakContainer,padding:P[o].container,...t?.cardBackground&&{backgroundColor:t.cardBackground}},children:[jsx("span",{style:{...S.streakFlame,fontSize:P[o].flame,...t?.flameColor&&{color:t.flameColor}},children:"\u{1F525}"}),jsx("span",{style:{...S.streakCount,fontSize:P[o].count,...t?.countColor&&{color:t.countColor}},children:v.currentCount}),jsxs("div",{style:S.streakInfo,children:[jsxs("div",{style:{display:"flex",alignItems:"center"},children:[jsx("span",{style:S.streakName,children:v.name}),jsx("span",{style:{...S.streakStatus,backgroundColor:A.bg,color:A.color},children:v.status})]}),jsxs("span",{style:S.streakLabel,children:["Best: ",v.maxStreak," days"]})]}),s&&jsxs("button",{type:"button",onClick:()=>{x(v.id);},disabled:!h||B,style:h?S.freezeButton:S.freezeButtonDisabled,children:[jsx("span",{children:"\u2744\uFE0F"}),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]=useState("all"),h=p??a??true;if(useEffect(()=>{x(o);},[x,o]),k)return u?u():jsx("div",{style:{textAlign:"center",padding:"16px",color:b.foregroundSecondary},children:"Loading..."});if(P)return g?g(P):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 jsxs("div",{className:i,style:{...d,padding:"16px"},children:[h&&jsxs("div",{style:C.progressSummary,children:[jsxs("div",{style:C.progressSummaryLeft,children:[jsx("div",{style:C.progressSummaryIcon,children:"\u2728"}),jsxs("div",{children:[jsxs("div",{style:C.progressSummaryText,children:[L," / ",E]}),jsx("div",{style:C.progressSummarySubtext,children:"Badges Earned"})]})]}),jsx("div",{style:C.progressSummaryBar,children:jsx("div",{style:{...C.progressSummaryBarFill,width:`${w}%`}})})]}),t&&jsx("div",{style:C.filterTabs,children:["all","unlocked","locked"].map(R=>jsx("button",{type:"button",onClick:()=>A(R),style:v===R?C.filterTabActive:C.filterTab,children:R==="all"?"All":R==="unlocked"?"Earned":"Locked"},R))}),jsx("div",{style:z,children:jsx(Y,{mode:"popLayout",children:y.map(R=>{if(m)return jsx("div",{children:m(R)},R.id);let G=f(R.rarity),j=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&&jsx("div",{style:C.badgeCheckmark,children:"\u2713"}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children: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?jsx("img",{src:R.iconUrl,alt:R.name,style:{width:"16px",height:"16px",objectFit:"contain"}}):R.isUnlocked?jsx("span",{style:{color:G.color},children:"\u{1F3C5}"}):jsx("span",{style:{color:b.foregroundSecondary},children:"\u{1F512}"})})}),jsx("h4",{style:{fontSize:"14px",fontWeight:"500",marginBottom:"4px",color:b.foreground},children:R.name}),R.description&&jsx("p",{style:{fontSize:"12px",color:b.foregroundSecondary,marginBottom:"8px",lineHeight:1.4},children:R.description}),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"?jsx(Q,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},children:j},R.id):jsx("div",{children:j},R.id)})})}),y.length===0&&jsxs("div",{style:{textAlign:"center",padding:"24px",color:"#6c757d"},children:[jsx("span",{style:{fontSize:"40px",display:"block",marginBottom:"8px",opacity:.5},children:"\u{1F3C5}"}),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(useEffect(()=>{u();},[u]),n)return p?p():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(c)return t?t(c):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 jsxs("div",{className:s,style:{...m,...i},children:[jsxs("div",{style:S.levelHeader,children:[jsx("div",{style:{...S.levelIcon,...a.tier?.color&&{backgroundColor:a.tier.color}},children:a.tier?.iconUrl?jsx("img",{src:a.tier.iconUrl,alt:a.tier.name,style:{width:"100%",height:"100%",borderRadius:"50%"}}):"\u2B50"}),jsxs("div",{style:S.levelInfo,children:[jsx("div",{style:{...S.levelTierName,...d?.textColor&&{color:d.textColor}},children:a.tier?.name??"No Tier"}),jsxs("div",{style:S.levelPoints,children:[a.points.toLocaleString()," points"]})]})]}),e&&a.nextTier&&jsxs("div",{style:S.levelProgressContainer,children:[jsxs("div",{style:S.levelProgressHeader,children:[jsxs("span",{style:{color:"#6c757d"},children:["Progress to ",a.nextTier.name]}),jsxs("span",{style:{fontWeight:"500"},children:[a.nextTier.pointsNeeded.toLocaleString()," points needed"]})]}),jsx("div",{style:S.levelProgressBar,children:jsx("div",{style:b})})]}),o&&a.tier?.benefits&&Object.keys(a.tier.benefits).length>0&&jsxs("div",{style:S.levelBenefits,children:[jsx("div",{style:S.levelBenefitsTitle,children:"Your Benefits"}),jsx("ul",{style:S.levelBenefitsList,children:Object.entries(a.tier.benefits).map(([C,B])=>jsxs("li",{style:S.levelBenefitItem,children:[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]=useState(null);if(useEffect(()=>{C();},[C]),g&&c.length===0)return t?t():jsx("div",{style:{textAlign:"center",padding:"16px"},children:"Loading..."});if(m)return a?a(m):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 jsxs("div",{className:o,style:s,children:[i&&jsxs("div",{style:S.rewardPointsHeader,children:[jsx("span",{style:S.rewardPointsLabel,children:"Your Points"}),jsx("span",{style:S.rewardPointsValue,children:u.toLocaleString()})]}),jsx("div",{style:S.rewardStoreGrid,children:k.map(x=>{if(n)return 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 jsxs("div",{style:v,children:[x.imageUrl?jsx("img",{src:x.imageUrl,alt:x.name,style:S.rewardImage}):jsx("div",{style:{...S.rewardImage,display:"flex",alignItems:"center",justifyContent:"center",fontSize:"32px"},children:"\u{1F381}"}),jsxs("div",{style:S.rewardContent,children:[jsx("span",{style:S.rewardName,children:x.name}),x.description&&jsx("span",{style:S.rewardDescription,children:x.description}),jsxs("span",{style:S.rewardCost,children:[x.pointsCost.toLocaleString()," points"]}),x.requiredBadgeName&&!x.hasBadge&&jsxs("span",{style:{fontSize:"12px",color:"#dc3545",marginBottom:"8px"},children:["Requires: ",x.requiredBadgeName]}),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);export{Ie as AffiliateStats,De as BadgeGrid,he as GamifyPageView,me as GamifyProvider,we as GamifyTrackClick,Te as Leaderboard,$e as LevelProgress,Fe as QuestProgress,Le as ReferralLink,qe as RewardStore,Ge as StreakFlame,K as useAffiliateStats,ne as useBadges,be as useGamify,V as useGamifyTheme,Ce as useIdentify,re as useLeaderboard,ee as useLoyalty,te as useQuests,ve as useReferral,ae as useRewards,Re as useSession,oe as useStreaks,H as useTrack};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|