import{o as e,r as s}from"./rolldown-runtime-iuO8RvI4.js";import{L_ as t}from"./shared-0-C4kdVF7Y.js";import{Mi as a,ki as o}from"./vendor-frame-CwiylG4Y.js";import{vr as i}from"./shared-1-3-6x7RKF.js";import{Wt as r,nn as n,rn as d}from"./vendor-all-2-BJdkbLSj.js";import{w as l}from"./shared-frame-DbQbH4Yr.js";import{r as c,t as m}from"./c184b2ab0-Ev4Zvq-y.js";import{k as p,w as u}from"./vendor-all-3-CWo5e8Lw.js";import{Qi as h}from"./shared-4-6CEyRAHb.js";import{G as j,H as f,I as x,P as y,j as g}from"./shared-7-VxUxSmVa.js";import{t as M}from"./cfb7b725b-B9Shn6WR.js";import{a as C,n as w,t as b}from"./c50575b1c-4GbDnFOH.js";var v=s({AddCreditsModal:()=>k}),S=e(a()),P=o(),k=e=>{const[s,t]=(0,S.useState)(e.isOpen);return e.isOpen&&!s&&t(!0),s?(0,P.jsx)(c,{withClientAttestation:!0,children:(0,P.jsx)(I,{...e,onExitTransitionComplete:()=>t(!1)})}):null};function I({isOpen:e,onClose:s,hasAutoReload:a=!1,targetModelId:o,copyModelId:c,switchToModelId:v,offerModelSwitch:k=!1,requiresEnablement:I=!1,onExitTransitionComplete:E}){const O=d().formatMessage({defaultMessage:"Close",id:"rbrahOGMC3"}),T=h(),[N,R]=(0,S.useState)("credits"),[A,H]=(0,S.useState)(!1),z=t("credit_purchase_link_passthrough");(0,S.useEffect)(()=>{e&&i()},[e]);const[L,_]=(0,S.useState)("form"),q="committed"===L,B=()=>{R("credits"),_("form"),s()},F=f(),G=x(),{mode:X}=y(),Y=g();return(0,P.jsx)(l.Root,{open:e,onOpenChange:e=>{e||q||A||("payment"!==N?B():R("credits"))},dismissible:!1,onOpenChangeComplete:e=>{e||E()},children:(0,P.jsxs)(l.Popup,{size:"md",children:["controls"===N?(0,P.jsx)(l.Header,{showClose:!q,closeLabel:O,description:(0,P.jsx)(w,{}),children:T?(0,P.jsx)(n,{defaultMessage:"Set extra usage controls",id:"MAd/nIeKXP"}):(0,P.jsx)(n,{defaultMessage:"Set usage credit controls",id:"KYSkh6i226"})}):"payment"===N?(0,P.jsx)(l.Header,{showClose:!1,children:(0,P.jsx)(n,{defaultMessage:"Update payment method",id:"iIM9E+ynde"})}):"auto-reload"===N?(0,P.jsx)(l.Header,{showClose:!q,closeLabel:O,description:T?(0,P.jsx)(n,{defaultMessage:"You can automatically buy more extra usage when you run low.",id:"+XRRgmkPyP"}):(0,P.jsx)(n,{defaultMessage:"Automatically buy more usage credits when you\u2019re running low.",id:"Z6oYpvXRjf"}),children:(0,P.jsx)(n,{defaultMessage:"Turn on auto-reload?",id:"ndHvajCZ0O"})}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(r,{asChild:!0,children:(0,P.jsx)(l.Title,{children:T?(0,P.jsx)(n,{defaultMessage:"Buy extra usage",id:"zlZmUPVSac"}):(0,P.jsx)(n,{defaultMessage:"Buy usage credits",id:"7q0oJax+NE"})})}),!q&&(0,P.jsx)(l.CloseButton,{"aria-label":O,className:"absolute right-4 top-4 z-[2]"})]}),(0,P.jsx)(u.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:(0,P.jsx)(p,{mode:"wait",initial:!1,children:"credits"===N?(0,P.jsx)(u.div,{exit:{opacity:0},transition:{duration:.15},className:"relative",children:(0,P.jsx)(C,{onComplete:()=>{if(Y(),o&&"credits"===X&&G(o)){const e=j();e?e(o):F(o,!0)}_("narrow"),I?R("controls"):a?B():R("auto-reload")},onClose:B,onCancel:B,onPurchaseStart:()=>_("committed"),onReturnToForm:()=>_("form"),targetModelId:o,copyModelId:c,switchToModelId:v,offerModelSwitch:k,requiresEnablement:I,onEditPaymentMethod:()=>R("payment")})},"credits"):"payment"===N?(0,P.jsx)(u.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},children:(0,P.jsx)(m,{topSlot:(0,P.jsx)(P.Fragment,{}),linkPassthrough:z,onLockedChange:H,onClose:()=>{H(!1),R("credits")}})},"payment"):"controls"===N?(0,P.jsx)(u.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:320,damping:30,delay:1},className:"mt-6",children:(0,P.jsx)(b,{targetModelId:o,onComplete:B})},"controls"):(0,P.jsx)(u.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{type:"spring",stiffness:320,damping:30,delay:1},className:"mt-2",children:(0,P.jsx)(M,{onComplete:B,onSkip:B,isEnabled:a,isPostPurchase:!0})},"auto-reload")})})]})})}export{v as n,k as t};