1import{k as W,r as s,l as H,bp as V,j as e,bD as se,bE as re,bM as pe,bN as me,bO as he,B as _,aZ as fe,T as te,e as ce,s as J,t as q,L as G,o as ye,bZ as ge,z as xe,b as be,d as Ne,bU as ae,bX as ve,b_ as je,b$ as we,I as ke,au as Pe,C as Se}from"./index-CtzJrn0d.js";import{I as Ee}from"./input-LQFCpWRr.js";import{L as Ce}from"./label-CGMjD-3b.js";import{C as Me}from"./circle-x-DYOJY8cm.js";/* empty css */import{A as Ie}from"./arrow-left-BrBQnxrk.js";const le="eznity_payment_session",ie="eznity_payment_page_loaded",Q=20;function Re(n){sessionStorage.removeItem(ie),sessionStorage.setItem(le,JSON.stringify(n))}function _e(){sessionStorage.removeItem(le),sessionStorage.removeItem(ie)}function Ae(n){if(n==null)return null;if(typeof n=="number"&&Number.isFinite(n))return n<1e12?n*1e3:n;const t=Number(n);if(Number.isFinite(t)&&String(n).trim()!=="")return t<1e12?t*1e3:t;const a=Date.parse(String(n));return Number.isNaN(a)?null:a}function De(n,t=15){const a=Ae(n.expiry_end_time);if(a!==null){const u=Date.now(),d=a-u;return{expiresAt:new Date(a).toISOString(),expiryMinutes:Math.max(0,Math.ceil(d/6e4))}}const f=t*60*1e3;return{expiresAt:new Date(Date.now()+f).toISOString(),expiryMinutes:t}}const Te=1e4;async function Oe(){return W.pollRazorpayPaymentStatus()}function Le({enabled:n,onTerminalStatus:t}){const[a,f]=s.useState("pending"),[u,d]=s.useState("Initializing payment status checkâ¦"),[p,x]=s.useState(!1),[b,N]=s.useState(null),m=s.useRef(null),y=s.useRef(!1),h=s.useRef(t);s.useEffect(()=>{h.current=t},[t]);const v=s.useCallback(()=>{y.current=!0,m.current!==null&&(window.clearInterval(m.current),m.current=null),x(!1)},[]),E=c=>c==="success"||c==="failed"||c==="cancelled"||c==="expired",j=s.useCallback(async()=>{var c;if(!y.current)try{const g=await Oe();N(null),f(g.status),d(g.message||Ye(g.status)),E(g.status)&&(H.log("[Payment Polling] Terminal status detected:",g.status),v(),(c=h.current)==null||c.call(h,g.status,g.message))}catch(g){H.error("[Payment Polling] API Error:",g)}},[v]);return s.useEffect(()=>{if(n)return y.current=!1,x(!0),f("pending"),d("Waiting for payment confirmationâ¦"),N(null),j(),m.current=window.setInterval(()=>{j()},Te),()=>{v()}},[n,j,v]),{status:a,message:u,isPolling:p,pollError:b,stopPolling:v}}function Ye(n){switch(n){case"success":return"Payment completed successfully.";case"failed":return"Payment failed. Please try again.";case"cancelled":return"Payment was cancelled.";case"expired":return"Payment session expired.";default:return"Processing your paymentâ¦"}}function ze(n){return n instanceof Element?n.closest("[data-radix-dialog-content]")!==null:!1}function Ue(n){s.useEffect(()=>{if(!n)return;const t=document.documentElement,a=document.body,f=window.scrollY,u={htmlOverflow:t.style.overflow,bodyOverflow:a.style.overflow,bodyPosition:a.style.position,bodyTop:a.style.top,bodyWidth:a.style.width,bodyPaddingRight:a.style.paddingRight},d=window.innerWidth-t.clientWidth;t.style.overflow="hidden",a.style.overflow="hidden",a.style.position="fixed",a.style.top=`-${f}px`,a.style.width="100%",d>0&&(a.style.paddingRight=`${d}px`);const p=x=>{ze(x.target)||x.preventDefault()};return document.addEventListener("wheel",p,{passive:!1}),document.addEventListener("touchmove",p,{passive:!1}),()=>{document.removeEventListener("wheel",p),document.removeEventListener("touchmove",p),t.style.overflow=u.htmlOverflow,a.style.overflow=u.bodyOverflow,a.style.position=u.bodyPosition,a.style.top=u.bodyTop,a.style.width=u.bodyWidth,a.style.paddingRight=u.bodyPaddingRight,window.scrollTo(0,f)}},[n])}const Fe=({open:n,status:t,title:a,description:f,onClose:u,closeLabel:d="Go to dashboard"})=>{const p=s.useRef(null),x=s.useRef(null);s.useEffect(()=>{var h;if(!n||!p.current||!x.current)return;const m=typeof window<"u"&&((h=window.matchMedia)==null?void 0:h.call(window,"(prefers-reduced-motion: reduce)").matches),y=V.context(()=>{m||(V.fromTo(x.current,{opacity:0,scale:.92,y:16},{opacity:1,scale:1,y:0,duration:.45,ease:"back.out(1.4)"}),V.fromTo(p.current,{scale:.4,opacity:0,rotation:-20},{scale:1,opacity:1,rotation:0,duration:.55,ease:"back.out(2)",delay:.1}))});return()=>y.revert()},[n,t]);const b=t==="success"?fe:t==="expired"?te:Me,N=t==="success"?"payment-result-icon payment-result-icon--success":t==="expired"?"payment-result-icon payment-result-icon--warning":"payment-result-icon payment-result-icon--error";return e.jsx(se,{open:n,children:e.jsxs(re,{ref:x,className:"payment-result-dialog sm:max-w-md [&>button]:hidden",onPointerDownOutside:m=>m.preventDefault(),onEscapeKeyDown:m=>m.preventDefault(),children:[e.jsxs(pe,{className:"items-center text-center",children:[e.jsx("div",{ref:p,className:N,children:e.jsx(b,{size:40,strokeWidth:2})}),e.jsx(me,{className:"text-xl",children:a}),e.jsx(he,{className:"text-base",children:f})]}),u&&e.jsx("div",{className:"flex justify-center mt-4",children:e.jsx(_,{onClick:u,className:"min-w-[120px]",children:d})})]})})},ee=50,ne=2*Math.PI*ee,Z=120;function We(n){const t=Math.max(0,Math.ceil(n/1e3)),a=Math.floor(t/60),f=t%60;return`${String(a).padStart(2,"0")}
1:${String(f).padStart(2,"0")}`}function Be(n){switch(n){case"success":return{title:"Payment Successful",description:"Your subscription has been updated successfully."};case"expired":return{title:"Payment Session Expired",description:"Your payment session timed out. Please try again."};case"cancelled":return{title:"Payment Cancelled",description:"You cancelled the payment."};default:return{title:"Payment Failed",description:"We could not complete your payment. Please try again."}}}function $e(n){return n==="success"?"Go to dashboard":"Back to plans & try again"}const Ge=({open:n,session:t,onComplete:a})=>{const{refreshUser:f}=ce(),u=s.useRef(null),d=s.useRef(!1),p=s.useRef(!1),[x,b]=s.useState(!1),[N,m]=s.useState(!1),[y,h]=s.useState(null),[v,E]=s.useState(!0),j=v&&y===null;Ue(n||N);const c=s.useMemo(()=>{if(t!=null&&t.expiresAt){const o=Date.parse(t.expiresAt);if(!Number.isNaN(o))return o}return Date.now()+((t==null?void 0:t.expiryMinutes)??Q)*60*1e3},[t==null?void 0:t.expiresAt,t==null?void 0:t.expiryMinutes]),g=s.useMemo(()=>{const o=(t==null?void 0:t.expiryMinutes)??Q,M=c-Date.now();return M>0?M:Math.max(o*60*1e3,1)},[c,t==null?void 0:t.expiryMinutes]),[A,C]=s.useState(()=>Math.max(0,c-Date.now())),R=s.useCallback(()=>{d.current=!1,p.current=!1,b(!1),m(!1),h(null),E(!0),u.current=null},[]);s.useEffect(()=>{n&&t&&(R(),Re(t),C(Math.max(0,c-Date.now())))},[n,t,c,R]);const D=s.useCallback(()=>{if(!(t!=null&&t.checkoutUrl))return;const o=window.open(t.checkoutUrl,"_blank","noopener,noreferrer");if(!o){b(!0);return}u.current=o,b(!1),window.focus()},[t]),B=s.useCallback(()=>{const o=u.current;if(o&&!o.closed)try{o.close()}catch{}},[]),T=s.useCallback(async o=>{if(H.log("[PaymentProcessingModal] handleTerminalStatus called with status:",o),!p.current){if(p.current=!0,E(!1),h(o),B(),_e(),o==="success"){const M=(t==null?void 0:t.orderId)||(t==null?void 0:t.sessionId)||`order_${Date.now()}`,L=(t==null?void 0:t.planName)||"Subscription Plan",F=t!=null&&t.amount?t.amount/100:0,K=(t==null?void 0:t.currency)||"INR";J.trackEvent(q.PURCHASE,{transaction_id:M,plan_name:L,value:F,currency:K}),await f()}m(!0)}},[B,f,t]),{message:k,pollError:z}=Le({enabled:v&&n&&!!t,onTerminalStatus:o=>{T(o)}});if(s.useEffect(()=>{!n||!t||d.current||(d.current=!0,D())},[n,D,t]),s.useEffect(()=>{if(!n||!t)return;const o=()=>{const L=Math.max(0,c-Date.now());C(L),L<=0&&!p.current&&T("expired")};o();const M=window.setInterval(o,1e3);return()=>window.clearInterval(M)},[c,T,n,t]),!t)return null;const r=Math.max(0,Math.min(1,A/g)),P=ne*(1-r),U=y?Be(y):null,O=Z/2;return e.jsxs(e.Fragment,{children:[e.jsx(se,{open:n&&!N,children:e.jsx(re,{className:"payment-processing-dialog [&>button]:hidden",onPointerDownOutside:o=>o.preventDefault(),onEscapeKeyDown:o=>o.preventDefault(),children:e.jsxs("div",{className:"payment-processing-modal-body",children:[e.jsxs("div",{className:"payment-processing-badge",children:[e.jsx(G,{size:13,className:"animate-spin"}),"Payment in progress"]}),e.jsx("h2",{className:"payment-processing-title",children:"Complete your payment"}),e.jsxs("p",{className:"payment-processing-subtitle",children:["Finish checkout in the payment tab for ",e.jsx("strong",{children:t.planName}),". This page updates automatically once confirmed."]}),j&&e.jsx("div",{className:"payment-keep-open-note",children:"Please keep this page open while you complete payment in the other tab."}),e.jsxs("div",{className:"payment-ring-wrap",children:[e.jsxs("svg",{className:"payment-ring-svg",viewBox:`0 0 ${Z} ${Z}`,"aria-hidden":"true",children:[e.jsx("circle",{className:"payment-ring-track",cx:O,cy:O,r:ee}),e.jsx("circle",{className:"payment-ring-progress",cx:O,cy:O,r:ee,strokeDasharray:ne,strokeDashoffset:P})]}),e.jsxs("div",{className:"payment-ring-center",children:[e.jsx(ye,{size:16,className:"text-muted-foreground mb-1"}),e.jsx("span",{className:"payment-timer-value",children:We(A)}),e.jsx("span",{className:"payment-timer-label",children:"remaining"})]})]}),e.jsx("p",{className:"payment-status-message",children:k}),e.jsx("p",{className:"payment-status-hint",children:x?"Your browser blocked the payment tab. Use the button below to open checkout.":"Keep this tab open while you pay in the other window."}),z&&e.jsxs("div",{className:"payment-status-error",children:[e.jsx(te,{size:15}),e.jsx("span",{children:z})]}),e.jsx("div",{className:"payment-tab-actions",children:e.jsxs(_,{type:"button",className:"w-full max-w-[280px]",onClick:D,children:[e.jsx(ge,{size:15}),x?"Open Payment Page":"Reopen Payment Tab"]})})]})})}
1),U&&y&&e.jsx(Fe,{open:N,status:y,title:U.title,description:U.description,closeLabel:$e(y),onClose:async()=>{await f(),a(y)}})]})},$=n=>n/100,qe=()=>{const{planId:n}=xe(),t=be(),{user:a,refreshUser:f}=ce(),{toast:u}=Ne(),d=Number(n),[p,x]=s.useState([]),[b,N]=s.useState(!0),[m,y]=s.useState(null),[h,v]=s.useState(!1),[E,j]=s.useState(""),[c,g]=s.useState(null),[A,C]=s.useState(null),[R,D]=s.useState(!1),[B,T]=s.useState(null),[k,z]=s.useState(!1);s.useEffect(()=>{(async()=>{try{N(!0),y(null);const l=await W.getSubscriptionPlans(),I=(Array.isArray(l==null?void 0:l.plans)?l.plans:[]).filter(w=>!(!w.active||w.is_visible===!1||!w.limits||Object.keys(w.limits).length===0||w.limits.limits&&Object.keys(w.limits.limits).length===0)).sort((w,X)=>w.price-X.price);x(I)}catch(l){console.error("Error fetching subscription plans:",l),y("Failed to load plan details. Please try again later.")}finally{N(!1)}})()},[]);const r=s.useMemo(()=>p.find(i=>i.id===d)??null,[p,d]);s.useEffect(()=>{r&&J.trackEvent(q.BEGIN_CHECKOUT,{plan_name:r.name,price:$(r.price),billing_cycle:ae(r)||void 0})},[r]);const P=s.useMemo(()=>{var l;const i=(l=a==null?void 0:a.active_plan)==null?void 0:l.status;return!!(a!=null&&a.active_plan)&&a.active_plan.price>0&&(i==="active"||i==="success"||i==="cancelled")},[a==null?void 0:a.active_plan]);s.useEffect(()=>{P&&(g(null),j(""),C(null))},[P]);const U=()=>{var l;const i=(l=a==null?void 0:a.active_plan)==null?void 0:l.status;return a!=null&&a.active_plan&&(i==="active"||i==="success"||i==="cancelled")?a.active_plan.id:null};s.useEffect(()=>{if(!(b||m)){if(!Number.isFinite(d)||!r){t("/subscription",{replace:!0});return}if(r.price===0){t("/subscription",{replace:!0});return}if(U()===r.id){t("/subscription",{replace:!0});return}ve(a==null?void 0:a.active_plan,r)&&t("/subscription",{replace:!0})}},[b,m,r,d,a==null?void 0:a.active_plan,t]);const O=async()=>{const i=E.trim();if(!(!i||!r)){D(!0),C(null);try{const l=await W.validateCoupon(i,r.id);g({code:l.code,discountAmount:$(l.discount_amount_minor),finalPrice:$(l.final_amount_minor),description:l.description}),j(l.code)}catch(l){g(null),C(l instanceof Error?l.message:"Invalid or expired promo code.")}finally{D(!1)}}},o=()=>{g(null),j(""),C(null)},M=async()=>{if(!(!r||h||k)){J.trackEvent(q.CHECKOUT_PAYMENT_INITIATED,{plan_name:r.name,price:(c==null?void 0:c.finalPrice)??$(r.price),currency:"INR",promo_code:c==null?void 0:c.code});try{v(!0);const i=P||c==null?void 0:c.code,l=P?await W.changeRazorpaySubscription(r.id):await W.createRazorpaySubscription(r.id,i),{checkout_url:S,action:I,message:w}=l;if(H.log("Checkout URL received from backend:",S),!S){if(I==="downgrade"){u({variant:"success",title:"Plan Changed",description:w||"Your plan has been successfully changed. The new plan will start at the next billing cycle."}),await f(),t("/profile");return}throw new Error("No checkout URL received from server")}const{expiresAt:X,expiryMinutes:de}=De(l,Q);T({checkoutUrl:S,expiresAt:X,planId:r.id,planName:r.name,expiryMinutes:de}),z(!0)}catch(i){let l="Failed to initiate subscription",S="Subscription Error";if(i instanceof Error){const I=i.message.toLowerCase();I.includes("network")||I.includes("fetch")?(S="Network Error",l="Network failure. Please check your connection and try again."):I.includes("subscription id")?(S="Payment Setup Error",l="We could not start your payment session. Please try again or contact support."):I.includes("checkout url")?(S="Payment Setup Error",l="Payment page could not be loaded. Please try again."):l=i.message}u({variant:"destructive",title:S,description:l})}finally{v(!1)}}},L=i=>{z(!1),T(null),t(i==="success"?"/dashboard":"/subscription",{replace:!0})};if(b)return e.jsx("div",{className:"subscription-page checkout-page",children:e.jsxs("div",{className:"pricing-loading",children:[e.jsx(G,{className:"animate-spin",size:28}),e.jsx("p",{children:"Loading checkoutâ¦"})]})});if(m||!r)return e.jsx("div",{className:"subscription-page checkout-page",children:e.jsxs("div",{className:"pricing-error",children:[e.jsx(te,{size:28}),e.jsx("h2",{children:"Checkout unavailable"}),e.jsx("p",{children:m||"Plan not found."}),e.jsx(_,{type:"button",variant:"link",className:"text-grey",onClick:()=>t("/subscription"),children:"Back to plans"})]})});
1const F=je(r.name),K=ae(r)==="yearly",oe=!P&&c?c.finalPrice:r.price,Y=!P&&c!=null,ue=we(r);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"subscription-page checkout-page",children:[e.jsxs("section",{className:"checkout-hero",children:[e.jsx("h1",{children:"You're one step away"}),e.jsxs("p",{children:["Unlock ",e.jsx("strong",{children:r.name})," and start turning your streams into ready-to-post clips â automatically, while you go live."]})]}),e.jsxs("div",{className:"checkout-layout",children:[e.jsx("div",{className:"checkout-sidebar",children:e.jsxs("div",{className:"checkout-order-card",children:[e.jsx("p",{className:"checkout-order-label",children:"Order summary"}),e.jsxs("div",{className:"plan-header",children:[e.jsx("h3",{children:r.name}),e.jsx("p",{className:"plan-desc",children:r==null?void 0:r.description})]}),e.jsxs("div",{className:"price-block",children:[e.jsxs("div",{className:"price-display",children:[Y&&e.jsxs("span",{className:"checkout-price-original",children:["â¹",r.price]}),e.jsx("span",{className:"price-currency",children:"â¹"}),e.jsx("span",{className:"price-amount",children:oe}),e.jsx("span",{className:"price-period",children:K?"/yr":"/mo"})]}),Y&&e.jsxs("p",{className:"checkout-price-savings",children:["Congratulations! You saved â¹",c.discountAmount,"."]})]}),!P&&e.jsxs("div",{className:"checkout-promo-section",children:[e.jsx(Ce,{htmlFor:"promo-code",children:"Have a promo code?"}),e.jsxs("div",{className:"checkout-promo-row",children:[e.jsx(Ee,{id:"promo-code",type:"text",className:"flex-1",placeholder:"Enter code",value:E,onChange:i=>{j(i.target.value),A&&C(null)},disabled:Y||R||h||k,readOnly:Y}),Y?e.jsx(_,{type:"button",variant:"destructive",size:"icon",onClick:o,disabled:h||k,"aria-label":"Remove promo code",children:e.jsx(ke,{size:16})}):e.jsx(_,{type:"button",variant:"secondary",onClick:()=>void O(),disabled:!E.trim()||R||h||k,children:R?e.jsx(G,{className:"h-4 w-4 animate-spin"}):"Apply"})]}),A&&e.jsx("p",{className:"checkout-promo-error",children:A}),Y&&c&&e.jsx("p",{className:"checkout-promo-success",children:"Promo code applied."})]}),e.jsxs("div",{className:"checkout-actions",children:[e.jsx(_,{type:"button",className:"checkout-cta w-full",onClick:()=>void M(),disabled:h||k||R,children:h?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"h-4 w-4 animate-spin"}),"Processing..."]}):"Continue to Checkout"}),e.jsxs(_,{type:"button",variant:"link",className:"text-grey",onClick:()=>t("/subscription"),disabled:h||k,children:[e.jsx(Ie,{className:"h-3.5 w-3.5"}),"Back to plans"]})]}),e.jsx("p",{className:"checkout-trust-note",children:"Secure payment via Razorpay. Cancel anytime â your access continues until the end of your billing period."})]})}),e.jsxs("div",{className:"checkout-details",children:[e.jsx("span",{className:"checkout-plan-badge",children:r.name}),e.jsx("h2",{className:"checkout-details-title",children:F.headline}),e.jsx("p",{className:"checkout-details-headline",children:F.desc}),e.jsxs("p",{className:"checkout-details-tagline",children:[e.jsx(Pe,{className:"inline h-3.5 w-3.5 mr-1"}),F.tagline]}),e.jsx("p",{className:"checkout-features-title",children:"What you get"}),e.jsx("ul",{className:"checkout-features-list",children:ue.map(i=>e.jsxs("li",{className:"checkout-feature-item",children:[e.jsx(Se,{className:"checkout-feature-icon",size:16}),e.jsx("span",{className:"checkout-feature-label",children:i.label}),e.jsx("span",{className:"checkout-feature-value",children:i.value})]},i.label))})]})]})]}),e.jsx(Ge,{open:k,session:B,onComplete:L})]})};export{qe 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.