import{r as j,aS as w,aR as B,u as L,P as K,f_ as N,f$ as U,g0 as Q,an as W,g1 as $,j as e,b as l,aX as z,Q as a,E as H,fO as c,aU as f,b0 as X,aT as _,g2 as d,x as S,ao as q,al as J,c as Y}from"./index-ea7817a2.js";import{R as E}from"./RedirectInProject-7cd1be4f.js";import{u as Z}from"./useCurrentProject-0132f110.js";import{u as ee}from"./useProjectId-fe5627bf.js";import{D as se,K as te,T as ae,a as re,I as oe,A as ie,R as ne,v as le}from"./validations-7e0b3ce6.js";import{M as ce,a as de,A as ue,P as xe}from"./useResourceConfiguration-30b5e7f2.js";import{a as v,s as t,g as me}from"./utils-8f90da1d.js";import"./useProject-77619fff.js";import"./index-b96fda11.js";import"./FileUploaderButton-495e1c87.js";import"./useDownload-09eaf3eb.js";import"./PrimaryIconButton-fe990c52.js";import"./index-8f672200.js";import"./file-utils-a5f053e8.js";const ke=()=>{var D;const[u,x]=j.useState(!1),P=w(),b=B(),o=ee(),{project:F}=Z(),{dId:i}=L(),[C,y]=K(),[k,{isLoading:m,isSuccess:I}]=N(),{data:s,isFetching:g}=U({projectId:o,id:i},{refetchOnMountOrArgChange:!0}),[O,{isLoading:R,isSuccess:T}]=Q(),n=W({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:q(le)}),V=async r=>{J(n.formState.errors)&&await k({projectId:o,formValues:me({apiValues:v(s),formValues:r,project:F})})},{handleDelete:A}=j.useContext($),G=async()=>{try{await O({projectId:+o,deploymentId:i}).unwrap(),A(Y(l.deployments.overview,l.project.value,{id:o,dId:i}))}catch(r){console.error(r)}},M=()=>P(-1),p=()=>x(r=>!r);return j.useEffect(()=>{n.reset({...v(s),kserve:(s==null?void 0:s.servingTool)==="KSERVE"})},[s]),I?e.jsx(E,{to:l.deployments.overview,params:{dId:i}}):T?e.jsx(E,{to:l.deployments.list}):e.jsx(z,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(V),style:t.editForm,children:[e.jsx(a,{sx:t.editFormWrapper,children:e.jsxs(a,{flexDirection:"column",sx:t.fieldsWrapper,children:[e.jsx(H,{title:"Edit deployment",children:e.jsxs(a,{flexDirection:"column",sx:t.defaultGap,children:[e.jsxs(a,{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.jsx(se,{}),e.jsxs(a,{sx:t.defaultGap,children:[e.jsx(ce,{}),e.jsx(de,{}),e.jsx(ue,{})]}),e.jsx(te,{disabled:!0}),e.jsx(xe,{isFileExplorerOpen:C,toggleFileExplorerPopup:y}),e.jsx(ae,{})]})}),e.jsx(c,{title:"Kafka topic",children:e.jsxs(a,{flexDirection:"column",sx:t.defaultGap,children:[e.jsx(re,{}),e.jsx(oe,{})]})}),e.jsx(c,{title:"Configuration",children:e.jsx(ie,{batchingEnabled:(D=s==null?void 0:s.batchingConfiguration)==null?void 0:D.batchingEnabled})}),e.jsx(c,{title:"Resource allocation",children:e.jsx(ne,{})}),e.jsxs(c,{title:"Danger zone",mb:"20px",children:[e.jsx(f,{intent:"alert",type:"button",disabled:m||g,onClick:p,children:"Delete deployment"}),e.jsx(X,{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:p,mainButtonProps:{children:"Delete deployment",isLoading:R,onClick:G},secondaryButtonProps:{children:"Back",onClick:p}})]})]})}),e.jsx(_,{hasScrollOnScreen:b,mainButton:e.jsx(f,{type:"submit",intent:"primary",disabled:m||g,isLoading:m,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(f,{type:"button",intent:"secondary",onClick:M,children:"Back"})})]})})},h=({name:u,value:x})=>e.jsxs(a,{flexDirection:"column",justifyContent:"flex-start",children:[e.jsx(S,{bold:!0,gray:!0,mb:"4px",children:u}),e.jsx(S,{bold:!0,children:x})]});export{ke as Edit,ke as default};
