import{r as e,j as s}from"./vendor-react-Dp9pL_Wn.js";import{q as o,b7 as t}from"./c2ee0272b-DPDuX889.js";import{u as a,M as i}from"./vendor-intl-D2wGIp4M.js";import{b9 as r,ba as n,O as d,z as c,bb as l,bc as m}from"./index-XoaBlZfC.js";import{C as p,U as j}from"./c184b2ab0-DziIPN3m.js";import{U as u,A as h,a as f}from"./c50575b1c-zVWM-VNR.js";import{A as x}from"./cfb7b725b-CtbtRcDE.js";import{D as b}from"./vendor-ant-cds-BLsR_p72.js";import{m as y,A as g}from"./vendor-motion-EDlUw66k.js";import{R as v}from"./vendor-radix-Dv3qPI0v.js";import"./vendor-base-ui-N1VQ4ctE.js";import"./vendor-zod-B8MhECV7.js";import"./vendor-zustand-BeF8W8xk.js";import"./vendor-icons-DGChWNxR.js";import"./vendor-lodash-BvMLws5K.js";import"./vendor-router-qG5OCEmI.js";import"./vendor-query-CRl6sF7K.js";import"./vendor-zod-v3-CZy0YPWu.js";import"./vendor-luxon-CZxT8ieM.js";import"./vendor-infra-DayZK7Ds.js";import"./vendor-growthbook-HDTqppl-.js";import"./vendor-base-5_f7mmWg.js";import"./c9a5287df-D_Z7ffFR.js";import"./c51e217b4-CQax1dv1.js";import"./c627fcdb6-1_bsVTpt.js";import"./vendor-virtual-DRz8lJfQ.js";import"./c284c2e59-Dscwpvgf.js";import"./ccf5b4c65-WcJ6U-m7.js";import"./c0662a73e-qWm_evwI.js";import"./cf8dbbbdb-DiSrJlH1.js";import"./c71860c77-PevZi8ly.js";import"./c590fc197-DV9Hq9cB.js";import"./c3a484033-CxVAsaHW.js";import"./ce00bfecc-D6UIZtf_.js";import"./c80791b3a-C9RrC3yS.js";import"./c33b2042a-BXM4oh1L.js";const M=o=>{const[t,a]=e.useState(o.isOpen);return o.isOpen&&!t&&a(!0),t?s.jsx(p,{withClientAttestation:!0,children:s.jsx(C,{...o,onExitTransitionComplete:()=>a(!1)})}):null};function C({isOpen:p,onClose:M,hasAutoReload:C=!1,targetModelId:w,copyModelId:S,switchToModelId:P,offerModelSwitch:O=!1,requiresEnablement:k=!1,onExitTransitionComplete:E}){const I=a().formatMessage({defaultMessage:"Close",id:"rbrahOGMC3"}),z=r(),[R,T]=e.useState("credits"),[A,N]=e.useState(!1),q=o("credit_purchase_link_passthrough");e.useEffect(()=>{p&&t()},[p]);const[U,H]=e.useState("form"),X="committed"===U,B=()=>{T("credits"),H("form"),M()},F=n(),L=d(),{mode:Y}=c(),Z=l();return s.jsx(b.Root,{open:p,onOpenChange:e=>{e||X||A||("payment"!==R?B():T("credits"))},dismissible:!1,onOpenChangeComplete:e=>{e||E()},children:s.jsxs(b.Popup,{size:"md",children:["controls"===R?s.jsx(b.Header,{showClose:!X,closeLabel:I,description:s.jsx(u,{}),children:z?s.jsx(i,{defaultMessage:"Set extra usage controls",id:"MAd/nIeKXP"}):s.jsx(i,{defaultMessage:"Set usage credit controls",id:"KYSkh6i226"})}):"payment"===R?s.jsx(b.Header,{showClose:!1,children:s.jsx(i,{defaultMessage:"Update payment method",id:"iIM9E+ynde"})}):"auto-reload"===R?s.jsx(b.Header,{showClose:!X,closeLabel:I,description:z?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(v,{asChild:!0,children:s.jsx(b.Title,{children:z?s.jsx(i,{defaultMessage:"Buy extra usage",id:"zlZmUPVSac"}):s.jsx(i,{defaultMessage:"Buy usage credits",id:"7q0oJax+NE"})})}),!X&&s.jsx(b.CloseButton,{"aria-label":I,className:"absolute right-4 top-4 z-[2]"})]}),s.jsx(y.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(g,{mode:"wait",initial:!1,children:"credits"===R?s.jsx(y.div,{exit:{opacity:0},transition:{duration:.15},className:"relative",children:s.jsx(h,{onComplete:()=>{if(Z(),w&&"credits"===Y&&L(w)){const e=m();e?e(w):F(w,!0)}H("narrow"),k?T("controls"):C?B():T("auto-reload")},onClose:B,onCancel:B,onPurchaseStart:()=>H("committed"),onReturnToForm:()=>H("form"),targetModelId:w,copyModelId:S,switchToModelId:P,offerModelSwitch:O,requiresEnablement:k,onEditPaymentMethod:()=>T("payment")})},"credits"):"payment"===R?s.jsx(y.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:N,onClose:()=>{N(!1),T("credits")}})},"payment"):"controls"===R?s.jsx(y.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(f,{targetModelId:w,onComplete:B})},"controls"):s.jsx(y.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(x,{onComplete:B,onSkip:B,isEnabled:C,isPostPurchase:!0})},"auto-reload")})})]})})}export{M as AddCreditsModal};
