1import{J as te,r as t,p as e,a_ as D,ak as pe,a0 as de,a1 as Ie,T as W,B as K,aj as ae,ag as be,x as H,y as V,bj as ue,L as G,b2 as Qe,aI as He,D as Ke,q as xe,fE as De,V as Ze,fF as Je,aV as Xe,aW as et}from"./index-C9IH3k-2.js";import{A as Fe}from"./Add3rdPartyScript-CynHdFNV.js";import{C as Ee}from"./CustomerPhoneNumberSelect-BI8Hs9hY.js";import{I as q,N as Pe,T as le,W as F,ac as Me,S as tt,aV as nt,K as Ue}from"./TemplateUtil-D1DzmWLm.js";import{g as st}from"./planFeatureItemPriceApi-CNS5-Qqw.js";import{X as k,Y as ce,Z as at,V as lt,i as rt,_ as ot}from"./MainApp-BoiAvjMg.js";import{A as ee}from"./Wrapper-ChjuDa3w.js";import{F as it}from"./Table-isZ0WXp4.js";import{D as ct,Q as z,s as je,A as We,C as dt}from"./CurrentPlanCard-DU9FiSjt.js";import{u as me}from"./useGstRate-D2b2dHB0.js";import{u as Te,B as Se,R as ut}from"./ResellerSubscription-Bv6W1EmT.js";import{P as ve}from"./PaymentResultModal-CDGC6Tfj.js";import{R as pt}from"./ArrowUpOutlined-BhfGhE4E.js";import{R as mt}from"./AppstoreAddOutlined-DUgGbAsx.js";import{R as yt}from"./SyncOutlined-D8Vo-rc6.js";import"./HelperMethods-C-ewwU_x.js";import"./index-BOwvFOZJ.js";import"./Pagination-D1z-xPUv.js";import"./HolderOutlined-YOHjCGKZ.js";import"./InfoCircleOutlined-B7sKwm1k.js";import"./index-8jSYgZzf.js";import"./razorpayCheckoutMessages-BU1kUeUH.js";import"./index-BwbTZq_x.js";const{Text:he}=W,{TextArea:ht}=be,gt=n=>{const{token:o}=te.useToken(),{selectedCustomer:g}=n,[l,m]=t.useState(null),[P,T]=t.useState([]),[A,p]=t.useState(""),[j,r]=t.useState(!1),[S,d]=t.useState(!1),[x,b]=t.useState(!1),C=g?.id||null;t.useEffect(()=>{if(!C){T([]);return}let i=!1;return(async()=>{b(!0);try{const E=await H(`/api/v1/payment/plans?resellerId=${C}`);i||T(E?.data||[])}catch(E){i||T([]),console.error("Error fetching plans:",E)}finally{i||b(!1)}})(),()=>{i=!0}},[C]);const s=i=>{m(i),r(!0)},u=async()=>{if(!l)return;const i={resellerId:C,planId:l?.id,comment:A};d(!0);try{await V("/api/v1/admin/applyPlan",i),ue.success({title:"Plan Applied",description:"The plan has been successfully applied."}),r(!1),m(null),p("")}catch(N){console.log("Error applying plan:",N),ue.error({title:"Error",description:"There was an issue applying the plan."})}finally{d(!1)}};return C?x?e.jsx("div",{style:{padding:40,textAlign:"center"},children:e.jsx(pe,{size:"large"})}):P.length?e.jsxs("div",{style:{padding:"20px",background:o.colorBgLayout},children:[e.jsx(de,{gutter:[24,24],justify:"center",children:e.jsx(de,{gutter:[24,24],justify:"center",children:P.map(i=>e.jsx(Ie,{xs:24,sm:12,md:8,lg:7,children:e.jsxs(q,{title:i.displayName,variant:"borderless",style:{textAlign:"center",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",padding:"12px 8px",minHeight:"600px",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{children:[e.jsx(he,{strong:!0,style:{fontSize:"24px",color:"#1890ff"},children:i.priceShortText}),e.jsx(K,{type:"primary",size:"large",shape:"round",block:!0,style:{marginTop:"24px",marginBottom:"24px",fontWeight:"bold"},onClick:()=>s(i),children:"Activate Plan"}),e.jsx(he,{style:{whiteSpace:"pre-wrap"},children:i.description})]}),e.jsx("div",{style:{marginTop:"auto"},children:e.jsxs("ul",{style:{textAlign:"left",fontSize:"14px",color:"#8c8c8c",listStyleType:"none",paddingLeft:0,marginBottom:0},children:[e.jsxs("li",{children:["Validity: ",i.validityDays," days"]}),e.jsxs("li",{children:["Total Amount (Incl. GST): â¹",i.totalAmount]})]})})]})},i.id))})}),l&&e.jsxs(Pe,{title:"Confirm Plan Activation",open:j,onCancel:()=>r(!1),onOk:u,confirmLoading:S,okText:"Apply Plan",cancelText:"Cancel",children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx(he,{strong:!0,children:"Plan Name:"})," ",e.jsx("span",{children:l.displayName})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx(he,{strong:!0,children:"Amount:"})," ",e.jsxs("span",{children:["â¹",l.totalAmount]})]}),e.jsx(ae.Item,{label:"Add Comment",children:e.jsx(ht,{rows:4,placeholder:"Enter a comment for this plan...",value:A,onChange:i=>p(i.target.value)})})]})]}):e.jsx("div",{style:{padding:20},children:e.jsx(D,{description:"No plans available for this reseller",image:D.PRESENTED_IMAGE_SIMPLE})}):e.jsx("div",{style:{padding:20},children:e.jsx(D,{description:"Select a reseller to see the plans available for it",image:D.PRESENTED_IMAGE_SIMPLE})})},{Text:ie,Title:xt}=W,{TextArea:ft}=be,jt=n=>!!n?.name&&n.type==="NEW"&&(n.tier==="LIFETIME"||/lifetime/i.test(n.name)),bt=()=>{const[n,o]=t.useState(null),[g,l]=t.useState([]),[m,P]=t.useState(!0),[T,A]=t.useState(!1),[p,j]=t.useState([]),[r,S]=t.useState(!1),[d,x]=t.useState(!1),[b,C]=t.useState(0),[s,u]=t.useState(null),[i,N]=t.useState(!1),[E]=ae.useForm(),L=n?.id||null;t.useEffect(()=>{let f=!1;return(async()=>{P(!0),A(!1);try{const O=await st();if(O?.status!==200)throw new Error("Plan catalogue unavailable");const Z=(O?.data||[]).filter(jt).sort((J,Q)=>(J.displayOrder||0)-(Q.displayOrder||0));f||l(Z)}catch{f||(l([]),A(!0))}finally{f||P(!1)}})(),()=>{f=!0}},[]),t.useEffect(()=>{if(j([]),x(!1),!L)return;let f=!1;return(async()=>{S(!0);try{const O=await H(`/api/v1/admin/customer/${L}`);if(O?.status!==200)throw new Error("Customer numbers unavailable");f||j(O?.data?.wabaTokens||[])}catch{f||(j([]),x(!0))}finally{f||S(!1)}})(),()=>{f=!0}},[L,b]);const v=t.useMemo(()=>new Set(g.map(f=>f.name)),[g]),y=f=>v.has(f?.phoneFeature?.planSlug),R=!m&&!T,I=p.filter(y),a=I.length,c=[...new Set(I.map(f=>f.phoneFeature.planSlug))],U=c[0],B=g.find(f=>f.name===U),Y=a>0&&(a<p.length||c.length>1);t.useEffect(()=>{s&&(E.resetFields(),E.setFieldsValue({monthlyCredits:s.walletPoints}))},[s,E]);const re=[{title:"Number",key:"number",render:(f,_)=>_.displayPhoneNumber||_.phoneNumberId},{title:"Current plan",key:"plan",render:(f,_)=>_.phoneFeature?.planName||e.jsx(ie,{type:"secondary",children:"No plan"})},{title:"Entitlements",key:"entitlements",render:(f,_)=>R?y(_)?e.jsx(le,{color:"gold",children:"Lifetime plan caps"}):e.jsx(le,{children:"Per-phone plan"}):e.jsx(ie,{type:"secondary",children:"â"})}],ne=async f=>{N(!0);try{const _=await V("/api/v1/admin/customerPlan",{customerId:L,planSlug:s.name,monthlyCredits:f.monthlyCredits,purchaseRef:f.purchaseRef,comment:f.comment});if(_?.status===200){const O=_.data;
1ue.success({title:"Lifetime plan assigned",description:`${O?.planName||s.displayName} · ${O?.monthlyCredits} credits/month · purchase ref ${O?.purchaseRef||"â"}`}),u(null),C(Z=>Z+1)}}catch{}finally{N(!1)}};return e.jsxs(G,{vertical:!0,gap:"large",children:[e.jsx(Ee,{showPhoneNumber:!1,onCustomerChange:o}),L?e.jsxs(e.Fragment,{children:[e.jsxs(q,{title:`Numbers of ${n?.username||"customer"}`,children:[a>0&&e.jsx(ee,{type:Y?"warning":"info",showIcon:!0,style:{marginBottom:16},title:Y?c.length>1?`Numbers are split across ${c.length} lifetime plans: ${c.join(", ")}`:`Only ${a} of ${p.length} numbers run "${B?.displayName||U}"`:`Numbers run lifetime plan "${B?.displayName||U}"`,description:Y?"Billing mode is customer-wide, so this is not a supported state â re-assign the plan to move the remaining numbers onto it.":"The granted credits and the purchase reference are on this customer's audit trail."}),!r&&d?e.jsx(ee,{type:"error",showIcon:!0,title:"Could not load this customer's numbers",description:"Assigning is blocked because the numbers this grant would move cannot be listed. Re-select the customer to retry."}):!r&&!p.length?e.jsx(ee,{type:"warning",showIcon:!0,title:"This customer has no WhatsApp numbers yet",description:"Onboard a number first. The API would accept the grant and auto-enrol anything added later, but assigning is blocked here until there is at least one number to move onto the plan."}):e.jsx(it,{rowKey:"phoneNumberId",size:"small",pagination:!1,loading:r,columns:re,dataSource:p})]}),e.jsxs("div",{children:[e.jsx(xt,{level:5,children:a>0?"Change lifetime plan":"Grant a lifetime plan"}),m?e.jsx("div",{style:{padding:40,textAlign:"center"},children:e.jsx(pe,{size:"large"})}):T?e.jsx(ee,{type:"error",showIcon:!0,title:"Could not load the plan catalogue",description:"Without it the lifetime plans cannot be listed, and the numbers above cannot be classified."}):g.length?e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))",gap:20},children:g.map(f=>e.jsxs(q,{title:f.displayName,extra:f.name===U?e.jsx(le,{color:"success",children:"Current"}):null,style:{display:"flex",flexDirection:"column"},styles:{body:{flex:1,display:"flex",flexDirection:"column"}},children:[e.jsx(ie,{strong:!0,children:f.shortText}),e.jsxs(ie,{type:"secondary",children:[k(f.totalAmount)," one-time incl. GST"]}),e.jsx(ie,{style:{margin:"12px 0",whiteSpace:"pre-wrap"},children:f.description}),e.jsx("div",{style:{flex:1}}),e.jsx(K,{type:"primary",shape:"round",block:!0,disabled:!p.length,onClick:()=>u(f),children:f.name===U?"Re-assign":"Assign"})]},f.id))}):e.jsx(D,{description:"No lifetime plans in the catalogue",image:D.PRESENTED_IMAGE_SIMPLE})]})]}):e.jsx(D,{description:"Select a customer to grant a lifetime plan",image:D.PRESENTED_IMAGE_SIMPLE}),e.jsxs(Pe,{title:"Confirm lifetime plan",open:!!s,destroyOnHidden:!0,okText:"Assign plan",confirmLoading:i,onCancel:()=>u(null),onOk:()=>E.submit(),children:[e.jsx(ee,{type:"warning",showIcon:!0,style:{marginBottom:16},title:`All ${p.length} number(s) of ${n?.username||"this customer"} move onto this plan`,description:"Their current per-phone plans are replaced and any purchased add-ons on those numbers are cleared. This cannot be undone from here."}),e.jsxs(F,{column:1,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(F.Item,{label:"Customer",children:n?.username||"â"}),e.jsx(F.Item,{label:"Plan",children:s?.displayName||"â"}),e.jsx(F.Item,{label:"One-time amount",children:s?`${k(s.totalAmount)} incl. GST`:"â"})]}),e.jsxs(ae,{form:E,layout:"vertical",onFinish:ne,children:[e.jsx(ae.Item,{label:"Purchase reference",name:"purchaseRef",tooltip:"PayU txnid or PayPal order id â the only link back to the off-platform payment.",rules:[{required:!0,message:"Enter the payment reference for this grant"}],children:e.jsx(be,{placeholder:"e.g. PAYU-1234567890"})}),e.jsx(ae.Item,{label:"Monthly credits",name:"monthlyCredits",tooltip:"Defaults to the plan's catalogue allowance. Override only for a negotiated or comped amount.",rules:[{required:!0,message:"Monthly credits are required"}],children:e.jsx(Qe,{min:0,precision:0,style:{width:"100%"}})}),e.jsx(ae.Item,{label:"Comment",name:"comment",children:e.jsx(ft,{rows:3,placeholder:"Recorded on the audit entry for this grant..."})})]})]})]})},{Text:ge}=W,{TextArea:Pt}=be,Tt=n=>{const{token:o}=te.useToken(),{selectedCustomer:g}=n,[l,m]=t.useState(null),[P,T]=t.useState([]),[A,p]=t.useState(""),[j,r]=t.useState(!1),[S,d]=t.useState(!1),[x,b]=t.useState(!1),[C,s]=t.useState("Yearly"),u=g?.wabaToken?.phoneNumberId||null,i=y=>{s(y)},E=((y,R)=>y.filter(I=>R==="Monthly"?I.validityDays<365:R==="Yearly"?I.validityDays>=365:!1))(P,C);t.useEffect(()=>{if(!u){T([]);return}let y=!1;return(async()=>{b(!0);try{const I=await H(`/api/v1/payment/plans?phoneNumberId=${u}`);y||T(I?.data||[])}catch(I){y||T([]),console.error("Error fetching plans:",I)}finally{y||b(!1)}})(),()=>{y=!0}},[u]);const L=y=>{m(y),r(!0)},v=async()=>
1{if(!l)return;const y={phoneNumberId:u,planId:l?.id,comment:A};d(!0);try{await V("/api/v1/admin/applyPlan",y),ue.success({title:"Plan Applied",description:"The plan has been successfully applied."}),r(!1),m(null),p("")}catch(R){console.log("Error applying plan:",R),ue.error({title:"Error",description:"There was an issue applying the plan."})}finally{d(!1)}};return u?x?e.jsx("div",{style:{padding:40,textAlign:"center"},children:e.jsx(pe,{size:"large"})}):P.length?e.jsxs("div",{style:{padding:"20px",background:o.colorBgLayout},children:[e.jsxs(de,{gutter:[24,24],justify:"center",children:[e.jsx(ct,{planData:P,handleBillingCycleToggle:i,defaultSelected:"Yearly"}),e.jsx(de,{gutter:[24,24],justify:"center",children:E.map(y=>e.jsx(Ie,{xs:24,sm:12,md:8,lg:7,children:e.jsxs(q,{title:y.displayName,variant:"borderless",style:{textAlign:"center",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",padding:"12px 8px",minHeight:"600px",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{children:[e.jsx(ge,{strong:!0,style:{fontSize:"24px",color:"#1890ff"},children:y.priceShortText}),e.jsx(K,{type:"primary",size:"large",shape:"round",block:!0,style:{marginTop:"24px",marginBottom:"24px",fontWeight:"bold"},onClick:()=>L(y),children:"Activate Plan"}),e.jsx(ge,{style:{whiteSpace:"pre-wrap"},children:y.description})]}),e.jsx("div",{style:{marginTop:"auto"},children:e.jsxs("ul",{style:{textAlign:"left",fontSize:"14px",color:"#8c8c8c",listStyleType:"none",paddingLeft:0,marginBottom:0},children:[e.jsxs("li",{children:["Validity: ",y.validityDays," days"]}),e.jsxs("li",{children:["Total Amount (Incl. GST): â¹",y.totalAmount]})]})})]})},y.id))})]}),l&&e.jsxs(Pe,{title:"Confirm Plan Activation",open:j,onCancel:()=>r(!1),onOk:v,confirmLoading:S,okText:"Apply Plan",cancelText:"Cancel",children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx(ge,{strong:!0,children:"Plan Name:"})," ",e.jsx("span",{children:l.displayName})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx(ge,{strong:!0,children:"Amount:"})," ",e.jsxs("span",{children:["â¹",l.totalAmount]})]}),e.jsx(ae.Item,{label:"Add Comment",children:e.jsx(Pt,{rows:4,placeholder:"Enter a comment for this plan...",value:A,onChange:y=>p(y.target.value)})})]})]}):e.jsx("div",{style:{padding:20},children:e.jsx(D,{description:"No plans available for this phone number",image:D.PRESENTED_IMAGE_SIMPLE})}):e.jsx("div",{style:{padding:20},children:e.jsx(D,{description:"Select a customer and phone number to see the plans available for it",image:D.PRESENTED_IMAGE_SIMPLE})})},ke={plans:"/api/v1/admin/upgradePlans",calculate:"/api/v1/admin/upgrade/calculate",apply:"/api/v1/admin/upgrade"},St=async n=>await H(`${ke.plans}?phoneNumberId=${encodeURIComponent(n)}`),vt=async n=>await V(ke.calculate,n),wt=async n=>await V(ke.apply,n),{Text:Ae,Title:At}=W,Ct=[{id:"skeleton-1"},{id:"skeleton-2"}],Rt=n=>{const{phoneNumberId:o,onDone:g}=n,{token:l}=te.useToken(),{gstPercent:m}=me(),[P,T]=t.useState([]),[A,p]=t.useState({}),[j,r]=t.useState(!0),[S,d]=t.useState(null),[x,b]=t.useState(!1);t.useEffect(()=>{if(!o)return;let u=!1;return(async()=>{r(!0),p({});try{const N=await St(o),E=N?.status===200?N.data||[]:[];if(u)return;T(E);const L=await Promise.allSettled(E.map(y=>vt({phoneNumberId:o,planId:y.id})));if(u)return;const v={};L.forEach((y,R)=>{y.status==="fulfilled"&&y.value?.status===200&&(v[E[R].id]=y.value.data)}),p(v)}finally{u||r(!1)}})(),()=>{u=!0}},[o]);const C=async()=>{b(!0);try{(await wt({phoneNumberId:o,planId:S.id}))?.status===200&&(d(null),g?.())}catch{}finally{b(!1)}};if(!j&&!P.length)return e.jsx(D,{description:"No upgrades available for this phone's current plan"});const s=S?A[S.id]:null;return e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:20,maxWidth:820},children:(j?Ct:P).map(u=>{const i=A[u.id];return e.jsxs(q,{loading:j,styles:{body:{display:"flex",flexDirection:"column",height:"100%"}},children:[e.jsx(Ae,{strong:!0,children:u.displayName}),e.jsx(At,{level:5,style:{color:l.colorPrimary,margin:"8px 0 4px"},children:u.priceShortText}),e.jsx("div",{style:{marginTop:12},children:(u.description||"").split(`
2`).filter(Boolean).map((N,E)=>e.jsxs(G,{gap:8,style:{padding:"3px 0"},children:[e.jsx(Ae,{style:{color:l.colorSuccess},children:"â"}),e.jsx(Ae,{children:N.replace(/^[-â¢â]\s*/,"")})]},E))}),e.jsx("div",{style:{flex:1}}),i&&e.jsxs(G,{vertical:!0,gap:4,style:{borderTop:`1px solid ${l.colorSplit}`,marginTop:14,paddingTop:12},children:[e.jsx(z,{label:"Plan amount",value:k(i.chargePreGstAmount,i.currency),information:`Includes a credit of ${k(i.creditAmount,i.currency)} for the ${i.remainingMonths} unused month${i.remainingMonths===1?"":"s"} of the current plan.`}),e.jsx(z,{label:`GST (${m}%)`,value:k(i.gstAmount,i.currency)}),e.jsx(z,{label:"Customer would pay",value:k(i.totalAmount,i.currency),bold:!0})]}),e.jsx(K,{type:"primary",shape:"round",block:!0,size:"large",disabled:!i,loading:x&&S?.id===u.id,style:{marginTop:14},onClick:()=>d(u),children:"Apply upgrade"})]},u.id)})}),e.jsxs(Pe,{title:"Confirm plan upgrade",open:!!S,onCancel:()=>d(null),onOk:C,okText:"Upgrade",confirmLoading:x,children:[e.jsx(ee,{type:"info",showIcon:!0,style:{marginBottom:12},message:"The target plan is applied immediately; existing add-ons are cleared and the period restarts."}),e.jsxs(F,{column:1,size:"middle",bordered:!0,children:[e.jsx(F.Item,{label:"Phone",children:o}),e.jsx(F.Item,{label:"Upgrade to",children:S?.displayName??"-"}),e.jsx(F.Item,{label:"Customer would pay",children:s?`${k(s.totalAmount,s.currency)} incl. ${m}% GST`:"-"})]})]})]})},Et=()=>{const[n,o]=t.useState(null),[g,l]=t.useState(null),m=n?.wabaToken?.phoneNumberId,P=e.jsxs(e.Fragment,{children:[e.jsx(Ee,{onCustomerChange:()=>o(null),onPhoneNumberChange:o}),m?e.jsx(Me,{destroyOnHidden:!0,items:[{key:"apply",label:"Apply Plan",children:e.jsx(Tt,{selectedCustomer:n})},{key:"upgrade",label:"Upgrade",children:e.jsx(Rt,{phoneNumberId:m})}]}):e.jsx("div",{style:{padding:20},children:e.jsx(D,{description:"Select a customer and phone number to see the plans available for it",image:D.PRESENTED_IMAGE_SIMPLE})})]}),T=e.jsxs(e.Fragment,{children:[e.jsx(Ee,{searchType:"RESELLER",onCustomerChange:l}),e.jsx(gt,{selectedCustomer:g})]});return e.jsxs(e.Fragment,{children:[e.jsx(W.Title,{level:4,style:{margin:0},children:"Assign plans to Users"}),e.jsx("br",{}),e.jsx(Me,{defaultActiveKey:"customer",size:"large",destroyOnHidden:!0,items:[{key:"customer",label:"Customer",children:P},{key:"lifetime",label:"Lifetime Plan",children:e.jsx(bt,{})},{key:"reseller",label:"Reseller",children:T}]})]})},Ne={catalog:"/api/v1/payment/addonCatalog",calculate:"/api/v1/payment/addon/calculate",razorpayRequest:"/api/v1/payment/razorpay/addonRequest"},Ve=async n=>await H(`${Ne.catalog}${n?`?planName=${encodeURIComponent(n)}`:""}`),It=async n=>await V(Ne.calculate,n),kt=async n=>await V(Ne.razorpayRequest,n),Le={calculate:"/api/v1/payment/renewal/calculate",razorpayRequest:"/api/v1/payment/razorpay/renewalRequest",pending:"/api/v1/payment/renewal/pending"},Nt=async n=>await V(Le.calculate,n),Lt=async n=>await V(Le.razorpayRequest,n),_e=async n=>await H(`${Le.pending}?phoneNumberId=${encodeURIComponent(n)}`,!1),$e={plans:"/api/v1/payment/upgradePlans",calculate:"/api/v1/payment/upgrade/calculate",razorpayRequest:"/api/v1/payment/razorpay/upgradeRequest"},$t=async n=>await H(`${$e.plans}?phoneNumberId=${encodeURIComponent(n)}`),Bt=async n=>await V($e.calculate,n),Dt=async n=>await V($e.razorpayRequest,n),{Text:Ft,Title:Mt}=W,Be=n=>{const{title:o,subtitle:g,onClose:l}=n;return e.jsxs("div",{style:{marginTop:28,marginBottom:16},children:[e.jsxs(G,{justify:"space-between",align:"center",gap:12,children:[e.jsx(Mt,{level:5,style:{margin:0},children:o}),e.jsx(K,{type:"text",icon:e.jsx(He,{}),onClick:l,children:"Close"})]}),g&&e.jsx(Ft,{type:"secondary",style:{display:"block",marginTop:4},children:g})]})},{Text:Ge}=W,Oe=n=>{const o=[];return n.months&&o.push(`${n.months} month${n.months===1?"":"s"}`),n.days&&o.push(`${n.days} day${n.days===1?"":"s"}`),o.length?o.join(" "):"remaining period"},Ut=n=>{const{phoneNumberId:o,phoneFeature:g,catalog:l,loadingCatalog:m,onBack:P,onApplied:T}=n,{gstPercent:A}=me(),[p,j]=t.useState({}),[r,S]=t.useState(null),[d,x]=t.useState(!1),[b,C]=t.useState(!1),s=t.useRef(null),u=t.useRef(0),{launch:i,processing:N,paymentResult:E,paymentApiError:L,clearPaymentResult:v,checkoutFrame:y}=Te({onApplied:T});t.useEffect(()=>{const I=je(p);s.current&&clearTimeout(s.current);const a=++u.current;if(!I.length){S(null);return}return s.current=setTimeout(async()=>{x(!0);try{const c=await It({phoneNumberId:o,items:I});if(a!==u.current)return;S(c?.status===200?c.data:null)}catch{a===u.current&&S(null)}finally{a===u.current&&x(!1)}},400),()=>clearTimeout(s.current)},[p,o]);const R=async I=>{const a=je(p);if(a.length)try{const c=await kt({phoneNumberId:o,items:a,...I});c?.status===200&&(C(!1),i(c.data,I))}catch{}};return e.jsxs(e.Fragment,{children:[e.jsx(Be,{title:"Buy add-ons",subtitle:e.jsxs(e.Fragment,{children:["Added to your current ",e.jsx("b",{children:g?.planName||"plan"}),". Monthly add-ons are prorated for the time left in the current plan period."]}),onClose:P}),e.jsxs("div",{style:{display:"flex",gap:24,alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsx(q,{loading:m,style:{flex:1,minWidth:320},styles:{body:{padding:0}}
2,children:l.length?e.jsx(We,{catalog:l,value:p,onChange:j}):e.jsx(D,{description:"No add-ons available",image:D.PRESENTED_IMAGE_SIMPLE,style:{margin:24}})}),e.jsxs(q,{title:"Summary",loading:d,style:{width:300,position:"sticky",top:76,flexShrink:0},children:[r?e.jsxs(G,{vertical:!0,gap:6,children:[e.jsx(z,{label:"Billed for",value:Oe(r)}),e.jsx(z,{label:"Pre-GST",value:k(r.preGstAmount,r.currency)}),e.jsx(z,{label:`GST (${A}%)`,value:k(r.gstAmount,r.currency)}),e.jsx(z,{label:"Total payable now",value:k(r.totalAmount,r.currency),bold:!0,topBorder:!0}),e.jsx(Ge,{type:"secondary",style:{marginTop:2},children:"Billed until the current plan ends."})]}):e.jsx(Ge,{type:"secondary",children:"Select add-ons to see the amount payable."}),e.jsxs(K,{type:"primary",shape:"round",block:!0,size:"large",disabled:!r||d,loading:N,style:{marginTop:16},onClick:()=>C(!0),children:["Pay",r&&!d?` ${k(r.totalAmount,r.currency)}`:""]})]})]}),e.jsx(Se,{open:b,title:"Add-on billing details",confirmLoading:N,onCancel:()=>C(!1),onSubmit:R,summary:e.jsxs(F,{column:1,bordered:!0,size:"small",children:[e.jsx(F.Item,{label:"Billed for",children:b&&Oe(r)}),e.jsxs(F.Item,{label:"Total amount",children:[r?k(r.totalAmount,r.currency):"-"," incl. ",A,"% GST"]})]})}),y,e.jsx(ve,{open:!!(E||L),result:E,apiError:L,onClose:v,onRetry:()=>{v(),C(!0)}})]})},{Text:X,Title:ze}=W,_t=[{id:"skeleton-1"},{id:"skeleton-2"},{id:"skeleton-3"}],Gt=(n,o)=>{const g=n.validityDays>=365?12:Math.max(1,Math.round(n.validityDays/30)),l=o?n.totalAmount/o:n.totalAmount;return k(l/g)},Ot=n=>{const{phoneNumberId:o,phoneLabel:g,plans:l=[],loading:m,onPurchased:P}=n,{token:T}=te.useToken(),{gstRate:A,gstPercent:p,gstLoading:j}=me(),[r,S]=t.useState("Yearly"),[d,x]=t.useState(null),[b,C]=t.useState(!1),s=t.useRef(null),{launch:u,processing:i,paymentResult:N,paymentApiError:E,clearPaymentResult:L,checkoutFrame:v}=Te({onApplied:P}),y=l.filter(a=>r==="Monthly"?a.validityDays<365:a.validityDays>=365).sort((a,c)=>(a.totalAmount||0)-(c.totalAmount||0)),R=a=>(a.displayName||"").toLowerCase().includes("standard"),I=async a=>{C(!0);try{const c=await V("/api/v1/payment/razorpay/planRequest",{planId:d.id,phoneNumberId:o,...a});c?.status===200&&(s.current=d,x(null),u(c.data,a))}catch{}finally{C(!1)}};return e.jsxs(G,{vertical:!0,align:"center",style:{maxWidth:960,margin:"0 auto",textAlign:"center"},children:[e.jsx(ze,{level:3,style:{marginBottom:6},children:"Choose your plan"}),e.jsxs(X,{type:"secondary",style:{marginBottom:24},children:[g?`For ${g} · `:"","Upgrade or add add-ons anytime."]}),e.jsx(tt,{value:r,onChange:S,size:"large",shape:"round",style:{marginBottom:28},options:[{value:"Monthly",label:"Monthly"},{value:"Yearly",label:e.jsxs("span",{children:["Yearly"," ",e.jsx(le,{color:"success",style:{marginInlineEnd:0,borderRadius:10},children:"SAVE 20%"})]})}]}),!m&&!y.length?e.jsx(D,{description:`No ${r.toLowerCase()} plans available`}):e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))",gap:20,width:"100%",textAlign:"left",alignItems:"stretch"},children:(m||j?_t:y).map(a=>{const c=!m&&R(a);return e.jsxs(q,{loading:m||j,style:{position:"relative",overflow:"visible"},styles:{body:{padding:"26px 24px",display:"flex",flexDirection:"column",height:"100%"}},children:[e.jsx(X,{strong:!0,children:a.displayName}),e.jsxs(G,{align:"baseline",gap:4,style:{marginTop:12},children:[e.jsx(ze,{level:2,style:{margin:0},children:Gt(a,A)}),e.jsx(X,{type:"secondary",children:"/month"})]}),e.jsxs(X,{type:"secondary",style:{marginTop:4},children:["billed ",r.toLowerCase()," · ",a.priceShortText]}),e.jsxs(X,{type:"secondary",style:{marginTop:2},children:["Total ",k(a.totalAmount)," incl. ",p,"% GST"]}),e.jsxs(K,{type:c?"primary":"default",shape:"round",block:!0,size:"large",style:{marginTop:18,...c?{}:{color:T.colorPrimary,borderColor:T.colorPrimary}},onClick:()=>x(a),children:["Get ",a.displayName]}),e.jsx("div",{style:{marginTop:16},children:(a.description||"").split(` 3`).filter(Boolean).map((U,B)=>e.jsxs(G,{gap:8,style:{padding:"3.5px 0"},children:[e.jsx(X,{style:{color:T.colorSuccess},children:"â"}),e.jsx(X,{children:U.replace(/^[-â¢â]\s*/,"")})]},B))})]},a.id)})}),e.jsxs(X,{type:"secondary",style:{marginTop:20},children:["All plans exclude Meta messaging charges. Prices in INR, ",p,"% GST added at checkout."]}),e.jsx(Se,{open:!!d,title:"Your billing details",confirmLoading:b||i,onCancel:()=>x(null),onSubmit:I,summary:e.jsxs(F,{column:1,bordered:!0,size:"small",children:[e.jsxs(F.Item,{label:"Selected plan",children:[d?.displayName," (",r.toLowerCase(),")"]}),e.jsxs(F.Item,{label:"Total amount",children:[d?k(d.totalAmount):"-"," incl. ",p,"% GST"]})]})}),v,e.jsx(ve,{open:!!(N||E),result:N,apiError:E,onClose:L,onRetry:()=>{L(),x(s.current)}})]})},{Text:qe,Title:zt}=W,qt=n=>{const{refreshKey:o,...g}=n,{token:l}=te.useToken(),[m,P]=t.useState(null),[T,A]=t.useState(!0);if(t.useEffect(()=>{let x=!1;return(async()=>{A(!0);try{const C=await at();x||P(C?.status===200?C.data:null)}catch{x||P(null)}finally{x||A(!1)}})(),()=>{x=!0}},[o]),T)return e.jsx(q,{...g,children:e.jsx(G,{justify:"center",style:{padding:12},children:e.jsx(pe,{})})});if(!m?.onCreditPlan)return null;const p=m.granted||0,j=m.used||0,r=m.remaining??Math.max(0,p-j),S=p>0?Math.min(100,Math.round(j/p*100)):0,d=p>0&&r<=0;
3return e.jsxs(q,{...g,children:[e.jsxs(G,{align:"flex-start",gap:16,children:[e.jsxs("div",{style:{flex:1},children:[e.jsx(le,{color:l.colorPrimary,style:{marginBottom:8},children:"MONTHLY CREDITS"}),e.jsxs(zt,{level:5,style:{marginTop:0,marginBottom:0},children:[j.toLocaleString("en-IN")," of ",p.toLocaleString("en-IN")," credits used this month"]}),e.jsx(qe,{type:"secondary",style:{display:"block",marginTop:6},children:"One credit is one outgoing message or one chatbot run. Unused credits do not carry over."})]}),e.jsxs("div",{style:{textAlign:"right"},children:[e.jsxs(le,{color:d?"error":"success",style:{borderRadius:20,marginInlineEnd:0},children:[r.toLocaleString("en-IN")," left"]}),m.resetsOn&&e.jsxs(qe,{type:"secondary",style:{display:"block",marginTop:6},children:["Resets ",ce(m.resetsOn)]})]})]}),e.jsx(nt,{percent:S,showInfo:!1,strokeColor:d?l.colorError:l.colorPrimary,style:{marginTop:12}})]})},{Text:se}=W,Wt=n=>{const{phoneNumberId:o,phoneFeature:g,plans:l=[],currentPlanId:m,catalog:P,loadingCatalog:T,onBack:A,onApplied:p}=n,{token:j}=te.useToken(),{gstRate:r,gstPercent:S}=me(),[d,x]=t.useState(m||l[0]?.id),[b,C]=t.useState({}),[s,u]=t.useState(null),[i,N]=t.useState(!1),[E,L]=t.useState(!1),[v,y]=t.useState(!1),R=t.useRef(null),I=t.useRef(0),{launch:a,processing:c,paymentResult:U,paymentApiError:B,clearPaymentResult:Y,checkoutFrame:re}=Te({onApplied:p}),ne=l.find(w=>w.id===d)?.name,[f,_]=t.useState(P),[O,Z]=t.useState(!1);t.useEffect(()=>{x(w=>w||m||l[0]?.id)},[m,l]),t.useEffect(()=>{if(!ne)return;let w=!1;return Z(!0),(async()=>{try{const M=await Ve(ne);if(w)return;const h=M?.data||[];_(h);const $=new Set(h.map(we=>we.id));C(we=>Object.fromEntries(Object.entries(we).filter(([Ye])=>$.has(Ye))))}catch{w||_([])}finally{w||Z(!1)}})(),()=>{w=!0}},[ne]),t.useEffect(()=>{const w=++I.current;if(!d){u(null);return}return R.current&&clearTimeout(R.current),R.current=setTimeout(async()=>{N(!0);try{const M=await Nt({phoneNumberId:o,planId:d,addons:je(b)});if(w!==I.current)return;u(M?.status===200?M.data:null)}catch{w===I.current&&u(null)}finally{w===I.current&&N(!1)}},400),()=>clearTimeout(R.current)},[d,b,o]);const J=async w=>{if(d)try{const M=await Lt({phoneNumberId:o,planId:d,addons:je(b),...w});M?.status===200&&(L(!1),a(M.data,w))}catch{}},Q=g?.activeUpto,oe=Q&&s?.validityDays?Q+s.validityDays*864e5:null,ye=s?.addons?s.addons.preGstAmount:0;return e.jsxs(e.Fragment,{children:[e.jsx(Be,{title:"Renew plan",subtitle:e.jsxs(e.Fragment,{children:["Your current plan expires ",e.jsx("b",{children:ce(Q)}),". The new period starts when it ends â payment is taken now and the renewal applies automatically."]}),onClose:A}),l.length?e.jsxs("div",{style:{display:"flex",gap:24,alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsxs("div",{style:{flex:1,minWidth:340,display:"flex",flexDirection:"column",gap:20},children:[e.jsx(q,{title:"Renew into plan",children:e.jsx(Ue.Group,{value:d,onChange:w=>{x(w.target.value),y(!1)},style:{display:"flex",flexDirection:"column",gap:8,width:"100%"},children:l.map(w=>e.jsxs(Ue,{value:w.id,style:{width:"100%",border:`1px solid ${w.id===d?j.colorPrimary:j.colorBorderSecondary}`,background:w.id===d?j.colorPrimaryBg:void 0,borderRadius:8,padding:"12px 16px",marginInlineEnd:0},styles:{label:{flex:1}},children:[e.jsxs(G,{justify:"space-between",align:"center",gap:12,style:{width:"100%"},children:[e.jsx(se,{strong:!0,children:w.displayName}),e.jsxs(se,{type:"secondary",children:[k(r?w.totalAmount/r:w.totalAmount)," + ",S,"% GST"]})]}),w.id===d&&w.description&&e.jsxs(e.Fragment,{children:[e.jsx(K,{type:"link",size:"small",style:{padding:0,marginTop:6},onClick:()=>y(M=>!M),children:v?"Hide plan features":"View plan features"}),v&&e.jsx("div",{style:{borderTop:`1px solid ${j.colorPrimaryBorder}`,marginTop:8,paddingTop:10,display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"5px 16px"},children:w.description.split(` 4`).filter(Boolean).map((M,h)=>e.jsxs(G,{gap:8,children:[e.jsx(se,{style:{color:j.colorSuccess},children:"â"}),e.jsx(se,{children:M.replace(/^[-â¢â]\s*/,"")})]},h))})]})]},w.id))})}),(T||O||f.length>0)&&e.jsx(q,{title:"Add-ons for the next period",loading:T||O,styles:{body:{padding:0}}
4,children:e.jsx(We,{catalog:f,value:b,onChange:C,rowPadding:"12px 20px"})})]}),e.jsxs(q,{title:"Renewal summary",loading:i,style:{width:320,position:"sticky",top:76,flexShrink:0},children:[s?e.jsxs(e.Fragment,{children:[e.jsxs(G,{vertical:!0,gap:6,children:[e.jsx(z,{label:"Plan",value:k(s.planPreGstAmount,s.currency)}),e.jsx(z,{label:"Add-ons",value:k(ye,s.currency)}),e.jsx(z,{label:"Pre-GST",value:k(s.preGstAmount,s.currency)}),e.jsx(z,{label:`GST (${S}%)`,value:k(s.gstAmount,s.currency)}),e.jsx(z,{label:"Total payable",value:k(s.totalAmount,s.currency),bold:!0,topBorder:!0})]}),oe&&e.jsxs(se,{type:"secondary",style:{display:"block",marginTop:10},children:["New period: ",ce(Q)," â ",ce(oe)]})]}):e.jsx(se,{type:"secondary",children:"Select a plan to see the renewal amount."}),e.jsxs(K,{type:"primary",shape:"round",block:!0,size:"large",disabled:!s||i,loading:c,style:{marginTop:14},onClick:()=>L(!0),children:["Pay Now",s&&!i?` â ${k(s.totalAmount,s.currency)}`:""]}),e.jsxs(se,{type:"secondary",style:{display:"block",marginTop:8,textAlign:"center"},children:["The renewal is applied automatically on ",ce(Q),"."]})]})]}):e.jsx(D,{description:"No plans available"}),e.jsx(Se,{open:E,title:"Renewal billing details",confirmLoading:c,onCancel:()=>L(!1),onSubmit:J,summary:e.jsxs(F,{column:1,bordered:!0,size:"small",children:[e.jsx(F.Item,{label:"Selected plan",children:l.find(w=>w.id===d)?.displayName}),e.jsxs(F.Item,{label:"Total amount",children:[s?k(s.totalAmount,s.currency):"-"," incl. ",S,"% GST"]})]})}),re,e.jsx(ve,{open:!!(U||B),result:U,apiError:B,onClose:Y,onRetry:()=>{Y(),L(!0)}})]})},{Text:fe,Title:Vt}=W,Ce=n=>{const{icon:o,title:g,description:l,cta:m,active:P,onClick:T,primary:A,primaryBg:p}=n;return e.jsxs(q,{hoverable:!0,onClick:T,style:P?{borderColor:A,background:p}:void 0,styles:{body:{padding:20}},children:[e.jsx("div",{style:{marginBottom:8,color:A},children:o}),e.jsx(fe,{strong:!0,children:g}),e.jsx(fe,{type:"secondary",style:{display:"block",marginTop:4},children:l}),e.jsx(fe,{strong:!0,style:{color:A,display:"block",marginTop:10},children:P?"Close â":`${m} â`})]})},Yt=n=>{const{phoneFeature:o,currentPlan:g,pendingRenewal:l,phoneLabel:m,activeView:P,showUpgradeAction:T=!0,showBuyAddOnsAction:A=!0,showRenewAction:p=!0,lifetime:j=!1,onNavigate:r}=n,{token:S}=te.useToken(),d=S.colorPrimary;return e.jsxs(e.Fragment,{children:[e.jsx(Vt,{level:4,style:{marginTop:0,marginBottom:4},children:"Subscription"}),e.jsxs(fe,{type:"secondary",style:{display:"block",marginBottom:20},children:[j?"Your plan":"Manage your plan, add-ons and renewal",m?` for ${m}`:""]}),e.jsx(dt,{phoneFeature:o,currentPlan:g,pendingRenewal:l,lifetime:j,style:{marginBottom:20}}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(240px, 1fr))",gap:16},children:[T&&e.jsx(Ce,{icon:e.jsx(pt,{}),title:"Upgrade plan",description:"Move to a higher plan. Unused time on your current plan is credited.",cta:"Upgrade",active:P==="upgrade",onClick:()=>r("upgrade"),primary:d,primaryBg:S.colorPrimaryBg}),A&&e.jsx(Ce,{icon:e.jsx(mt,{}),title:"Buy add-ons",description:"Extra agents, contacts, chatbots and AI features. Prorated for the days remaining.",cta:"Browse add-ons",active:P==="addons",onClick:()=>r("addons"),primary:d,primaryBg:S.colorPrimaryBg}),p&&e.jsx(Ce,{icon:e.jsx(yt,{}),title:"Renew plan",description:"Renew into any plan with add-ons for the next period.",cta:"Renew",active:P==="renew",onClick:()=>r("renew"),primary:d,primaryBg:S.colorPrimaryBg})]})]})},{Text:Re,Title:Qt}=W,Ht=[{id:"skeleton-1"},{id:"skeleton-2"}],Kt=n=>{const{phoneNumberId:o,phoneFeature:g,upgradePlans:l=[],loadingUpgradePlans:m,onBack:P,onApplied:T}=n,{token:A}=te.useToken(),{gstPercent:p}=me(),[j,r]=t.useState({}),[S,d]=t.useState(!0),[x,b]=t.useState(null),C=t.useRef(null),{launch:s,processing:u,paymentResult:i,paymentApiError:N,clearPaymentResult:E,checkoutFrame:L}=Te({onApplied:T});t.useEffect(()=>{if(!o||m)return;let a=!1;return(async()=>{d(!0),r({});try{const c=await Promise.allSettled(l.map(B=>Bt({phoneNumberId:o,planId:B.id})));if(a)return;const U={};
4c.forEach((B,Y)=>{B.status==="fulfilled"&&B.value?.status===200&&(U[l[Y].id]=B.value.data)}),r(U)}finally{a||d(!1)}})(),()=>{a=!0}},[o,l,m]);const v=m||S,y=l,R=async a=>{try{const c=await Dt({phoneNumberId:o,planId:x.id,...a});c?.status===200&&(C.current=x,b(null),s(c.data,a))}catch{}},I=Object.values(j)[0];return e.jsxs(e.Fragment,{children:[e.jsx(Be,{title:"Upgrade your plan",subtitle:e.jsxs(e.Fragment,{children:["You are on ",e.jsx("b",{children:g?.planName||"your current plan"}),". Pick a higher plan below."]}),onClose:P}),!v&&!y.length?e.jsx(D,{description:"No upgrades available for your current plan"}):e.jsxs(e.Fragment,{children:[I&&e.jsx(ee,{type:"success",showIcon:!0,style:{marginBottom:20},message:e.jsxs(e.Fragment,{children:["You are credited ",e.jsx("b",{children:k(I.creditAmount,I.currency)})," for the ",I.remainingMonths," unused month",I.remainingMonths===1?"":"s"," of your current plan. This benefit is already included in the price below."]})}),e.jsx(de,{gutter:[20,20],children:(v?Ht:y).map(a=>{const c=j[a.id];return e.jsx(Ie,{xs:24,md:12,xl:8,children:e.jsxs(q,{loading:v,style:{height:"100%"},styles:{body:{display:"flex",flexDirection:"column",height:"100%"}},children:[e.jsx(Re,{strong:!0,children:a.displayName}),e.jsx(Qt,{level:5,style:{color:A.colorPrimary,margin:"8px 0 4px"},children:a.priceShortText}),a.validityDays&&e.jsxs(Re,{type:"secondary",style:{display:"block",marginBottom:12},children:["per ",a.validityDays>=365?"year":`${a.validityDays} days`]}),(a.description||"").split(` 5`).filter(Boolean).map((U,B)=>e.jsxs(Re,{style:{display:"block",padding:"3px 0"},children:["â ",U.replace(/^[-â¢â]\s*/,"")]},B)),e.jsx("div",{style:{flex:1}}),c&&e.jsxs(G,{vertical:!0,gap:4,style:{borderTop:`1px solid ${A.colorSplit}`,marginTop:14,paddingTop:12},children:[e.jsx(z,{label:"Plan amount",value:k(c.chargePreGstAmount,c.currency),bold:!0,information:`This price already includes a credit of ${k(c.creditAmount,c.currency)} for the unused time on your current plan.`}),e.jsx(z,{label:`GST (${p}%)`,value:k(c.gstAmount,c.currency)}),e.jsx(z,{label:"Payable now",value:k(c.totalAmount,c.currency),bold:!0})]}),e.jsxs(K,{type:"primary",shape:"round",block:!0,size:"large",disabled:!c,loading:u&&x?.id===a.id,style:{marginTop:14},onClick:()=>b(a),children:["Upgrade",c?` â Pay ${k(c.totalAmount,c.currency)}`:""]})]})},a.id)})})]}),e.jsx(Se,{open:!!x,title:"Upgrade billing details",confirmLoading:u,onCancel:()=>b(null),onSubmit:R,summary:e.jsxs(F,{column:1,bordered:!0,size:"small",children:[e.jsx(F.Item,{label:"Selected plan",children:x?.displayName}),e.jsxs(F.Item,{label:"Total amount",children:[x&&j[x.id]?k(j[x.id].totalAmount):"-"," incl. ",p,"% GST"]})]})}),L,e.jsx(ve,{open:!!(i||N),result:i,apiError:N,onClose:E,onRetry:()=>{E(),b(C.current)}})]})},Zt=()=>{const[n,o]=t.useState([]),[g,l]=t.useState(),[m,P]=t.useState(null),[T,A]=t.useState([]),[p,j]=t.useState(!1),[r,S]=t.useState([]),[d,x]=t.useState(!0),[b,C]=t.useState(null),[s,u]=t.useState("overview"),i=Ke(),N=xe(h=>h.connectedPhonesList),E=xe(h=>
5h.customerWabaTokensDetails),L=xe(h=>h.selectedPhoneRec),v=L?.value||(N?.length===1?N[0].value:null),R=(E?.wabaTokens||[]).find(h=>h.phoneNumberId===v)?.phoneFeature||null,I=(n||[]).find(h=>h.displayName===R?.planName)||null,a=!!R?.activeUpto&&R.activeUpto>Date.now(),c=lt(R?.planSlug),U=c===ot,B=rt(c),Y=a&&!!R?.planSlug&&c===void 0;t.useEffect(()=>{v&&(u("overview"),re(v))},[v]),t.useEffect(()=>{!v||b!==!0||Z(R?.planSlug)},[v,R?.planSlug,b]);const re=async h=>{_(h),await ne()?(f(h),O(h)):x(!1)},ne=async()=>{try{const $=(await H("/api/v1/payment/showPlan"))?.data?.showPlan!==!1;return C($),$}catch(h){return C(!0),console.error("Failed to fetch plan visibility:",h),!0}},f=async h=>{l(!0);try{const $=await H(`/api/v1/payment/plans?phoneNumberId=${h}`);$&&o($.data)}catch($){console.error("Failed to fetch plans list:",$)}finally{l(!1)}},_=async h=>{try{const $=await _e(h);P($?.data||null)}catch($){console.error("Failed to load pending renewal:",$)}},O=async h=>{x(!0);try{const $=await $t(h);S($?.status===200?$.data||[]:[])}catch($){console.error("Failed to load upgrade plans:",$)}finally{x(!1)}},Z=async h=>{j(!0);try{const $=await Ve(h);A($?.data||[])}catch($){console.error("Failed to load add-on catalog:",$)}finally{j(!1)}},J=async()=>{u("overview");try{const[h,$]=await Promise.all([H("/api/v1/onboard/customerDetail"),_e(v)]);h?.data&&i(Ze(h.data)),P($?.data||null)}catch(h){console.error("Failed to refresh after payment:",h)}};if(!v)return e.jsx(G,{vertical:!0,gap:"large",align:"center",style:{paddingTop:24},children:e.jsx(W.Title,{level:4,children:"Select a phone number in the header to manage its subscription"})});if(!E||b===null||Y)return e.jsx(G,{justify:"center",style:{paddingTop:48},children:e.jsx(pe,{size:"large"})});const Q=L?.label||(N||[]).find(h=>h.value===v)?.label||v;if(!a||U)return b?e.jsx(Ot,{phoneNumberId:v,phoneLabel:Q,plans:n,loading:g,onPurchased:J}):e.jsx(G,{justify:"center",style:{paddingTop:48},children:e.jsx(D,{description:De})});const oe=!B&&(!b||d||r.length>0),ye=!B&&(!b||p||T.length>0),w=!B,M=e.jsx(ee,{type:"warning",showIcon:!0,message:De,style:{marginTop:28}});return e.jsxs("div",{children:[e.jsx(Yt,{phoneFeature:R,currentPlan:I,pendingRenewal:m,phoneLabel:Q,activeView:s,lifetime:B,showUpgradeAction:oe,showBuyAddOnsAction:ye,showRenewAction:w,onNavigate:h=>u(s===h?"overview":h)}),B&&e.jsx(qt,{refreshKey:v}),s==="upgrade"&&oe&&(b?e.jsx(Kt,{phoneNumberId:v,phoneFeature:R,upgradePlans:r,loadingUpgradePlans:d,onBack:()=>u("overview"),onApplied:J}):M),s==="addons"&&ye&&(b?e.jsx(Ut,{phoneNumberId:v,phoneFeature:R,catalog:T,loadingCatalog:p,onBack:()=>u("overview"),onApplied:J}):M),s==="renew"&&w&&(b?e.jsx(Wt,{phoneNumberId:v,phoneFeature:R,plans:n,currentPlanId:I?.id,catalog:T,loadingCatalog:p,onBack:()=>u("overview"),onApplied:J}):M)]})},Tn=()=>{const n=xe(g=>g.jwtTokenDecodedData),{roleType:o}=n||{};return t.useLayoutEffect(()=>{Je&&!window.bolt&&Fe(Xe),window.Razorpay||Fe(et)},[]),o==="RESELLER"?e.jsx(ut,{}):o==="ADMIN"?e.jsx(Et,{}):o==="USER"?e.jsx(Zt,{}):null};export{Tn 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.