vendor: 3,794 bytes, line 1
1import{j as e}from"./vendor-query-REUEbryQ.js";import{r as s,i as a,L as r}from"./vendor-react-tIoPkRwd.js";import{f as t,g as n,e as o,s as i,L as l,B as c,T as d,u,C as m}from"./index--0ud_HHy.js";import{C as p,b as h,c as x,d as f,a as g}from"./card-DatLY8HA.js";import{A as j,b,c as v,d as y,e as w,f as N}from"./alert-dialog-BqZuNkPB.js";import{g as k,u as _,P as C,c as S,i as A,a0 as R,$ as P,s as E,t as T,h as L,v as M,I}from"./vendor-ui-BVtOlGvj.js";import{C as Y}from"./circle-DNRAjJQk.js";import{L as O}from"./label-BLxROBsa.js";import{T as q}from"./textarea-C1OSlJeR.js";import{MagicLinkLogin as F}from"./MagicLinkLogin-pB4UGT7Y.js";import{C as $}from"./credit-card-CYKdopSW.js";import{A as B}from"./arrow-left-DdlyX7wK.js";import{E as D}from"./external-link-D4r3JqVx.js";import{G as V}from"./gift-CiTZqr8X.js";import{C as G}from"./circle-x-DaLvDtfU.js";import{C as U}from"./clock-Bhs4QKh8.js";import"./vendor-supabase-BcbvpzCe.js";import"./use-mobile-B4hqzuWL.js";import"./mail-dvoj9BP8.js";var z="Radio",[K,H]=k(z),[W,J]=K(z),X=s.forwardRef((a,r)=>{const{__scopeRadio:t,name:n,checked:o=!1,required:i,disabled:l,value:c="on",onCheck:d,form:u,...m}=a,[p,h]=s.useState(null),x=_(r,e=>h(e)),f=s.useRef(!1),g=!p||u||!!p.closest("form");return e.jsxs(W,{scope:t,checked:o,disabled:l,children:[e.jsx(C.button,{type:"button",role:"radio","aria-checked":o,"data-state":se(o),"data-disabled":l?"":void 0,disabled:l,value:c,...m,ref:x,onClick:S(a.onClick,e=>{o||null==d||d(),g&&(f.current=e.isPropagationStopped(),f.current||e.stopPropagation())})}),g&&e.jsx(ee,{control:p,bubbles:!f.current,name:n,value:c,checked:o,required:i,disabled:l,form:u,style:{transform:"translateX(-100%)"}})]})});X.displayName=z;var Q="RadioIndicator",Z=s.forwardRef((s,a)=>{const{__scopeRadio:r,forceMount:t,...n}=s,o=J(Q,r);return e.jsx(A,{present:t||o.checked,children:e.jsx(C.span,{"data-state":se(o.checked),"data-disabled":o.disabled?"":void 0,...n,ref:a})})});Z.displayName=Q;var ee=s.forwardRef(({__scopeRadio:a,control:r,checked:t,bubbles:n=!0,...o},i)=>{const l=s.useRef(null),c=_(l,i),d=R(t),u=P(r);return s.useEffect(()=>{const e=l.current;if(!e)return;const s=window.HTMLInputElement.prototype,a=Object.getOwnPropertyDescriptor(s,"checked").set;if(d!==t&&a){const s=new Event("click",{bubbles:n});a.call(e,t),e.dispatchEvent(s)}},[d,t,n]),e.jsx(C.input,{type:"radio","aria-hidden":!0,defaultChecked:t,...o,tabIndex:-1,ref:c,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});function se(e){return e?"checked":"unchecked"}ee.displayName="RadioBubbleInput";var ae=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],re="RadioGroup",[te,ne]=k(re,[E,H]),oe=E(),ie=H(),[le,ce]=te(re),de=s.forwardRef((s,a)=>{const{__scopeRadioGroup:r,name:t,defaultValue:n,value:o,required:i=!1,disabled:l=!1,orientation:c,dir:d,loop:u=!0,onValueChange:m,...p}=s,h=oe(r),x=T(d),[f,g]=L({prop:o,defaultProp:n??null,onChange:m,caller:re});return e.jsx(le,{scope:r,name:t,required:i,disabled:l,value:f,onValueChange:g,children:e.jsx(M,{asChild:!0,...h,orientation:c,dir:x,loop:u,children:e.jsx(C.div,{role:"radiogroup","aria-required":i,"aria-orientation":c,"data-disabled":l?"":void 0,dir:x,...p,ref:a})})})});de.displayName=re;var ue="RadioGroupItem",me=s.forwardRef((a,r)=>{const{__scopeRadioGroup:t,disabled:n,...o}=a,i=ce(ue,t),l=i.disabled||n,c=oe(t),d=ie(t),u=s.useRef(null),m=_(r,u),p=i.value===o.value,h=s.useRef(!1);return s.useEffect(()=>{const e=e=>{ae.includes(e.key)&&(h.current=!0)},s=()=>h.current=!1;return document.addEventListener("keydown",e),document.addEventListener("keyup",s),()=>{document.removeEventListener("keydown",e),document.removeEventListener("keyup",s)}},[]),e.jsx(I,{asChild:!0,...c,focusable:!l,active:p,children:e.jsx(X,{disabled:l,required:i.required,
1checked:p,...d,...o,name:i.name,ref:m,onCheck:()=>i.onValueChange(o.value),onKeyDown:S(e=>{"Enter"===e.key&&e.preventDefault()}),onFocus:S(o.onFocus,()=>{var e;h.current&&(null==(e=u.current)||e.click())})})})});me.displayName=ue;var pe=s.forwardRef((s,a)=>{const{__scopeRadioGroup:r,...t}=s,n=ie(r);return e.jsx(Z,{...n,...t,ref:a})});pe.displayName="RadioGroupIndicator";var he=de,xe=me,fe=pe;const ge=s.forwardRef(({className:s,...a},r)=>e.jsx(he,{className:t("grid gap-2",s),...a,ref:r}));ge.displayName=he.displayName;const je=s.forwardRef(({className:s,...a},r)=>e.jsx(xe,{ref:r,className:t("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),...a,children:e.jsx(fe,{className:"flex items-center justify-center",children:e.jsx(Y,{className:"h-2.5 w-2.5 fill-current text-current"})})}));je.displayName=xe.displayName;const be="https://wfpeajmdojcjqyrsnxbk.supabase.co",ve=[{value:"too_pricey",label:"Too expensive"},{value:"more_sounds",label:"Need more/different sounds"},{value:"more_courses",label:"Need more courses"},{value:"more_project_files",label:"Need more project files"},{value:"not_using",label:"I'm not using it enough"},{value:"other",label:"Other"}],ye=()=>{const{isLoggedIn:t,isSubscribed:k,subscriptionDetails:_,isLoading:C,login:S,sendMagicLink:A,showLoginModal:R,setShowLoginModal:P,refreshSubscription:E}=n(),{openSubscriptionModal:T}=o(),[L,M]=a(),[I,Y]=s.useState(null),[z,K]=s.useState(!0),[H,W]=s.useState(!1),[J,X]=s.useState(!1),[Q,Z]=s.useState(!1),[ee,se]=s.useState("closed"),[ae,re]=s.useState(""),[te,ne]=s.useState(""),oe=s.useCallback(async()=>{try{const{data:{session:e}}=await i.auth.getSession();if(!(null==e?void 0:e.access_token))return void K(!1);const s=await fetch(`${be}/functions/v1/polar-auth/get-billing-info`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.access_token}`}});if(s.ok){const e=await s.json();Y(e)}}catch(e){}finally{K(!1)}},[]);s.useEffect(()=>{t?oe():K(!1)},[t,oe]),s.useEffect(()=>{const e=L.get("checkout"),s=L.get("session_id");"success"!==e||!s||t||C||sessionStorage.setItem("pending_checkout_session",s)},[L,t,C]),s.useEffect(()=>{const e=L.get("checkout");let s=L.get("session_id");if(!s&&t){const e=sessionStorage.getItem("pending_checkout_session");e&&(s=e,sessionStorage.removeItem("pending_checkout_session"))}if(!t||!s&&"success"!==e||H)return;if(!s)return;let a=!1;return(async()=>{W(!0);try{const{data:{session:e}}=await i.auth.getSession();if(!(null==e?void 0:e.access_token))return;const r=await fetch(`${be}/functions/v1/polar-auth/confirm-checkout`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.access_token}`},body:JSON.stringify({sessionId:s})}),t=await r.json().catch(()=>({}));if(!r.ok)throw new Error((null==t?void 0:t.error)||"Failed to confirm checkout");(null==t?void 0:t.recovered)?(await Promise.all([E(),oe()]),a||u.success("Your Music-Prod+ access is now active.")):(a||u.info("Your subscription is being activated. It may take a minute."),setTimeout(async()=>{a||await Promise.all([E(),oe()])},1e4))}catch(e){}finally{if(!a){const e=new URLSearchParams(L);e.delete("checkout"),e.delete("session_id"),M(e,{replace:!0}),W(!1)}}})(),()=>{a=!0}},[t,L,M,E,oe,H]);const ie=e=>e?new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"N/A";if(C||z)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(l,{className:"w-8 h-8 animate-spin text-primary"})});if(!t)return e.jsxs("div",{className:"min-h-screen bg-background flex items-center justify-center",children:[e.jsxs(p,{className:"max-w-md w-full mx-4",children:[e.jsxs(h,{className:"text-center",children:[e.jsx($,{className:"w-12 h-12 text-muted-foreground mx-auto mb-2"}),e.jsx(x,{children:"Login Required"}),e.jsx(f,{children:"Please log in to view your subscription details."})]}),e.jsxs(g,{className:"flex flex-col gap-4",children:[e.jsx(c,{onClick:S,className:"w-full",children:"Login"}),e.jsx(r,{to:"/",className:"text-center text-sm text-muted-foreground hover:text-foreground",children:"â Back to Samples"})]})]}),e.jsx(F,{open:R,onOpenChange:P,onSendMagicLink:A})]});const le=(null==I?void 0:I.status)||(null==_?void 0:_.status)||"none",ce=(null==I?void 0:I.isSubscribed)??k,de=(e=>{switch(e){case"active":return{icon:m,color:"text-success",bg:"bg-success/20",label:"Active"};case"cancelled":return{icon:U,color:"text-warning",bg:"bg-warning/20",label:"Cancelled"};case"expired":return{icon:G,color:"text-destructive",bg:"bg-destructive/20",label:"Expired"};case"on_trial":case"courtesy_trial":return{icon:U,color:"text-primary",bg:"bg-primary/20",label:"Trial"};case"expired_trial":return{icon:G,color:"text-destructive",bg:"bg-destructive/20",label:"Trial Ended"};case"paused":return{icon:U,color:"text-muted-foreground",bg:"bg-muted",label:"Paused"};default:return{icon:G,color:"text-muted-foreground",bg:"bg-muted",label:"No Subscription"}}})(le),ue=de.icon,me=ce||"cancelled"===le&&(null==I?void 0:I.endsAt)&&new Date(I.endsAt)>new Date;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border bg-card/50 backdrop-blur-sm sticky top-0 z-10",children:e.jsx("div",{className:"container mx-auto px-4 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(r,{to:"/",className:"flex items-center gap-2 text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(B,{className:"w-4 h-4"}),"Back to Samples"]}),e.jsx("h1",{className:"text-lg font-semibold",children:"Billing"})]})})}),e.jsxs("main",{className:"container mx-auto px-4 py-8 max-w-2xl",children:[e.jsxs(p,{children:[e.jsxs(h,{children:[e.jsxs(x,{className:"flex items-center gap-2",children:[e.jsx($,{className:"w-5 h-5 text-primary"}),"My Subscription"]}),e.jsx(f,{children:"Manage your Music-Prod+ membership"})]}),e.jsxs(g,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-secondary/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Status"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("div",{className:`p-1 rounded-full ${de.bg}`,children:e.jsx(ue,{className:`w-4 h-4 ${de.color}`})}),e.jsx("span",{className:"font-medium",children:de.label})]})]}),me&&e.jsxs("span",{className:"tag-pill-success",children:[e.jsx("span",{className:"w-1.5 h-1.5 bg-success rounded-full"}),"ACCESS ACTIVE"]})]}),(null==I?void 0:I.productName)&&e.jsxs("div",{className:"p-4 rounded-lg bg-secondary/50",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plan"}
1),e.jsx("p",{className:"font-medium mt-1",children:I.productName})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[(null==I?void 0:I.discount)&&e.jsxs("div",{className:"p-4 rounded-lg bg-primary/10 border border-primary/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Coupon Applied"}),e.jsx("p",{className:"font-medium mt-1",children:I.discount.name}),I.discount.code&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Code: ",e.jsx("span",{className:"font-mono text-foreground",children:I.discount.code}),"repeating"===I.discount.duration&&" ⢠Repeating discount","once"===I.discount.duration&&" ⢠One-time discount","forever"===I.discount.duration&&" ⢠Lifetime discount"]})]}),("on_trial"===le||"courtesy_trial"===le)&&e.jsxs(e.Fragment,{children:[((null==I?void 0:I.trialStart)||(null==I?void 0:I.startedAt))&&e.jsxs("div",{className:"p-4 rounded-lg bg-secondary/50",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Trial Started"}),e.jsx("p",{className:"font-medium mt-1",children:ie(I.trialStart||I.startedAt)})]}),((null==I?void 0:I.trialEnd)||(null==I?void 0:I.renewsAt))&&e.jsxs("div",{className:"p-4 rounded-lg bg-warning/10 border border-warning/20",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Trial Ends & First Charge"}),e.jsx("p",{className:"font-medium mt-1",children:ie(I.trialEnd||I.renewsAt)}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Your card will be charged on this date. Cancel before to avoid being billed."})]})]}),"cancelled"===le&&(null==I?void 0:I.endsAt)&&e.jsxs("div",{className:"p-4 rounded-lg bg-secondary/50",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Access Until"}),e.jsx("p",{className:"font-medium mt-1",children:ie(I.endsAt)}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Your subscription has been cancelled but you have access until this date."})]}),"active"===le&&(null==I?void 0:I.renewsAt)&&e.jsxs("div",{className:"p-4 rounded-lg bg-secondary/50",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Next Renewal"}),e.jsx("p",{className:"font-medium mt-1",children:ie(I.renewsAt)})]})]}),e.jsxs("div",{className:"space-y-3 pt-4 border-t border-border",children:[(null==I?void 0:I.customerPortalUrl)&&e.jsx(c,{variant:"outline",className:"w-full",asChild:!0,children:e.jsxs("a",{href:I.customerPortalUrl,target:"_blank",rel:"noopener noreferrer",children:[e.jsx($,{className:"w-4 h-4 mr-2"}),"Manage Subscription",e.jsx(D,{className:"w-3 h-3 ml-2"})]})}),("active"===le||"on_trial"===le||"courtesy_trial"===le)&&e.jsx(c,{variant:"ghost",className:"w-full text-destructive hover:text-destructive hover:bg-destructive/10",onClick:async()=>{if("on_trial"!==(null==I?void 0:I.status)&&"courtesy_trial"!==(null==I?void 0:I.status))try{const{data:{session:e}}=await i.auth.getSession();if(!(null==e?void 0:e.access_token))return void se("reason");const{data:s}=await i.from("user_subscriptions").select("retention_used").eq("user_id",e.user.id).single();(null==s?void 0:s.retention_used)?se("reason"):se("retention")}catch{se("retention")}else se("confirm")},children:"on_trial"===le||"courtesy_trial"===le?"Cancel Trial":"Cancel Subscription"}),!ce&&"cancelled"!==le&&e.jsx(c,{className:"w-full",onClick:T,children:"Subscribe to Music-Prod+"})]})]})]}),e.jsx(j,{open:"retention"===ee,onOpenChange:()=>{},children:e.jsxs(b,{children:[e.jsxs(v,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(V,{className:"w-5 h-5 text-primary"}),"Wait â how about one more month on us?"]}),e.jsxs(w,{className:"space-y-3",children:[e.jsxs("span",{className:"block",children:["We'd love for you to stay! As a one-time offer, we'll give you ",e.jsx("strong",{className:"text-foreground",children:"one full month completely free"})," â no charge at all."]}),e.jsx("span",{className:"block",children:"After the free month, your regular plan continues. You can still cancel anytime."})]})]}),e.jsxs(N,{className:"flex-col sm:flex-row gap-2",children:[e.jsx(c,{variant:"outline",onClick:()=>{se("reason")},disabled:Q,children:"No thanks, cancel anyway"}),e.jsx(c,{onClick:async()=>{Z(!0);try{const{data:{session:e}}=await i.auth.getSession();if(!(null==e?void 0:e.access_token))return void u.error("Please log in to manage your subscription");const s=await fetch(`${be}/functions/v1/polar-auth/retain-subscription`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.access_token}`}}),a=await s.json();s.ok&&a.url?(u.success("Great! Redirecting you to confirm your free month..."),window.location.href=a.url):"retention_already_used"===a.error?(u.info("You've already used your one-time free month offer."),se("reason")):(u.error(a.error||"Something went wrong"),se("reason"))}catch(e){u.error("Something went wrong. You can still cancel normally."),se("reason")}finally{Z(!1)}},disabled:Q,className:"gap-2",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(l,{className:"w-4 h-4 animate-spin"}),"Setting up..."]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4"}),"Yes, give me a free month!"]})})]})]})}),e.jsx(j,{open:"reason"===ee,onOpenChange:()=>{},children:e.jsxs(b,{children:[e.jsxs(v,{children:[e.jsx(y,{children:"Before you go â what could we improve?"}),e.jsx(w,{children:"Your feedback helps us make Music-Prod+ better for everyone."})]}),e.jsx(ge,{value:ae,onValueChange:re,className:"space-y-3 py-2",children:ve.map(s=>e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(je,{value:s.value,id:s.value}),e.jsx(O,{htmlFor:s.value,className:"cursor-pointer text-sm",children:s.label})]},s.value))}),"other"===ae&&e.jsx(q,{placeholder:"Tell us more (optional)...",value:te,onChange:e=>ne(e.target.value),className:"mt-2",rows:3}),e.jsxs(N,{children:[e.jsx(c,{variant:"outline",onClick:()=>{se("closed"),re(""),ne("")},children:"Never mind, keep my plan"}),e.jsx(c,{onClick:()=>{ae?se("confirm"):u.error("Please select a reason before continuing.")},disabled:!ae,variant:"destructive",children:"Continue to cancel"})]})]})}),e.jsx(j,{open:"confirm"===ee,onOpenChange:()=>{},children:e.jsxs(b,{children:[e.jsxs(v,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(d,{className:"w-5 h-5 text-warning"}),"on_trial"===le||"courtesy_trial"===le?"Cancel Trial?":"Cancel Subscription?"]}),e.jsx(w,{asChild:!0,children:"on_trial"===le||"courtesy_trial"===le?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"font-medium text-destructive",children:"Heads up: cancelling your free trial revokes your Music-Prod+ access immediately."}),e.jsx("p",{children:"You will lose access to all Music-Prod+ features right now, including:"}),e.jsxs("ul",{className:"list-disc pl-5 space-y-1 text-sm",children:[e.jsx("li",{children:"All sample packs, preset packs and MIDI packs"}),e.jsx("li",{children:"Every course, tutorial and Music-Prod+ tool"}),e.jsx("li",{children:"The VYRE plugin and expansion packs"})]}),e.jsx("p",{className:"text-sm",children:"You won't be charged, but your trial cannot be resumed â you'd need to start a new subscription to regain access."})]}):e.jsx("span",{children:"Are you sure you want to cancel your subscription? You'll still have access until your current billing period ends."})})]}),e.jsxs(N,{children:[e.jsx(c,{variant:"outline",disabled:J,onClick:()=>se("closed"),children:"on_trial"===le||"courtesy_trial"===le?"Keep Trial":"Keep Subscription"}),e.jsx(c,{onClick:async()=>{X(!0);try{const{data:{session:s}}=await i.auth.getSession();if(!(null==s?void 0:s.access_token))return void u.error("Please log in to manage your subscription");try{await i.from("cancellation_reasons").insert({user_id:s.user.id,reason:ae,detail:te||null,subscription_status:(null==I?void 0:I.status)||null})}catch(e){}const a=await fetch(`${be}/functions/v1/polar-auth/cancel-subscription`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`}});if(a.ok){const e=await a.json();e.immediate?(u.success("Trial cancelled. Your access has been revoked immediately."),Y(e=>e?{...e,isSubscribed:!1,status:"none",endsAt:null}:null)):(u.success("Subscription cancelled. You'll have access until your billing period ends."),Y(s=>s?{...s,status:"cancelled",endsAt:e.endsAt}:null))}else{const e=await a.json();u.error(e.error||"Failed to cancel subscription")}}catch(s){u.error("Failed to cancel subscription")}finally{X(!1),se("closed"),re(""),ne("")}},disabled:J,variant:"destructive",children:J?e.jsxs(e.Fragment,{children:[e.jsx(l,{className:"w-4 h-4 mr-2 animate-spin"}),"Cancelling..."]}):"Yes, Cancel"})]})]})})]})]})};export{ye as default};
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.