import{b9 as U,r as f,bo as W,aw as q,u as z,y as g,fy as $,fz as H,fA as Q,aC as _,aD as J,fB as X,j as e,q as p,bv as Y,$ as r,b as Z,dS as n,br as D,bz as ee,bq as se,b1 as te,cL as x,c as E,o as re,h as oe}from"./index-46ma1THH.js";import{u as ie}from"./useScreenWithScroll-zcr7TMGO.js";import{u as ae}from"./useProjectId-0fA9rNnF.js";import{v as ne,D as le,K as ce,a as de,I as ue,A as pe,R as xe,b as fe}from"./validations-1LUbtRgK.js";import{c as me,d as je,A as ge,P as he,T as Fe,e as be,C as De,f as Ee}from"./PythonEnvField-D-anKKWV.js";import{s as t}from"./styles-CqvG5Ri0.js";import{f as P,e as Pe}from"./utils-CSjO8SQp.js";import"./SingleSelect-DyMHGSBW.js";import"./index-DIN48ET6.js";import"./index-CcWUz40c.js";import"./KubernetesProjectEdit-DOgOIrBH.js";import"./getDefaultFormValues-3rRlpL1j.js";import"./index-D241LvV7.js";const v=({to:o,params:i})=>{const l=U();return f.useEffect(()=>{l(o,i)},[o,i,l]),null},Le=()=>{var b;const[o,i]=f.useState(!1),l=W(),S=ie(),c=ae(),{project:C}=q(),{dId:d}=z(),[y,I]=g(),[O,k]=g(),[A,T]=g(),[G,{isLoading:m,isSuccess:B}]=$(),{data:s,isFetching:F}=H({projectId:c,id:d},{refetchOnMountOrArgChange:!0}),[R,{isLoading:w,isSuccess:L}]=Q(),u=_({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:J(ne)}),V=async a=>{oe(u.formState.errors)&&await G({projectId:c,formValues:Pe({apiValues:P(s),formValues:a,project:C})})},{handleDelete:M}=f.useContext(X),N=async()=>{try{await R({projectId:+c,deploymentId:d}).unwrap(),M(re(p.project.deployments.overview,p.project.value,{id:c,dId:d}))}catch(a){console.error(a)}},K=()=>l(-1),j=()=>i(a=>!a);return f.useEffect(()=>{u.reset({...P(s),kserve:(s==null?void 0:s.servingTool)==="KSERVE"})},[s]),B?e.jsx(v,{to:p.project.deployments.overview,params:{dId:d}}):L?e.jsx(v,{to:p.project.deployments.list}):e.jsx(Y,{...u,children:e.jsxs("form",{onSubmit:u.handleSubmit(V),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(me,{}),e.jsx(je,{}),e.jsx(ge,{})]}),e.jsx(le,{})]})}),e.jsx(n,{title:"Environment configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(ce,{disabled:!0}),e.jsx(he,{isFileExplorerOpen:y,toggleFileExplorerPopup:I}),e.jsx(Fe,{isFileExplorerOpen:O,toggleFileExplorerPopup:k}),e.jsx(be,{}),e.jsx(De,{isFileExplorerOpen:A,toggleFileExplorerPopup:T})]})}),e.jsx(n,{title:"Inference logging",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(de,{}),e.jsx(ue,{})]})}),e.jsx(n,{title:"Advanced configuration",children:e.jsxs(r,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(Ee,{apiProtocol:s==null?void 0:s.apiProtocol}),e.jsx(pe,{batchingEnabled:(b=s==null?void 0:s.batchingConfiguration)==null?void 0:b.batchingEnabled})]})}),e.jsx(n,{title:"Resource allocation",children:e.jsx(xe,{})}),e.jsx(fe,{prefix:[],init:!1}),e.jsxs(n,{title:"Danger zone",mb:"20px",children:[e.jsx(D,{intent:"alert",type:"button",disabled:m||F,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:w,onClick:N},secondaryButtonProps:{children:"Back",onClick:j}})]})]})}),e.jsx(se,{hasScrollOnScreen:S,mainButton:e.jsx(D,{type:"submit",intent:"primary",disabled:m||F,isLoading:m,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(te,{type:"button",intent:"secondary",onClick:K,children:"Back"})})]})})},h=({name:o,value:i})=>e.jsxs(r,{flexDirection:"column",justifyContent:"flex-start",children:[e.jsx(E,{bold:!0,gray:!0,mb:"4px",children:o}),e.jsx(E,{bold:!0,children:i})]});export{Le as Edit,Le as default};
