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