import{b9 as K,r as m,bo as U,aw as $,u as H,y as g,fD as _,fE as q,fF as z,aC as J,aD as Q,fG as Z,j as e,t as p,bw as X,a as r,W as Y,dV as n,bs as F,bA as ee,bq as se,br as te,aJ as re,cM as x,c as P,s as oe,l as ie}from"./index-_eM6l4Nf.js";import{u as ae}from"./useScreenWithScroll-zcr7TMGO.js";import{u as ne}from"./useProjectId-BzgWWAl7.js";import{v as le,D as ce,K as de,a as ue,I as pe,A as xe,R as me,b as fe}from"./validations-DQKjlEYw.js";import{s as t}from"./styles-BK4Eh60z.js";import{c as je,d as ge,P as he,T as Ee,e as De,C as Fe,A as Pe}from"./PythonEnvField-kgV_dzlR.js";import{f as b,e as be}from"./utils-CSOjPL09.js";import"./SingleSelect-DCo75wUx.js";import"./index-CmVntchS.js";import"./form-CMT9TYED.js";import"./KubernetesProjectEdit-CZi-T2Qi.js";import"./index-B-5JhFyZ.js";import"./getDefaultFormValues-CCXN4e2h.js";import"./index-BXwHI1zk.js";const v=({to:o,params:i})=>{const l=K();return m.useEffect(()=>{l(o,i)},[o,i,l]),null},Ne=()=>{var D;const[o,i]=m.useState(!1),l=U(),C=ae(),c=ne(),{project:S}=$(),{dId:d}=H(),[y,I]=g(),[O,T]=g(),[k,G]=g(),[A,{isLoading:f,isSuccess:w}]=_(),{data:s,isFetching:E}=q({projectId:c,id:d},{refetchOnMountOrArgChange:!0}),[R,{isLoading:B,isSuccess:M}]=z(),u=J({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:Q(le)}),N=async a=>{ie(u.formState.errors)&&await A({projectId:c,formValues:be({apiValues:b(s),formValues:a,project:S})})},{handleDelete:V}=m.useContext(Z),W=async()=>{try{await R({projectId:+c,deploymentId:d}).unwrap(),V(oe(p.project.deployments.overview,p.project.value,{id:c,dId:d}))}catch(a){console.error(a)}},L=()=>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}}):M?e.jsx(v,{to:p.project.deployments.list}):e.jsx(X,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(N),style:t.editForm,children:[e.jsx(r,{sx:t.editFormWrapper,children:e.jsxs(r,{flexDirection:"column",sx:t.fieldsWrapper,children:[e.jsx(Y,{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(je,{}),e.jsx(ge,{})]}),e.jsx(ce,{})]})}),e.jsx(n,{title:"Environment configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(de,{disabled:!0}),e.jsx(he,{isFileExplorerOpen:y,toggleFileExplorerPopup:I}),e.jsx(Ee,{isFileExplorerOpen:O,toggleFileExplorerPopup:T}),e.jsx(De,{}),e.jsx(Fe,{isFileExplorerOpen:k,toggleFileExplorerPopup:G})]})}),e.jsx(n,{title:"Inference logging",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(ue,{}),e.jsx(pe,{})]})}),e.jsx(n,{title:"Advanced configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(Pe,{apiProtocol:s==null?void 0:s.apiProtocol}),e.jsx(xe,{batchingEnabled:(D=s==null?void 0:s.batchingConfiguration)==null?void 0:D.batchingEnabled})]})}),e.jsx(n,{title:"Resource allocation",children:e.jsx(me,{})}),e.jsx(fe,{prefix:[],init:!1}),e.jsxs(n,{title:"Danger zone",mb:"20px",children:[e.jsx(F,{intent:"alert",type:"button",disabled:f||E,onClick:j,children:"Delete deployment"}),e.jsx(ee,{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:B,onClick:W},secondaryButtonProps:{children:"Back",onClick:j}})]})]})}),e.jsx(se,{sx:{maxWidth:`var(${te})`},hasScrollOnScreen:C,mainButton:e.jsx(F,{type:"submit",intent:"primary",disabled:f||E,isLoading:f,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(re,{type:"button",intent:"secondary",onClick:L,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{Ne as Edit,Ne as default};
