import{aD as y,u as b,r as h,eu as C,ev as E,ew as P,ex as V,W as $,az as A,ey as B,ez as U,eA as z,e0 as u,j as g,bB as O,B as j,aG as R}from"./index-dP1W1_bd.js";import{u as W,a as _}from"./index-DEBSKkGo.js";import{B as H}from"./ButtonWithRole-CF64B_Or.js";import{S as Q}from"./SchematisedTagsForm-DmZAUPYh.js";const q=()=>{const s=y(),{id:t,fsId:e,fgId:a}=b(),[i,d]=h.useState(!1),{currentData:n}=C({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 P(+t,+e,+a,o),s(V.invalidateTags([{type:$.ProjectTags.FeatureGroupTag,id:+a}])),d(!1),"success"},[n,s,a,e,t]),i]},J=({onDone:s,tags:t,type:e=u.fv,tdVersion:a})=>{const{fsId:i,id:d,fvName:n,fvVersion:l,mId:o,vId:c}=b(),T=A({shouldUnregister:!1,defaultValues:{tags:t}}),[p,{isLoading:r}]=B(),[I,{isLoading:M}]=U(),[v,{isLoading:k}]=z(),[x,G]=q(),[F,{isLoading:L}]=W(),[S,{isLoading:D}]=_(),N=h.useCallback(async m=>{const f=K(t,m.tags);if(e===u.fg)return x(m).then(()=>{s()});if(e===u.fv)return f.length>0&&await Promise.all(f.map(w=>I({pId:+d,fsId:+i,id:n,version:+l,tagName:w}).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(w=>S({projectId:d,modelId:`${o}_${c}`,tagName:w}).unwrap())),F({projectId:d,modelId:`${o}_${c}`,tags:m.tags}).unwrap().then(()=>{s()});throw new Error(`type ${e} is not supported`)},[p,F,v,I,S,i,n,l,o,s,d,t,a,e,x,c]);return g.jsx(O,{...T,children:g.jsxs(j,{width:"100%",flexDirection:"column",children:[g.jsx(Q,{type:e,withoutDelete:e===u.td,isEdit:!0,withoutTitle:!0}),g.jsxs(j,{justifyContent:"flex-end",sx:{gap:"15px"},children:[g.jsx(R,{intent:"secondary",onClick:s,children:"cancel"}),g.jsx(H,{onClick:T.handleSubmit(N),isLoading:r||k||G||L||M||D,children:"save"})]})]})})},se=h.memo(J),K=(s,t)=>{const e=s.map(i=>i.name),a=Object.keys(t);return e.filter(i=>!a.includes(i))};export{se as S};
