import{bf as $,u as x,r as h,d_ as D,d$ as E,e0 as V,e1 as y,O as C,au as U,e2 as A,e3 as O,e4 as _,dq as u,j as g,ba as B,d as j,b6 as R}from"./index-CK33qGU_.js";import{u as q,a as H}from"./index-B4h3z62J.js";import{B as Q}from"./ButtonWithRole-NHXEosto.js";import{S as W}from"./SchematisedTagsForm-BQySjcvw.js";const z=()=>{const s=$(),{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 V(+t,+e,+a,o),s(y.invalidateTags([{type:C.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}=x(),T=U({shouldUnregister:!1,defaultValues:{tags:t}}),[p,{isLoading:r}]=A(),[I,{isLoading:M}]=O(),[v,{isLoading:k}]=_(),[b,L]=z(),[F,{isLoading:G}]=q(),[S,{isLoading:N}]=H(),P=h.useCallback(async m=>{const f=K(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(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,b,c]);return g.jsx(B,{...T,children:g.jsxs(j,{width:"100%",flexDirection:"column",children:[g.jsx(W,{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(Q,{onClick:T.handleSubmit(P),isLoading:r||k||L||G||M||N,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};
