1import{ej as Me,dQ as Fe,en as Le,e5 as Te,e7 as $e,eb as qe,P as G,W as me,db as t,dc as r,c as be,h as T,e as Ae,a8 as ye,l as Ne}from"./index-CmSfgMPc.js";import{b1 as u,ae as Ee,p as fe,A as Re,e as s,g as Be,aj as d,y as He,aa as We,z as he,a9 as pe,v as $,N as q,ay as xe,m as Pe}from"./ui-u4xJzAJX.js";import{L as Ge}from"./Label-CRbSig1w.js";import{u as je}from"./useIsFirstRender-CaDMHm42.js";import{P as ge}from"./Page-DJs2_DnW.js";import{P as Qe}from"./PaddleContext-C8AfNkPE.js";import{d as De}from"./debounce-EtspMjWp.js";import{u as Ue}from"./useClearSubscriptionCache-Bl-1nXgW.js";import{u as Ye}from"./useSubscription-DneNUiyQ.js";import{u as Ke}from"./useGoBack-D4RZMB7_.js";import{P as Ve}from"./PurchaseGate-B_lb6oh1.js";import"./media-UejkmJrh.js";import"./editor-WYCba1gG.js";import"./auth-CAQqEDmo.js";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},l=new n.Error().stack;l&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[l]="00e5df93-c3d1-4564-86c0-e35cbad07ec5",n._sentryDebugIdIdentifier="sentry-dbid-00e5df93-c3d1-4564-86c0-e35cbad07ec5")}catch{}})();const j=n=>!((n==null?void 0:n.available)===0||(n==null?void 0:n.sub_type)!=="paddle"),b=n=>{const l=ye.c(1),{isLoading:i,children:A}=n;if(i){let y;return l[0]===Symbol.for("react.memo_cache_sentinel")?(y=t(s,{sx:{height:24,display:"flex",justifyContent:"flex-end",alignItems:"center"},children:t(Pe,{size:20,color:"inherit"})}),l[0]=y):y=l[0],y}return A};function Je(){var X,Z,O,v,ee,te,ie,oe,ne,re,se,ae,le,ce,de;const[n]=Me(),l=Ue(),[i,A]=u.useState(),[y,Q]=u.useState(!1),[f,_e]=u.useState(n.get("interval")==="monthly"?"month":"year"),[k,N]=u.useState(0),m=4,[D,z]=u.useState(()=>{const e=Number(n.get("seats"));return Number.isInteger(e)&&e>m?e:m}),p=Math.max(m,Number(D)||m),[x,E]=u.useState(!1),U=je(),{paddle:h,setPaddleEventCallback:Se}=Ee.useContext(Qe),{user:we,dbData:M}=Fe(),{enqueueSnackbar:Y}=Le(),{mixpanel:R}=Te(),B=$e(),ke=Ke(),{data:g,isPending:Ce}=Ye();let _=qe({queryKey:["available_subscription"],queryFn:async()=>({data:(await me.get("available_subscriptions")).data})}),H=((X=_==null?void 0:_.data)==null?void 0:X.data)??[];const F=n.get("_ptxn"),K=Number(n.get("plan")),o=H==null?void 0:H.find(e=>e.subscription_plan_id===K),a=((o==null?void 0:o.paddle_products)??[]).find(e=>e.type==="primary"&&e.frequency===f),V=((o==null?void 0:o.paddle_products)??[]).filter(e=>e.type==="coach_seat"&&e.frequency===f),Ie=((o==null?void 0:o.paddle_products)??[]).filter(e=>e.type==="addon"&&e.frequency===f),C=V.length>0?V:Ie,L=(o==null?void 0:o.ownedBy)==="organization"&&(a==null?void 0:a.seats)===1&&C.length===0,ze=()=>{if(M.tolt_referral){let e=Ae.getDateFromMysql(M.signup),w=Math.abs(new Date-e);if(Math.floor(w/(1e3*60*60*24))<60)return{tolt_referral:M.tolt_referral}}return window.tolt_referral?{tolt_referral:window.tolt_referral}:{}},W=!Ce&&!!(g!=null&&g.subscription_id)&&(g==null?void 0:g.paddle_api_type)==="billing";u.useEffect(()=>
1{if(F||!W||_.isPending||!j(o))return;const e=L?`&seats=${p}`:"";B(`${G.updatePlan}?plan=${K}&subscription_id=${g.subscription_id}&interval=${f==="month"?"monthly":"yearly"}`+e,{replace:!0})},[W,F,_.isPending,o]);const P=()=>{var e;return[{quantity:L?p:1,priceId:a==null?void 0:a.paddle_product_id},...k>0&&C.length>0?[{quantity:k,priceId:(e=C[0])==null?void 0:e.paddle_product_id}]:[]]},J=u.useCallback(De(e=>{h==null||h.Checkout.updateCheckout({...e})},500),[]);return u.useEffect(()=>{!i||U||!o||(E(!0),J({items:P(),discountCode:null}))},[f]),u.useEffect(()=>{!i||U||!o||(E(!0),J({items:P()}))},[o,k,p]),u.useEffect(()=>{Se(e=>{var S;if(((e==null?void 0:e.name)==="checkout.error"||(e==null?void 0:e.type)==="checkout.error")&&Y((e==null?void 0:e.detail)??"Payment failed. Please try again.",{variant:"error"}),(e==null?void 0:e.name)==="checkout.payment.initiated"&&Q(!0),((e==null?void 0:e.name)==="checkout.payment.failed"||(e==null?void 0:e.name)==="checkout.payment.error")&&(Q(!1),R==null||R.track("Checkout Payment Failed",{subscription_name:o==null?void 0:o.subscription_name,subscription_plan_id:o==null?void 0:o.subscription_plan_id,frequency:f,seats:L?p:1})),(e==null?void 0:e.name)==="checkout.completed"){const w=(S=e==null?void 0:e.data)==null?void 0:S.transaction_id;(async()=>{try{await me.post("paddle_billing/sync",{transaction_id:w}),l()}catch(I){console.error("Post-checkout sync failed",I),setTimeout(()=>{l()},3e3),setTimeout(()=>{l()},1e4)}})(),Y("Your subscription has been successfully created",{variant:"success"}),(o==null?void 0:o.ownedBy)==="organization"?B(G.welcomeOrganization):B(G.root+"/")}e.data&&(e.data.totals&&A(e.data),E(!1))})},[o,f,p]),u.useEffect(()=>{!(h&&o&&!i&&j(o))||W||h==null||h.Checkout.open({transactionId:F,customData:{...ze(),user_id:we.db_user_id},settings:{displayMode:"inline",theme:"light",locale:"en",frameTarget:"checkout-container",frameInitialHeight:"450",frameStyle:"width: 100%; min-width: 312px; background-color: transparent; border: none;"},customer:{email:M.email},items:!F&&P()})},[h,o]),!_.isPending&&!j(o)?t(ge,{title:"Subscription to The Hoops Geek",children:r(fe,{sx:{minHeight:800,mt:15},children:[t(Re,{color:"error",children:"This plan is not available"}),t(s,{sx:{mt:3},children:t(Be,{variant:"contained",onClick:ke,children:"Go back"})})]})}):t(ge,{title:"Subscription to The Hoops Geek",children:t(fe,{sx:{minHeight:800,mt:15},children:r(d,{sx:{minHeight:600},direction:{md:"row"},children:[!y&&t(d,{sx:e=>({background:i?e.palette.grey[100]:"transparent",flex:1,px:7,pt:7,pb:{xs:7,md:0}}),children:i&&r(be,{children:[t(s,{sx:{mb:3,fontSize:20,fontWeight:600},children:"Order Summary"}),t(He,{sx:{mb:3},children:r(We,{value:f,onChange:e=>{_e(e.target.value)},row:!0,"aria-labelledby":"demo-row-radio-buttons-group-label",name:"row-radio-buttons-group",children:[t(he,{value:"year",control:t(pe,{sx:{ml:.5,p:.5},color:"info"}),label:r("span",{children:["Pay Yearly",t(Ge,{sx:{ml:.5,mr:2},color:"info",children:"Save 50%"})]})}),t(he,{value:"month",control:t(pe,{sx:{ml:.5,p:.5},color:"info"}),label:"Pay Monthly"})]})}),r(d,{sx:{mt:1,mb:1},direction:"row",children:[t(s,{sx:{flex:1,pr:2},children:o==null?void 0:o.subscription_name}),t(s,{sx:{fontWeight:"600"},children:r(b,{isLoading:x,children:["$",(v=(O=(Z=((i==null?void 0:i.items)??[]).find(e=>e.price_id===(a==null?void 0:a.paddle_product_id)))==null?void 0:Z.totals)==null?void 0:O.subtotal)==null?void 0:v.toFixed(2)]})})]}),(a==null?void 0:a.description)&&t(s,{sx:e=>({color:e.palette.text.secondary,fontSize:12,mt:-.5,mb:2}),children:a==null?void 0:a.description}),L&&r(s,{children:[t($,{sx:{mt:1,mb:1}}),t(d,{sx:{mt:2},direction:"row",children:t(s,{sx:{flex:1,pr:2},children:"Coach seats"})}),r(d,{spacing:1,sx:{mt:1.5},direction:"row",alignItems:"center",children:[t(q,{size:"small",onClick:()=>{z(e=>Math.max(m,(Number(e)||m)-1))},sx:e=>({background:e.palette.grey[5008],fontSize:16,color:"black"}),children:t(T,{icon:"eva:minus-outline"})}),t(xe,{color:"info",value:D,onChange:e=>z(e.target.value),onBlur:()=>z(p),size:"small",sx:{".MuiOutlinedInput-input":{fontSize:14,background:"#fff"},width:60,py:0},slotProps:{htmlInput:{min:m,inputMode:"numeric",pattern:"[0-9]*",sx:{textAlign:"center"}}}}),t(q,{size:"small",onClick:()=>{z(e=>Math.max(m,(Number(e)||m)+1))},sx:e=>({background:e.palette.grey[5008],fontSize:16,color:"black"}),children:t(T,{icon:"eva:plus-outline"})})]}),r(s,{sx:e=>({color:e.palette.text.secondary,fontSize:12,mt:1}),children:[p," coach seats, minimum ",m]})]}),C&&C.map(e=>{var S,w,I;return r(s,{children:[t($,{sx:{mt:1,mb:1}}),r(d,{sx:{mt:2},direction:"row",children:[t(s,{sx:{flex:1,pr:2},children:e.title}),t(s,{sx:{fontWeight:"600"},children:r(b,{isLoading:x,children:["$",((I=(w=(S=((i==null?void 0:i.items)??[]).find(c=>c.price_id===e.paddle_product_id))==null?void 0:S.totals)==null?void 0:w.subtotal)==null?void 0:I.toFixed(2))??0]})})]}),r(d,{spacing:1,sx:{mt:1.5},direction:"row",alignItems:"center",children:[t(q,{size:"small",onClick:()=>{N(c=>Math.max(0,c-1))},sx:c=>({background:c.palette.grey[5008],fontSize:16,color:"black"}),children:t(T,{icon:"eva:minus-outline"})}),t(xe,{color:"info",value:k,onChange:c=>{const ue=parseInt(c.target.value);isNaN(ue)||N(Math.max(0,ue))},size:"small",sx:{".MuiOutlinedInput-input":{fontSize:14,background:"#fff"},width:60,py:0},slotProps:{htmlInput:{min:0,inputMode:"numeric",pattern:"[0-9]*",sx:{textAlign:"center"}}}}),t(q,{size:"small",onClick:()=>{N(c=>Math.max(0,c+1))},sx:c=>({background:c.palette.grey[5008],fontSize:16,color:"black"}),children:t(T,{icon:"eva:plus-outline"})})]}),r(s,{sx:c=>({color:c.palette.text.secondary,fontSize:12,mt:1}),children:["Total: ",((a==null?void 0:a.seats)??4)+k," ","coach seats"]})]},e.paddle_product_id)}),r(d,{justifyContent:"flex-end",sx:{mt:2},children:[t($,{sx:{mb:2,mt:2}}),r(d,{direction:"row",children:[t(s,{sx:{flex:1,pr:2},children:"Subtotal"}),t(s,{sx:{fontWeight:"600"},children:r(b,{isLoading:x,children:["$",(te=(ee=i==null?void 0:i.totals)==null?void 0:ee.subtotal)==null?void 0:te.toFixed(2)]})})]}),((ie=i==null?void 0:i.totals)==null?void 0:ie.discount)>0&&r(d,{sx:{mt:1},direction:"row",children:[t(s,{sx:{flex:1,pr:2},children:"Discount"}),t(s,{sx:{fontWeight:"600"},children:r(b,{isLoading:x,children:["- $",(ne=(oe=i==null?void 0:i.totals)==null?void 0:oe.discount)==null?void 0:ne.toFixed(2)]})})]}),r(d,{sx:{mt:1},direction:"row",children:[t(s,{sx:{flex:1,pr:2},children:"Tax"}),t(s,{sx:{fontWeight:"600"},children:r(b,{isLoading:x,children:["$",(se=(re=i==null?void 0:i.totals)==null?void 0:re.tax)==null?void 0:se.toFixed(2)]})})]}),t($,{sx:{mb:2,mt:2}}),r(d,{direction:"row",children:[t(s,{sx:{flex:1,pr:2},children:"Due Today"}),t(s,{sx:{fontWeight:"600"},children:r(b,{isLoading:x,children:["$",(le=(ae=i==null?void 0:i.totals)==null?void 0:ae.total)==null?void 0:le.toFixed(2)]})})]}),t(d,{direction:"row",children:t(s,{sx:e=>({fontSize:14,flex:1,mt:1,textAlign:"right",color:e.palette.text.secondary}),children:r(b,{isLoading:x,children:["then $",(de=(ce=i==null?void 0:i.recurring_totals)==null?void 0:ce.total)==null?void 0:de.toFixed(2)," ","billed ",f,"ly"]})})})]})]})}),t(s,{sx:{pb:{xs:7,md:0},px:7,pt:7,flex:1},className:"checkout-container"})]})})})}function dt(){const n=ye.c(2);let l;n[0]===Symbol.for("react.memo_cache_sentinel")?(l=t(Ne,{to:"/dashboard/"}),n[0]=l):l=n[0];let i;return n[1]===Symbol.for("react.memo_cache_sentinel")?(i=r(be,{children:[l,t(Ve,{children:t(Je,{})})]}),n[1]=i):i=n[1],i}export{dt as default}; 2//# sourceMappingURL=_auth.dashboard_.checkout-6HdiA0LV.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.