import{r as d,u as Z,dI as J,b1 as V,aS as W,P as X,e7 as ee,gw as te,gx as ae,g1 as se,e9 as ie,gy as re,gz as P,gA as y,gB as oe,dF as k,gC as F,s as G,c as I,b as n,b3 as $,aY as ne,aZ as ue,j as u,a$ as ce,cf as pe,gD as de,b0 as le}from"./index-ea7817a2.js";const ge=()=>{const{id:e,fsId:t,fgId:s}=Z(),{data:L}=J(),i=V(),l=W(),[U,c]=X(),{currentData:A,isFetching:N}=ee(),[D,{isLoading:O}]=te(),[E,{isLoading:B}]=ae(),{handleDelete:b}=d.useContext(se),{currentData:x,isLoading:M}=ie({pId:+e,fsId:+t,fgId:+s},{skip:!L});d.useEffect(()=>{i.schematisedTags.fetch()},[i,e,A,t,s]);const{currentData:r,isFetching:_}=re({pId:+e,fsId:+t,fgId:+s}),Q=d.useCallback(async(a,fe,z)=>{let w=s;try{if(z){const{features:o,enabled:S,histograms:m,correlations:h,exactUniqueness:v,expectationSuite:T,type:g,...p}=a,f=await i.featureGroups.create({projectId:+e,featureStoreId:+t,data:{...p,type:g,features:P(o),timeTravelFormat:p.timeTravelFormat[0].toUpperCase(),descStatsEnabled:!!y(o).length,validationType:p.validationType[0].toUpperCase(),eventTime:oe(o),jobs:[],statisticsConfig:{columns:y(o),correlations:h,enabled:S,histograms:m,exactUniqueness:v},...T&&g!==k.ON_DEMAND?{expectationSuite:a.expectationSuite}:{}}});f&&(w=String(f))}else{const{features:o,description:S,enabled:m,histograms:h,correlations:v,exactUniqueness:T,onlineEnabled:g,tags:p,keywords:f,validationType:K,type:C,expectationSuite:R}=a;a.expectationSuite&&Object.keys(a.expectationSuite).length>1&&(a.expectationSuite.id?await E({id:e,fgId:s,fsId:t,data:a.expectationSuite}).unwrap():await D({id:e,fgId:s,fsId:t,data:a.expectationSuite}).unwrap()),await i.featureGroups.edit({projectId:+e,featureStoreId:+t,featureGroupId:+s,data:{description:S,keywords:f,features:P(o),onlineEnabled:g,tags:p,type:C,validationType:K[0],prevTags:x.map(({name:Y})=>Y),statisticsConfig:{columns:y(o),correlations:v,enabled:m,histograms:h,exactUniqueness:T},...R.expectations&&C!==k.ON_DEMAND?{expectationSuite:a.expectationSuite}:{}}})}i(F.invalidateTags([G.ProjectTags.FeatureGroup])),i(F.invalidateTags([{type:G.ProjectTags.FeatureGroupKeyword,id:s}])),l(I(n.featureGroup.overview,n.project.value,{id:e,fsId:t,fgId:w}))}catch{}},[s,i,l,e,t,x,E,D]),q=d.useCallback(async()=>{c(),await i.featureGroups.delete({projectId:+e,featureStoreId:+t,featureGroupId:+s}),b(I(n.featureGroup.overview,n.project.value,{id:e,fsId:t,fgId:s})),i(F.invalidateTags([G.ProjectTags.FeatureGroup])),l(I(n.featureGroup.list,n.project.value,{id:e,fsId:t}))},[c,i,e,t,s,b,l]),H=$(a=>a.loading.effects.featureGroups.delete),j=$(a=>a.loading.effects.featureGroups.edit);return ne(`${ue.editFg} - ${r==null?void 0:r.name}`),_||M?u.jsx(ce,{}):r?u.jsxs(u.Fragment,{children:[u.jsx(de,{isEdit:!0,isLoading:j||H||N||O||B,isDisabled:j,submitHandler:Q,onDelete:c,initialData:{...r,tags:x}}),u.jsx(le,{title:`Delete ${r.name} v${r.version}`,secondaryText:"Once you delete a feature group, there is no going back. Please be certain.",isOpen:U,onClose:c,mainButtonProps:{children:`Delete ${r.name} v${r.version}`,onClick:q,"data-test":"delete-feature-group"},secondaryButtonProps:{children:"Back",onClick:c}})]}):u.jsx(pe,{})},Se=d.memo(ge);export{Se as default};
