import{ba as U,r as m,bx as q,gf as z,at as J,u as K,w as f,go as $,gp as H,gq as _,aA as Q,aB as Y,gr as X,j as e,x as p,bF as Z,q as r,f as ee,bk as n,bB as D,bJ as se,bz as te,bA as re,aJ as oe,cY as x,c as P,t as ie,h as ae}from"./index-DHiyXWqE.js";import{u as ne}from"./useScreenWithScroll-zcr7TMGO.js";import{D as le,A as ce,S as de,R as ue,K as pe}from"./ScalingConfigurationField-CLSzqPWR.js";import{s as t}from"./styles-Cck2dVpe.js";import"./index-BdIq0ego.js";import{v as xe,f as me,g as ge,h as je,T as fe,i as he,j as Ee,A as Fe}from"./PythonEnvField-DPH7js2h.js";import{d as b,c as De}from"./utils-iWS1xq3i.js";import"./form-CrZPXKpD.js";import"./KubernetesProjectEdit-Dg3mVF7r.js";import"./index-5hEKE-oe.js";import"./SingleSelect-CAXL6nES.js";import"./getDefaultFormValues-DjHhdfri.js";import"./index-Bat3pAWW.js";const v=({to:o,params:i})=>{const l=U();return m.useEffect(()=>{l(o,i)},[o,i,l]),null},Ge=()=>{var F;const[o,i]=m.useState(!1),l=q(),S=ne(),c=z(),{project:C}=J(),{dId:d}=K(),[O,y]=f(),[I,k]=f(),[T,A]=f(),[B,{isLoading:g,isSuccess:w}]=$(),{data:s,isFetching:E}=H({projectId:c,id:d},{refetchOnMountOrArgChange:!0}),[G,{isLoading:N,isSuccess:R}]=_(),u=Q({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:Y(xe)}),M=async a=>{ae(u.formState.errors)&&await B({projectId:c,formValues:De({apiValues:b(s),formValues:a,project:C})})},{handleDelete:V}=m.useContext(X),L=async()=>{try{await G({projectId:+c,deploymentId:d}).unwrap(),V(ie(p.project.deployments.overview,p.project.value,{id:c,dId:d}))}catch(a){console.error(a)}},W=()=>l(-1),j=()=>i(a=>!a);return m.useEffect(()=>{u.reset({...b(s),kserve:(s==null?void 0:s.servingTool)==="KSERVE"})},[s]),w?e.jsx(v,{to:p.project.deployments.overview,params:{dId:d}}):R?e.jsx(v,{to:p.project.deployments.list}):e.jsx(Z,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(M),style:t.editForm,children:[e.jsx(r,{sx:t.editFormWrapper,children:e.jsxs(r,{flexDirection:"column",sx:t.fieldsWrapper,children:[e.jsx(ee,{title:"Edit deployment",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsxs(r,{sx:t.defaultGap,children:[e.jsx(h,{name:"name",value:s==null?void 0:s.name}),e.jsx(h,{name:"framework",value:s==null?void 0:s.modelFramework}),e.jsx(h,{name:"model server",value:s==null?void 0:s.modelServer})]}),e.jsxs(r,{sx:t.defaultGap,children:[e.jsx(me,{}),e.jsx(ge,{})]}),e.jsx(le,{})]})}),e.jsx(n,{title:"Environment configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(je,{isFileExplorerOpen:O,toggleFileExplorerPopup:y}),e.jsx(fe,{isFileExplorerOpen:I,toggleFileExplorerPopup:k}),e.jsx(he,{}),e.jsx(Ee,{isFileExplorerOpen:T,toggleFileExplorerPopup:A})]})}),e.jsx(n,{title:"Advanced configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(Fe,{apiProtocol:s==null?void 0:s.apiProtocol}),e.jsx(ce,{batchingEnabled:(F=s==null?void 0:s.batchingConfiguration)==null?void 0:F.batchingEnabled})]})}),e.jsx(n,{title:"Scaling configuration",children:e.jsx(de,{})}),e.jsx(n,{title:"Resources per Instance",children:e.jsx(ue,{})}),e.jsx(pe,{prefix:[],init:!1}),e.jsxs(n,{title:"Danger zone",mb:"20px",children:[e.jsx(D,{intent:"alert",type:"button",disabled:g||E,onClick:j,children:"Delete deployment"}),e.jsx(se,{title:`Delete ${s==null?void 0:s.name}`,secondaryText:"Once you delete a deployment, there is no going back. Please be certain.",isOpen:o,onClose:j,mainButtonProps:{children:"Delete deployment",isLoading:N,onClick:L},secondaryButtonProps:{children:"Back",onClick:j}})]})]})}),e.jsx(te,{sx:{maxWidth:`var(${re})`},hasScrollOnScreen:S,mainButton:e.jsx(D,{type:"submit",intent:"primary",disabled:g||E,isLoading:g,children:!s||(s==null?void 0:s.status)===x.CREATING||(s==null?void 0:s.status)===x.CREATED||(s==null?void 0:s.status)===x.STOPPED||(s==null?void 0:s.status)===x.STOPPING?"Save":"Save and restart"}),secondaryButton:e.jsx(oe,{type:"button",intent:"secondary",onClick:W,children:"Back"})})]})})},h=({name:o,value:i})=>e.jsxs(r,{flexDirection:"column",justifyContent:"flex-start",children:[e.jsx(P,{bold:!0,gray:!0,mb:"4px",children:o}),e.jsx(P,{bold:!0,children:i})]});export{Ge as Edit,Ge as default};
