import{_ as e,a as t,b as n,h as r,i,s as a,v as o}from"./i18n-DfIivedY.js";import{At as s,Dt as c,s as l}from"./app-BUWZBqJJ.js";import{t as u}from"./card-CTKhq4f5.js";var d=e(),f=n(o(),1),p=t(),m=`https://checkout.razorpay.com/v1/checkout.js`;function h(e){let t=(0,d.c)(59),{razorpay_key_id:n,subscription_id:o,plan:h,customer:g,success_url:_,cancel_url:v}=e,{t:y}=i(),b=s(),x;t[0]!==b.site_title||t[1]!==y?(x=b.site_title||y(`Sales AI`),t[0]=b.site_title,t[1]=y,t[2]=x):x=t[2];let S=x,[C,w]=(0,f.useState)(null),T=(0,f.useRef)(!1),E,D;t[3]!==S||t[4]!==v||t[5]!==g.email||t[6]!==g.name||t[7]!==h.name||t[8]!==n||t[9]!==o||t[10]!==_||t[11]!==y?(E=()=>{if(T.current)return;let e=()=>{if(T.current||!window.Razorpay)return;T.current=!0;let e=new window.Razorpay({key:n,subscription_id:o,name:S,description:y(`:name subscription`,{name:h.name}),prefill:{name:g.name,email:g.email},theme:{color:`#111827`},handler:()=>{r.visit(_)},modal:{ondismiss:()=>{r.visit(v)}}});e.on(`payment.failed`,()=>{r.visit(v)}),e.open()};if(window.Razorpay){e();return}let t=document.querySelector(`script[src="${m}"]`);if(t)return t.addEventListener(`load`,e),t.addEventListener(`error`,()=>w(y(`Could not load Razorpay Checkout.`))),()=>{t.removeEventListener(`load`,e)};let i=document.createElement(`script`);i.src=m,i.async=!0,i.onload=e,i.onerror=()=>w(y(`Could not load Razorpay Checkout.`)),document.body.appendChild(i)},D=[n,o,h.name,g.name,g.email,_,v,S,y],t[3]=S,t[4]=v,t[5]=g.email,t[6]=g.name,t[7]=h.name,t[8]=n,t[9]=o,t[10]=_,t[11]=y,t[12]=E,t[13]=D):(E=t[12],D=t[13]),(0,f.useEffect)(E,D);let O;t[14]===y?O=t[15]:(O=y(`Billing`),t[14]=y,t[15]=O);let k;t[16]===O?k=t[17]:(k=[{title:O,href:`/app/billing`}],t[16]=O,t[17]=k);let A;t[18]===y?A=t[19]:(A=y(`Razorpay checkout`),t[18]=y,t[19]=A);let j;t[20]===A?j=t[21]:(j=(0,p.jsx)(a,{title:A}),t[20]=A,t[21]=j);let M;t[22]===y?M=t[23]:(M=y(`Opening Razorpay…`),t[22]=y,t[23]=M);let N;t[24]===M?N=t[25]:(N=(0,p.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:M}),t[24]=M,t[25]=N);let P;t[26]===y?P=t[27]:(P=y(`Subscribing to`),t[26]=y,t[27]=P);let F;t[28]===h.name?F=t[29]:(F=(0,p.jsx)(`span`,{className:`font-medium`,children:h.name}),t[28]=h.name,t[29]=F);let I;t[30]===y?I=t[31]:(I=y(`for`),t[30]=y,t[31]=I);let L=h.currency,R=h.price_cents/100,z;t[32]===R?z=t[33]:(z=R.toFixed(2),t[32]=R,t[33]=z);let B;t[34]===y?B=t[35]:(B=y(`/ month.`),t[34]=y,t[35]=B);let V;t[36]!==h.currency||t[37]!==P||t[38]!==F||t[39]!==I||t[40]!==z||t[41]!==B?(V=(0,p.jsxs)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:[P,` `,F,` `,I,` `,L,` `,z,` `,B]}),t[36]=h.currency,t[37]=P,t[38]=F,t[39]=I,t[40]=z,t[41]=B,t[42]=V):V=t[42];let H;t[43]===C?H=t[44]:(H=C&&(0,p.jsx)(`p`,{className:`mt-4 text-sm text-rose-600`,children:C}),t[43]=C,t[44]=H);let U;t[45]===y?U=t[46]:(U=y(`Cancel`),t[45]=y,t[46]=U);let W;t[47]!==v||t[48]!==U?(W=(0,p.jsx)(`div`,{className:`mt-6 flex justify-center gap-2`,children:(0,p.jsx)(c,{asChild:!0,variant:`outline`,children:(0,p.jsx)(`a`,{href:v,children:U})})}),t[47]=v,t[48]=U,t[49]=W):W=t[49];let G;t[50]!==V||t[51]!==H||t[52]!==W||t[53]!==N?(G=(0,p.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:(0,p.jsxs)(u,{className:`w-full max-w-md p-6 text-center`,children:[N,V,H,W]})}),t[50]=V,t[51]=H,t[52]=W,t[53]=N,t[54]=G):G=t[54];let K;return t[55]!==G||t[56]!==k||t[57]!==j?(K=(0,p.jsxs)(l,{breadcrumbs:k,children:[j,G]}),t[55]=G,t[56]=k,t[57]=j,t[58]=K):K=t[58],K}export{h as default};