import{b9 as K,r as m,bo as U,aw as $,u as q,y as g,fA as _,fB as H,fC as z,aC as Q,aD as J,fD as X,j as e,q as x,bw as Y,$ as r,b as Z,dT as n,bs as F,bA as ee,bq as se,br as te,b1 as re,cM as p,c as b,o as oe,h as ie}from"./index-Cc-6WbPt.js";import{u as ae}from"./useScreenWithScroll-zcr7TMGO.js";import{u as ne}from"./useProjectId-hjycL6JQ.js";import{v as le,D as ce,K as de,a as ue,I as xe,A as pe,R as me,b as fe}from"./validations-BA_PVm35.js";import{c as je,d as ge,A as he,P as De,T as Ee,e as Fe,C as be,f as Pe}from"./PythonEnvField-BiGFTxXs.js";import{s as t}from"./styles-HMF4H4tQ.js";import{f as P,e as ve}from"./utils-CksRkoB7.js";import"./SingleSelect-BdzfpmLO.js";import"./index-D8ntmGU0.js";import"./index-DeWhk8_Z.js";import"./KubernetesProjectEdit-BWf57EkW.js";import"./getDefaultFormValues-DKgoN3yI.js";import"./index-UO3hMyLO.js";const v=({to:o,params:i})=>{const l=K();return m.useEffect(()=>{l(o,i)},[o,i,l]),null},Ne=()=>{var E;const[o,i]=m.useState(!1),l=U(),C=ae(),c=ne(),{project:S}=$(),{dId:d}=q(),[y,I]=g(),[O,T]=g(),[k,A]=g(),[G,{isLoading:f,isSuccess:w}]=_(),{data:s,isFetching:D}=H({projectId:c,id:d},{refetchOnMountOrArgChange:!0}),[B,{isLoading:R,isSuccess:M}]=z(),u=Q({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:J(le)}),N=async a=>{ie(u.formState.errors)&&await G({projectId:c,formValues:ve({apiValues:P(s),formValues:a,project:S})})},{handleDelete:V}=m.useContext(X),L=async()=>{try{await B({projectId:+c,deploymentId:d}).unwrap(),V(oe(x.project.deployments.overview,x.project.value,{id:c,dId:d}))}catch(a){console.error(a)}},W=()=>l(-1),j=()=>i(a=>!a);return m.useEffect(()=>{u.reset({...P(s),kserve:(s==null?void 0:s.servingTool)==="KSERVE"})},[s]),w?e.jsx(v,{to:x.project.deployments.overview,params:{dId:d}}):M?e.jsx(v,{to:x.project.deployments.list}):e.jsx(Y,{...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(Z,{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(he,{})]}),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(De,{isFileExplorerOpen:y,toggleFileExplorerPopup:I}),e.jsx(Ee,{isFileExplorerOpen:O,toggleFileExplorerPopup:T}),e.jsx(Fe,{}),e.jsx(be,{isFileExplorerOpen:k,toggleFileExplorerPopup:A})]})}),e.jsx(n,{title:"Inference logging",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(ue,{}),e.jsx(xe,{})]})}),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(pe,{batchingEnabled:(E=s==null?void 0:s.batchingConfiguration)==null?void 0:E.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||D,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:R,onClick:L},secondaryButtonProps:{children:"Back",onClick:j}})]})]})}),e.jsx(se,{sx:{maxWidth:`var(${te})`},hasScrollOnScreen:C,mainButton:e.jsx(F,{type:"submit",intent:"primary",disabled:f||D,isLoading:f,children:!s||(s==null?void 0:s.status)===p.CREATING||(s==null?void 0:s.status)===p.CREATED||(s==null?void 0:s.status)===p.STOPPED||(s==null?void 0:s.status)===p.STOPPING?"Save":"Save and restart"}),secondaryButton:e.jsx(re,{type:"button",intent:"secondary",onClick:W,children:"Back"})})]})})},h=({name:o,value:i})=>e.jsxs(r,{flexDirection:"column",justifyContent:"flex-start",children:[e.jsx(b,{bold:!0,gray:!0,mb:"4px",children:o}),e.jsx(b,{bold:!0,children:i})]});export{Ne as Edit,Ne as default};
