import{bI as C,u as x,r as h,eR as D,eS as E,eT as U,eU as V,P as $,aC as y,eV as A,eW as R,eX as O,eh as u,j as g,bw as W,a as F,aJ as _,bs as B}from"./index-_eM6l4Nf.js";import{u as H,a as J}from"./index-BXwHI1zk.js";import{S as Q}from"./SchematisedTagsForm-D8cUEyzq.js";const X=()=>{const s=C(),{id:t,fsId:e,fgId:a}=x(),[i,d]=h.useState(!1),{currentData:n}=D({pId:+t,fsId:+e,fgId:+a},{skip:!a});return[h.useCallback(async({tags:o})=>{d(!0);const c=n.map(({name:r})=>r),T=Object.keys(o||{}),p=c.filter(r=>!T.includes(r));return await Promise.allSettled(p.map(async r=>{await E.deleteTag(+t,+e,+a,r)})),await U(+t,+e,+a,o),s(V.invalidateTags([{type:$.ProjectTags.FeatureGroupTag,id:+a}])),d(!1),"success"},[n,s,a,e,t]),i]},q=({onDone:s,tags:t,type:e=u.fv,tdVersion:a})=>{const{fsId:i,id:d,fvName:n,fvVersion:l,mId:o,vId:c}=x(),T=y({shouldUnregister:!1,defaultValues:{tags:t}}),[p,{isLoading:r}]=A(),[w,{isLoading:M}]=R(),[v,{isLoading:k}]=O(),[b,L]=X(),[S,{isLoading:G}]=H(),[j,{isLoading:N}]=J(),P=h.useCallback(async m=>{const f=z(t,m.tags);if(e===u.fg)return b(m).then(()=>{s()});if(e===u.fv)return f.length>0&&await Promise.all(f.map(I=>w({pId:+d,fsId:+i,id:n,version:+l,tagName:I}).unwrap())),p({pId:+d,fsId:+i,id:n,version:+l,tags:m.tags}).unwrap().then(()=>{s()});if(e===u.td)return v({pId:+d,fsId:+i,fvName:n,fvVersion:+l,id:a,tags:m.tags}).unwrap().then(()=>{s()});if(e===u.modelVersion)return f.length>0&&await Promise.all(f.map(I=>j({projectId:d,modelId:`${o}_${c}`,tagName:I}).unwrap())),S({projectId:d,modelId:`${o}_${c}`,tags:m.tags}).unwrap().then(()=>{s()});throw new Error(`type ${e} is not supported`)},[p,S,v,w,j,i,n,l,o,s,d,t,a,e,b,c]);return g.jsx(W,{...T,children:g.jsxs(F,{width:"100%",flexDirection:"column",children:[g.jsx(Q,{type:e,withoutDelete:e===u.td,isEdit:!0,withoutTitle:!0}),g.jsxs(F,{justifyContent:"flex-end",sx:{gap:"15px"},children:[g.jsx(_,{intent:"secondary",onClick:s,children:"cancel"}),g.jsx(B,{onClick:T.handleSubmit(P),isLoading:r||k||L||G||M||N,children:"save"})]})]})})},ee=h.memo(q),z=(s,t)=>{const e=s.map(i=>i.name),a=Object.keys(t);return e.filter(i=>!a.includes(i))};export{ee as S};
