import{r as f,bw as U,u as W,c as g,fz as z,fA as Q,fB as q,az as H,fC as $,j as e,s as c,bB as J,B as r,m as X,ds as i,bE as Y,bx as Z,fD as d,aG as _,b as E,aA as ee,g as se,q as te}from"./index-dP1W1_bd.js";import{R as D}from"./RedirectInProject-CQTAnW03.js";import{u as re}from"./useScreenWithScroll-zcr7TMGO.js";import{u as oe}from"./useDownload-C3yCvYJa.js";import{u as ie}from"./useProjectId-DopcTZap.js";import{B as b}from"./ButtonWithRole-CF64B_Or.js";import{D as ae,K as ne,a as le,I as ce,A as de,R as ue,b as pe,v as xe}from"./validations-D4l99VpE.js";import{a as me,b as fe,A as ge,P as je,T as he,c as Fe,C as Ee,d as De}from"./PythonEnvField-BA5Z1n7e.js";import{a as P,s as t,g as be}from"./utils-CSV5kSUs.js";import"./useProject-CXVt1xnE.js";import"./length-BzpOfCdE.js";import"./SingleSelect-B8f6hurf.js";import"./index-D4-3j93o.js";import"./KubernetesProjectEdit-CcUpiV79.js";import"./index-MHdXqM53.js";import"./FileUploaderButton-frSujVRY.js";import"./uniq-98MdbBvs.js";import"./uniqBy-6mvKp2Ip.js";import"./dumbPluralize-CcxDsNiu.js";import"./getDefaultFormValues-BDGdN25U.js";import"./index-DEBSKkGo.js";import"./min-DNV8UA03.js";import"./__-BIxbRvwe.js";const qe=()=>{var F;const[u,p]=f.useState(!1),v=U(),C=re(),a=ie(),{project:S}=oe(),{dId:n}=W(),[y,I]=g(),[O,k]=g(),[B,A]=g(),[T,{isLoading:x,isSuccess:G}]=z(),{data:s,isFetching:h}=Q({projectId:a,id:n},{refetchOnMountOrArgChange:!0}),[R,{isLoading:V,isSuccess:w}]=q(),l=H({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:ee(xe)}),L=async o=>{se(l.formState.errors)&&await T({projectId:a,formValues:be({apiValues:P(s),formValues:o,project:S})})},{handleDelete:M}=f.useContext($),K=async()=>{try{await R({projectId:+a,deploymentId:n}).unwrap(),M(te(c.deployments.overview,c.project.value,{id:a,dId:n}))}catch(o){console.error(o)}},N=()=>v(-1),m=()=>p(o=>!o);return f.useEffect(()=>{l.reset({...P(s),kserve:(s==null?void 0:s.servingTool)==="KSERVE"})},[s]),G?e.jsx(D,{to:c.deployments.overview,params:{dId:n}}):w?e.jsx(D,{to:c.deployments.list}):e.jsx(J,{...l,children:e.jsxs("form",{onSubmit:l.handleSubmit(L),style:t.editForm,children:[e.jsx(r,{sx:t.editFormWrapper,children:e.jsxs(r,{flexDirection:"column",sx:t.fieldsWrapper,children:[e.jsx(X,{title:"Edit deployment",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsxs(r,{sx:t.defaultGap,children:[e.jsx(j,{name:"name",value:s==null?void 0:s.name}),e.jsx(j,{name:"framework",value:s==null?void 0:s.modelFramework}),e.jsx(j,{name:"model server",value:s==null?void 0:s.modelServer})]}),e.jsxs(r,{sx:t.defaultGap,children:[e.jsx(me,{}),e.jsx(fe,{}),e.jsx(ge,{})]}),e.jsx(ae,{})]})}),e.jsx(i,{title:"Environment configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(ne,{disabled:!0}),e.jsx(je,{isFileExplorerOpen:y,toggleFileExplorerPopup:I}),e.jsx(he,{isFileExplorerOpen:O,toggleFileExplorerPopup:k}),e.jsx(Fe,{}),e.jsx(Ee,{isFileExplorerOpen:B,toggleFileExplorerPopup:A})]})}),e.jsx(i,{title:"Inference logging",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(le,{}),e.jsx(ce,{})]})}),e.jsx(i,{title:"Advanced configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(De,{apiProtocol:s==null?void 0:s.apiProtocol}),e.jsx(de,{batchingEnabled:(F=s==null?void 0:s.batchingConfiguration)==null?void 0:F.batchingEnabled})]})}),e.jsx(i,{title:"Resource allocation",children:e.jsx(ue,{})}),e.jsx(pe,{prefix:[],init:!1}),e.jsxs(i,{title:"Danger zone",mb:"20px",children:[e.jsx(b,{intent:"alert",type:"button",disabled:x||h,onClick:m,children:"Delete deployment"}),e.jsx(Y,{title:`Delete ${s==null?void 0:s.name}`,secondaryText:"Once you delete a deployment, there is no going back. Please be certain.",isOpen:u,onClose:m,mainButtonProps:{children:"Delete deployment",isLoading:V,onClick:K},secondaryButtonProps:{children:"Back",onClick:m}})]})]})}),e.jsx(Z,{hasScrollOnScreen:C,mainButton:e.jsx(b,{type:"submit",intent:"primary",disabled:x||h,isLoading:x,children:!s||(s==null?void 0:s.status)===d.CREATING||(s==null?void 0:s.status)===d.CREATED||(s==null?void 0:s.status)===d.STOPPED||(s==null?void 0:s.status)===d.STOPPING?"Save":"Save and restart"}),secondaryButton:e.jsx(_,{type:"button",intent:"secondary",onClick:N,children:"Back"})})]})})},j=({name:u,value:p})=>e.jsxs(r,{flexDirection:"column",justifyContent:"flex-start",children:[e.jsx(E,{bold:!0,gray:!0,mb:"4px",children:u}),e.jsx(E,{bold:!0,children:p})]});export{qe as Edit,qe as default};
