import{b0 as F,aR as P,b1 as N,ji as B,jk as L,u as W,jh as R,b2 as $,cR as z,jj as A,am as G,iL as f,r as i,fY as H,j as e,aW as O,a as v,fI as I,e8 as Q,aT as c,aS as U,g as Y,e as l}from"./index-d6499a22.js";import{u as _}from"./useProjectId-6028b5ae.js";import{g as q}from"./utils-14352779.js";const J=()=>{const a=_(),m=F(),u=P(),T=N(),[M]=B(),[b]=L(),{mId:g,vId:p}=W(),s=`${g}_${p}`,[S,{isLoading:h}]=R(),j=$(z),{data:o=[]}=A({modelId:s,projectId:a}),n=G({defaultValues:{tags:f(o)},shouldUnregister:!1}),w=()=>u(-1),{handleDelete:D}=i.useContext(H),E=n.handleSubmit(async r=>{const x=q(r.tags,j);try{const d=j.map(t=>t.name),k=x.filter(({schema:t})=>!d.includes(t));await Promise.all([...k.map(async t=>await b({modelId:s,projectId:a,tagName:t.name}).unwrap()),...x.map(async t=>await M({modelId:s,projectId:a,tagName:t.schema,data:t.value}).unwrap())]),u(-1)}catch(d){console.warn(d)}}),V=async()=>{try{await S({projectId:a,mlId:s}).unwrap(),D(Y(l.models.versionView,l.project.value,{id:a,mId:g,vId:p})),T(l.models.list)}catch(r){console.error(r)}};return i.useEffect(()=>{m.schematisedTags.fetch()},[m]),i.useEffect(()=>{o.length&&n.setValue("tags",f(o))},[o]),e.jsxs(O,{...n,children:[e.jsx(v,{sx:y.editFormWrapper,children:e.jsxs(v,{flexDirection:"column",sx:y.fieldsWrapper,children:[e.jsx(I,{title:"Meta data",mb:"20px",children:e.jsx(Q,{isEdit:!0})}),e.jsx(I,{title:"Danger zone",mb:"20px",children:e.jsx(c,{type:"button",intent:"alert",disabled:h,onClick:V,isLoading:h,children:"Delete model version"})})]})}),e.jsx(U,{hasScrollOnScreen:!0,mainButton:e.jsx(c,{type:"button",intent:"primary",onClick:E,children:"Save"}),secondaryButton:e.jsx(c,{type:"button",intent:"secondary",onClick:w,children:"Back"})})]})},ee=J,y={editFormWrapper:{width:"100%",alignItems:"center",paddingBottom:"10vh",justifyContent:"center"},fieldsWrapper:{gap:"20px",width:"100%"}};export{ee as default};
