import{u as re,eW as oe,r as i,bI as ie,bp as ne,bK as N,q as le,s as R,bx as ce,by as de,j as t,L as E,dX as ue,B as y,b as c,d as j,e4 as me,e5 as pe,gY as he,bU as fe}from"./index-C1DmWO_C.js";import{P as xe}from"./Panel-Z-sMb6LN.js";import{s as ge}from"./sort-BOLIcXtz.js";import{F as je}from"./FilterResult-BLSGYVa5.js";import{u as be}from"./Deprecated-BQWZLUTP.js";import{F as ve}from"./FeatureDrawer-eOnGtzTH.js";import{u as we}from"./useDrawer-D4MDANxq.js";import{N as Fe}from"./NoData-Y_e6mfNf.js";import{F as ye,s as Se}from"./FeatureFilters-DTS9HN8J.js";import{u as Ie}from"./useFeatureFilters-DdB4Pg89.js";import{u as Ce}from"./useFeatureGroupView-BP_FibV0.js";import{u as Pe}from"./useUserPermissions-BiARnwL4.js";import"./StatisticsTables-gOzf3GUA.js";import"./randomArrayString---X8tfjV.js";import"./generateCategoricalChart-BvxCftXa.js";import"./bump-BOZP-SHu.js";import"./linear-DWGfDWoG.js";import"./string-CFFdVFMV.js";import"./max-DBeXZoyG.js";import"./storage-connector-BuEuJyVA.js";const Te=(a,r)=>r.map(o=>o.filter(({identifierName:e})=>a.map(u=>u.name).includes(e))),ke=(a,r)=>{const[o=[]]=Object.values(r);return o.map((e,u)=>a.map(({name:x})=>({identifierName:x,value:r[x][u]})))},ze=()=>{const{id:a,fgId:r,fsId:o}=re(),{data:e,isLoading:u}=Ce(+a,+r,+o),{currentData:x}=oe(),[m,B]=i.useState(void 0),[b,K]=i.useState("name (A -> Z)"),p=ie(),S=ne();i.useEffect(()=>((async()=>{await p.featureGroupDataPreview.fetch({projectId:+a,featureStoreId:+o,featureGroupId:+r,storage:m})})(),()=>{p.featureGroupDataPreview.clear()}),[a,r,p,m,x,o]);const O=i.useCallback(()=>{p.featureGroupDataPreview.fetch({projectId:+a,featureStoreId:+o,featureGroupId:+r,storage:m})},[p.featureGroupDataPreview,a,o,r,m]),{isOpen:M,selectedName:I,handleSelectItemByName:C,handleClose:A}=we(),d=N(s=>s.featureGroupDataPreview),h=N(s=>s.loading.effects.featureGroupDataPreview.fetch),H=i.useCallback(s=>()=>{S(le(s,R.project.value,{fsId:o,fgId:r,id:a}))},[a,r,o,S]),[P,$]=i.useState(null),J=(s,w)=>{const l=JSON.parse(JSON.stringify(w));l&&(l.features=l.features.filter(({name:F})=>F===s),l.name=s),$(l)},U=i.useCallback(s=>{C(s),J(s,e)},[e,C]),g=i.useMemo(()=>(e==null?void 0:e.features)||[],[e]),v=i.useMemo(()=>{const s=Se[b];if(s){const[w,l,F]=s;return ge(w,l,F)(g.slice())}return g},[g,b]),T=i.useMemo(()=>d?ke(v,d.rows):[],[d,v]),{dataFiltered:n,types:W,search:Y,typeFilters:q,keyFilter:V,onReset:X,onTypeFiltersChange:Z,onSearchChange:_,onToggleKey:z}=Ie(v,"",e==null?void 0:e.onlineEnabled,e==null?void 0:e.eventTime),{isActiveFeatures:Q,handleBasket:G,isSwitch:ee}=be(),f=i.useMemo(()=>Te(n,T),[n,T]),k=g.length,D=n.length,te=k!==D,{canEdit:se,isLoading:ae,isDataScientist:L}=Pe();return ce(`${de.dataPreview} ${e==null?void 0:e.name}`),!e||u?t.jsx(E,{}):t.jsxs(t.Fragment,{children:[t.jsx(ve,{isOpen:!!I&&!!P&&e&&M,fgId:e.id,feature:P,handleToggle:A,projectId:+a,featurestoreId:+o,name:I}),t.jsx(xe,{type:ue.fg,data:e,title:e==null?void 0:e.name,idColor:(e==null?void 0:e.type)==="onDemandFeaturegroupDTO"?"labels.blue":"labels.orange",isEditDisabled:!se||L||ae,onClickEdit:H(R.featureGroup.edit),onClickRefresh:O,pathnamePostFix:"/data-preview",editRightText:L?"Your role is not allowed to perform this action":void 0}),t.jsxs(y,{mt:"10px",gap:"20px",flexDirection:"column",children:[t.jsx(ye,{search:Y,typeFilters:q,types:W,keyFilter:V,storageConnectorType:m||(d==null?void 0:d.storage),enableStorageConnectorFilter:(e==null?void 0:e.onlineEnabled)??!0,setStorageConnectorType:B,sortKey:b,setSortKey:K,onToggleKey:z,onSearchChange:_,onTypeFiltersChange:Z}),!h&&t.jsxs(y,{children:[t.jsx(c,{primary:!0,px:"5px",children:D}),t.jsx(c,{children:"out of"}),t.jsx(c,{primary:!0,px:"5px",children:k}),t.jsx(c,{children:"features displayed"}),t.jsxs(y,{ml:"5px",gap:"5px",children:[t.jsx(c,{children:"- last"}),t.jsx(c,{primary:!0,children:f.length}),t.jsx(c,{children:"rows"})]}),ee&&t.jsx(j,{ml:"5px",mt:"-3px",children:t.jsx(me,{mode:pe.bulk,possible:n.length>0,tooltipMainText:"Add all features to basket",tooltipSecondaryText:`${n.length} features`,handleClick:G(n,e),inBasket:Q(n,e)})})]}),!!n.length&&!!f.length&&!h&&t.jsx(j,{overflow:"auto",sx:{maxHeight:"calc(100vh - 260px)","> div":{width:"100%",margin:"0 auto",borderTop:"none"}},children:t.jsx(he,{values:f,columnHeaders:f[0].map(({identifierName:s})=>({identifier:{name:s},cellRender:De})),actions:[{label:"statistics",handler:U}],sx:{table:{height:"fit-content"}}})}),!h&&f.length===0&&t.jsx(Fe,{mainText:"No data available"}),h&&t.jsx(E,{}),te&&!n.length&&!h&&t.jsx(j,{mb:"20px",children:t.jsx(je,{subject:"features",result:n.length,onReset:X})})]})]})},De=({value:a,isHovered:r})=>t.jsx(j,{sx:{p:"8px",...fe,maxWidth:"400px",...r&&{overflow:"initial",whiteSpace:"initial",height:"100%"}},children:a});export{ze as default};
