import{r as f,aR as w,aQ as B,u as G,l as K,fV as N,fW as U,fX as W,am as z,fY as Q,j as e,e as l,aW as $,a,K as H,fI as c,aT as j,a$ as X,aS as Y,fZ as d,c as S,an as Z,ak as q,g as J}from"./index-d6499a22.js";import{R as v}from"./RedirectInProject-0591395a.js";import{u as _}from"./useCurrentProject-b23444be.js";import{u as ee}from"./useProjectId-6028b5ae.js";import{D as se,K as te,T as ae,a as re,I as ie,A as oe,R as ne,v as le}from"./validations-c473490c.js";import{M as ce,a as de,A as ue,P as me}from"./useResourceConfiguration-40036805.js";import{a as E,s as t,g as xe}from"./utils-b5e8f9a5.js";import"./useProject-0d0fdeb3.js";import"./index-0e1d5e0b.js";import"./FileUploaderButton-c4f1b533.js";import"./useDownload-7167ff3b.js";import"./PrimaryIconButton-fd23494f.js";import"./index-da50fbe6.js";import"./file-utils-b5704e1c.js";import"./index-d13f0052.js";import"./groupBy-d48cd610.js";const Oe=()=>{var D;const[u,m]=f.useState(!1),F=w(),b=B(),i=ee(),{project:P}=_(),{dId:o}=G(),[C,y]=K(),[k,{isLoading:x,isSuccess:I}]=N(),{data:s,isFetching:g}=U({projectId:i,id:o},{refetchOnMountOrArgChange:!0}),[O,{isLoading:R,isSuccess:T}]=W(),n=z({reValidateMode:"onChange",shouldUnregister:!1,mode:"onChange",resolver:Z(le)}),V=async r=>{q(n.formState.errors)&&await k({projectId:i,formValues:xe({apiValues:E(s),formValues:r,project:P})})},{handleDelete:A}=f.useContext(Q),L=async()=>{try{await O({projectId:+i,deploymentId:o}).unwrap(),A(J(l.deployments.overview,l.project.value,{id:i,dId:o}))}catch(r){console.error(r)}},M=()=>F(-1),p=()=>m(r=>!r);return f.useEffect(()=>{n.reset({...E(s),kserve:(s==null?void 0:s.servingTool)==="KSERVE"})},[s]),I?e.jsx(v,{to:l.deployments.overview,params:{dId:o}}):T?e.jsx(v,{to:l.deployments.list}):e.jsx($,{...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(me,{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(ie,{})]})}),e.jsx(c,{title:"Configuration",children:e.jsx(oe,{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(j,{intent:"alert",type:"button",disabled:x||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:L},secondaryButtonProps:{children:"Back",onClick:p}})]})]})}),e.jsx(Y,{hasScrollOnScreen:b,mainButton:e.jsx(j,{type:"submit",intent:"primary",disabled:x||g,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(j,{type:"button",intent:"secondary",onClick:M,children:"Back"})})]})})},h=({name:u,value:m})=>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:m})]});export{Oe as Edit,Oe as default};
