import{r as d,u as J,dE as K,b0 as V,aR as W,l as Z,e3 as ee,gp as te,gq as ae,fY as se,e5 as ie,gr as re,gs as w,gt as E,gu as oe,dB as C,gv as k,x as U,g as I,e as n,b2 as P,aX as ne,aY as ue,j as u,a_ as ce,ce as pe,gw as de,a$ as le}from"./index-d6499a22.js";const ge=()=>{const{id:e,fsId:t,fgId:s}=J(),{data:$}=K(),i=V(),l=W(),[L,c]=Z(),{currentData:N,isFetching:O}=ee(),[F,{isLoading:A}]=te(),[G,{isLoading:B}]=ae(),{handleDelete:y}=d.useContext(se),{currentData:x,isLoading:_}=ie({pId:+e,fsId:+t,fgId:+s},{skip:!$});d.useEffect(()=>{i.schematisedTags.fetch()},[i,e,N,t,s]);const{currentData:r,isFetching:M}=re({pId:+e,fsId:+t,fgId:+s}),q=d.useCallback(async(a,fe,R)=>{let j=s;try{if(R){const{features:o,enabled:m,histograms:S,correlations:h,exactUniqueness:v,expectationSuite:T,type:g,...p}=a,f=await i.featureGroups.create({projectId:+e,featureStoreId:+t,data:{...p,type:g,features:w(o),timeTravelFormat:p.timeTravelFormat[0].toUpperCase(),descStatsEnabled:!!E(o).length,validationType:p.validationType[0].toUpperCase(),eventTime:oe(o),jobs:[],statisticsConfig:{columns:E(o),correlations:h,enabled:m,histograms:S,exactUniqueness:v},...T&&g!==C.ON_DEMAND?{expectationSuite:a.expectationSuite}:{}}});f&&(j=String(f))}else{const{features:o,description:m,enabled:S,histograms:h,correlations:v,exactUniqueness:T,onlineEnabled:g,tags:p,keywords:f,validationType:Y,type:b,expectationSuite:X}=a;a.expectationSuite&&Object.keys(a.expectationSuite).length>1&&(a.expectationSuite.id?await G({id:e,fgId:s,fsId:t,data:a.expectationSuite}).unwrap():await F({id:e,fgId:s,fsId:t,data:a.expectationSuite}).unwrap()),await i.featureGroups.edit({projectId:+e,featureStoreId:+t,featureGroupId:+s,data:{description:m,keywords:f,features:w(o),onlineEnabled:g,tags:p,type:b,validationType:Y[0],prevTags:x.map(({name:z})=>z),statisticsConfig:{columns:E(o),correlations:v,enabled:S,histograms:h,exactUniqueness:T},...X.expectations&&b!==C.ON_DEMAND?{expectationSuite:a.expectationSuite}:{}}})}i(k.invalidateTags([U.ProjectTags.FeatureGroup])),l(I(n.featureGroup.overview,n.project.value,{id:e,fsId:t,fgId:j}))}catch{}},[s,i,l,e,t,x,G,F]),Q=d.useCallback(async()=>{c(),await i.featureGroups.delete({projectId:+e,featureStoreId:+t,featureGroupId:+s}),y(I(n.featureGroup.overview,n.project.value,{id:e,fsId:t,fgId:s})),i(k.invalidateTags([U.ProjectTags.FeatureGroup])),l(I(n.featureGroup.list,n.project.value,{id:e,fsId:t}))},[c,i,e,t,s,y,l]),H=P(a=>a.loading.effects.featureGroups.delete),D=P(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:D||H||O||A||B,isDisabled:D,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:L,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,{})},me=d.memo(ge);export{me as default};
