import{r as e,j as s}from"./vendor-react-Dp9pL_Wn.js";import{l as o,aW as t}from"./c6eedc03a-CsEFTfjy.js";import{u as a,M as i}from"./vendor-intl-D2wGIp4M.js";import{b4 as r,b5 as n,N as d,x as c,b6 as l,b7 as m}from"./index-DhMXk6CR.js";import{C as p,U as j}from"./c184b2ab0-B47vEJvU.js";import{U as u,A as x,a as h}from"./c50575b1c-B0BmdX7H.js";import{A as f}from"./c1c2ea900-DBL1xVvQ.js";import{D as y}from"./vendor-ant-cds-bBedrtIN.js";import{m as g,A as v}from"./vendor-motion-EDlUw66k.js";import{R as b}from"./vendor-radix-Ch96tRrt.js";import"./vendor-base-ui-DNypCIlh.js";import"./vendor-zod-0xcuG3aM.js";import"./vendor-zustand-BeF8W8xk.js";import"./vendor-icons-CokWnmlw.js";import"./vendor-lodash-BvMLws5K.js";import"./vendor-router-qG5OCEmI.js";import"./vendor-query-BwvgHhJ1.js";import"./vendor-zod-v3-CZy0YPWu.js";import"./vendor-luxon-CZxT8ieM.js";import"./vendor-growthbook-C66YtMMX.js";import"./vendor-infra-DayZK7Ds.js";import"./vendor-base-5_f7mmWg.js";import"./caf7c7e06-DJYXCm3T.js";import"./c5669b8e4-DFSq88jr.js";import"./c5f4e1303-CiyIFgnl.js";import"./cbaad2c48-DaP34LG2.js";import"./vendor-virtual-DRz8lJfQ.js";import"./c284c2e59-ro8gmunw.js";import"./ccf5b4c65-Rs0D4cuE.js";import"./c0662a73e-DgHyr3yk.js";import"./c70a3d12b-KRRwGjFX.js";import"./c71860c77-CQFxtENY.js";import"./c19ac20ec-DWIUqcV1.js";import"./c818056db--8xDiVrI.js";import"./ce00bfecc-BI8itAxm.js";import"./c32c0d97f-BRKlKuDE.js";import"./c14703658-0O8Mq3Ud.js";const M=o=>{const[t,a]=e.useState(o.isOpen);return o.isOpen&&!t&&a(!0),t?s.jsx(p,{children:s.jsx(C,{...o,onExitTransitionComplete:()=>a(!1)})}):null};function C({isOpen:p,onClose:M,hasAutoReload:C=!1,targetModelId:w,copyModelId:S,switchToModelId:k,offerModelSwitch:P=!1,requiresEnablement:E=!1,onExitTransitionComplete:I}){const z=a().formatMessage({defaultMessage:"Close",id:"rbrahOGMC3"}),A=r(),[N,O]=e.useState("credits"),[R,T]=e.useState(!1),q=o("credit_purchase_link_passthrough");e.useEffect(()=>{p&&t()},[p]);const[F,H]=e.useState("form"),U="committed"===F,X=()=>{O("credits"),H("form"),M()},B=n(),L=d(),{mode:Y}=c(),Z=l();return s.jsx(y.Root,{open:p,onOpenChange:e=>{e||U||R||("payment"!==N?X():O("credits"))},dismissible:!1,onOpenChangeComplete:e=>{e||I()},children:s.jsxs(y.Popup,{size:"md",children:["controls"===N?s.jsx(y.Header,{showClose:!U,closeLabel:z,description:s.jsx(u,{}),children:A?s.jsx(i,{defaultMessage:"Set extra usage controls",id:"MAd/nIeKXP"}):s.jsx(i,{defaultMessage:"Set usage credit controls",id:"KYSkh6i226"})}):"payment"===N?s.jsx(y.Header,{showClose:!1,children:s.jsx(i,{defaultMessage:"Update payment method",id:"iIM9E+ynde"})}):"auto-reload"===N?s.jsx(y.Header,{showClose:!U,closeLabel:z,description:A?s.jsx(i,{defaultMessage:"You can automatically buy more extra usage when you run low.",id:"+XRRgmkPyP"}):s.jsx(i,{defaultMessage:"Automatically buy more usage credits when you\u2019re running low.",id:"Z6oYpvXRjf"}),children:s.jsx(i,{defaultMessage:"Turn on auto-reload?",id:"ndHvajCZ0O"})}):s.jsxs(s.Fragment,{children:[s.jsx(b,{asChild:!0,children:s.jsx(y.Title,{children:A?s.jsx(i,{defaultMessage:"Buy extra usage",id:"zlZmUPVSac"}):s.jsx(i,{defaultMessage:"Buy usage credits",id:"7q0oJax+NE"})})}),!U&&s.jsx(y.CloseButton,{"aria-label":z,className:"absolute right-4 top-4 z-[2]"})]}),s.jsx(g.div,{layout:"size",transition:{layout:{duration:.35,ease:[.16,1,.3,1]}},className:"-mx-1 shrink-0 overflow-hidden px-1","data-testid":"add-credits-step-wrapper",children:s.jsx(v,{mode:"wait",initial:!1,children:"credits"===N?s.jsx(g.div,{exit:{opacity:0},transition:{duration:.15},className:"relative",children:s.jsx(x,{onComplete:()=>{if(Z(),w&&"credits"===Y&&L(w)){const e=m();e?e(w):B(w,!0)}H("narrow"),E?O("controls"):C?X():O("auto-reload")},onClose:X,onCancel:X,onPurchaseStart:()=>H("committed"),onReturnToForm:()=>H("form"),targetModelId:w,copyModelId:S,switchToModelId:k,offerModelSwitch:P,requiresEnablement:E,onEditPaymentMethod:()=>O("payment")})},"credits"):"payment"===N?s.jsx(g.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},children:s.jsx(j,{topSlot:s.jsx(s.Fragment,{}),linkPassthrough:q,onLockedChange:T,onClose:()=>{T(!1),O("credits")}})},"payment"):"controls"===N?s.jsx(g.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:320,damping:30,delay:1},className:"mt-6",children:s.jsx(h,{targetModelId:w,onComplete:X})},"controls"):s.jsx(g.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:320,damping:30,delay:1},className:"mt-2",children:s.jsx(f,{onComplete:X,onSkip:X,isEnabled:C,isPostPurchase:!0})},"auto-reload")})})]})})}export{M as AddCreditsModal};
