import{r as w,j as c}from"./vendor-react-wBh_31cN.js";import{u as A,F as U}from"./index.esm-CAGtek53.js";import{d4 as C,d5 as B,d6 as O,d7 as R,a4 as _,cg as l,G as H}from"./index-dNe6i2rS.js";import{g as Q,h as W,i as q,j as z}from"./index-DnLCKZiK.js";import{d as J}from"./index-CT6Pb5Ny.js";import{e as K,f as X}from"./index-_Tes9c9v.js";import{B as Y}from"./ButtonWithRole-ruQLmPtQ.js";import{T as Z}from"./TagsForm-B-vwjcyr.js";import{j as ee}from"./vendor-redux-CJZrIb6x.js";import{c as S}from"./vendor-router-D1GqFWiT.js";const te=()=>{const t=ee(),{id:i,fsId:e,fgId:s}=S(),[r,a]=w.useState(!1),{currentData:o}=C({pId:+i,fsId:+e,fgId:+s},{skip:!s});return[w.useCallback(async({tags:g})=>{a(!0);const T=o.map(({name:d})=>d),f=Object.keys(g||{}),m=T.filter(d=>!f.includes(d));return await Promise.allSettled(m.map(async d=>{await B.deleteTag(+i,+e,+s,d)})),await O(+i,+e,+s,g),t(R.invalidateTags([{type:_.ProjectTags.FeatureGroupTag,id:+s}])),a(!1),"success"},[o,t,s,e,i]),r]},se=({onDone:t,tags:i,type:e=l.fv,tdVersion:s})=>{const{fsId:r,id:a,fvName:o,fvVersion:p,mId:g,vId:T,dId:f}=S(),m=w.useRef(void 0),d=A({shouldUnregister:!1,defaultValues:{tags:i}}),[I,{isLoading:y}]=Q(),[v,{isLoading:L}]=W(),[j,{isLoading:N}]=J(),[F,k]=te(),[b,{isLoading:G}]=q(),[x,{isLoading:P}]=z(),[D,{isLoading:V}]=K(),[M,{isLoading:E}]=X(),$=w.useCallback(async u=>{const n=ae(i,u.tags);if(e===l.fg)return F(u).then(()=>{t()});if(e===l.fv)return n.length>0&&await Promise.all(n.map(h=>v({pId:+a,fsId:+r,id:o,version:+p,tagName:h}).unwrap())),I({pId:+a,fsId:+r,id:o,version:+p,tags:u.tags}).unwrap().then(()=>{t()});if(e===l.td)return j({pId:+a,fsId:+r,fvName:o,fvVersion:+p,id:s,tags:u.tags}).unwrap().then(()=>{t()});if(e===l.modelVersion)return n.length>0&&await Promise.all(n.map(h=>x({projectId:a,modelId:`${g}_${T}`,tagName:h}).unwrap())),b({projectId:a,modelId:`${g}_${T}`,tags:u.tags}).unwrap().then(()=>{t()});if(e===l.deployment)return n.length>0&&await Promise.all(n.map(h=>M({projectId:a,id:f,tagName:h}).unwrap())),D({projectId:a,id:f,tags:u.tags}).unwrap().then(()=>{t()});throw new Error(`type ${e} is not supported`)},[I,b,D,j,v,x,M,f,r,o,p,g,t,a,i,s,e,F,T]);return c.jsx(U,{...d,children:c.jsxs("div",{className:"flex w-full flex-col",children:[c.jsx(Z,{type:e,withoutDelete:e===l.td,isEdit:!0,withoutTitle:!0,validateMandatoryTagsRef:m}),c.jsxs("div",{className:"flex justify-end gap-4",children:[c.jsx(H,{variant:"secondary",onClick:t,children:"cancel"}),c.jsx(Y,{onClick:()=>{var n;(((n=m.current)==null?void 0:n.call(m))??!0)&&d.handleSubmit($)()},isLoading:y||N||k||G||L||P||V||E,children:"save"})]})]})})},pe=w.memo(se),ae=(t,i)=>{const e=t.map(r=>r.name),s=Object.keys(i);return e.filter(r=>!s.includes(r))};export{pe as T};
