import{u as ne,e7 as le,r as a,b1 as ce,aS as de,dG as ue,b3 as L,c as me,b as N,gT as pe,aY as fe,aZ as ge,j as t,a$ as E,dJ as he,Q as R,g as x,o as w,dL as xe,dM as je,gU as ve}from"./index-ea7817a2.js";import{P as Fe}from"./Panel-041c5d61.js";import{F as we}from"./FilterResult-9d9dd7e5.js";import{u as ye}from"./Deprecated-9bfe2e44.js";import{F as Se}from"./FeatureDrawer-3d4004d7.js";import{N as be}from"./NoData-8733f606.js";import{F as Ce,s as Pe}from"./FeatureFilters-9d528cd7.js";import{u as Ie}from"./useFeatureFilters-c103b717.js";import{u as Te}from"./useFeatureGroupView-80b143cb.js";import{u as ke}from"./useUserPermissions-d2903885.js";import"./CardActionButton-6aa39bc1.js";import"./StatisticsTables-d20123a2.js";import"./generateCategoricalChart-e28fa4a2.js";import"./index-43e7382e.js";import"./index-1c428bf7.js";import"./point-ea70dc51.js";import"./utils-aedc41ca.js";import"./index-8f672200.js";import"./file-utils-a5f053e8.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";const De=(r,n)=>n.map(o=>o.filter(({identifierName:e})=>r.map(j=>j.name).includes(e))),We=()=>{const{id:r,fgId:n,fsId:o}=ne(),{data:e,isLoading:j}=Te(+r,+n,+o),{currentData:M}=le(),[u,O]=a.useState(void 0),[[v],A]=a.useState(["name (A -> Z)"]),m=ce(),y=de();a.useEffect(()=>((async()=>{await m.featureGroupDataPreview.fetch({projectId:+r,featureStoreId:+o,featureGroupId:+n,storage:u})})(),()=>{m.featureGroupDataPreview.clear()}),[r,n,m,u,M,o]);const B=a.useCallback(()=>{m.featureGroupDataPreview.fetch({projectId:+r,featureStoreId:+o,featureGroupId:+n,storage:u})},[m.featureGroupDataPreview,r,o,n,u]),{isOpen:K,selectedName:S,handleSelectItemByName:b,handleClose:$}=ue(),c=L(s=>s.featureGroupDataPreview),p=L(s=>s.loading.effects.featureGroupDataPreview.fetch),H=a.useCallback(s=>()=>{y(me(s,N.project.value,{fsId:o,fgId:n,id:r}))},[r,n,o,y]),[C,J]=a.useState(null),Q=(s,d)=>{const l=JSON.parse(JSON.stringify(d));l&&(l.features=l.features.filter(({name:h})=>h===s),l.name=s),J(l)},U=(s,d)=>{const[l=[]]=Object.values(d);return l.map((h,ie)=>s.map(({name:D})=>({identifierName:D,value:d[D][ie]})))},V=a.useCallback(s=>{b(s),Q(s,e)},[e,b]),f=a.useMemo(()=>(e==null?void 0:e.features)||[],[e]),F=a.useMemo(()=>{const s=Pe[v];if(s){const[d,l,h]=s;return pe(d,l,h)(f.slice())}return f},[f,v]),P=a.useMemo(()=>c?U(F,c.rows):[],[c,F]),{dataFiltered:i,types:Y,search:Z,typeFilters:_,keyFilter:q,onReset:z,onTypeFiltersChange:G,onSearchChange:W,onToggleKey:X}=Ie(F,"",e==null?void 0:e.onlineEnabled,e==null?void 0:e.eventTime),{isActiveFeatures:ee,handleBasket:te,isSwitch:se}=ye(),g=a.useMemo(()=>De(i,P),[i,P]),I=f.length,T=i.length,ae=I!==T,{canEdit:re,isLoading:oe,isDataScientist:k}=ke();return fe(`${ge.dataPreview} ${e==null?void 0:e.name}`),!e||j?t.jsx(E,{}):t.jsxs(t.Fragment,{children:[t.jsx(Se,{isOpen:!!S&&!!C&&e&&K,fgId:e.id,feature:C,handleToggle:$,projectId:+r,featurestoreId:+o,name:S}),t.jsx(Fe,{type:he.fg,data:e,title:e==null?void 0:e.name,idColor:(e==null?void 0:e.type)==="onDemandFeaturegroupDTO"?"labels.blue":"labels.orange",isEditDisabled:!re||k||oe,onClickEdit:H(N.featureGroup.edit),onClickRefresh:B,pathnamePostFix:"/data-preview",editRightText:k?"Your role is not allowed to perform this action":void 0}),t.jsxs(R,{mt:"10px",gap:"20px",flexDirection:"column",children:[t.jsx(Ce,{search:Z,typeFilters:_,types:Y,keyFilter:q,storageConnectorType:u||(c==null?void 0:c.storage),enableStorageConnectorFilter:(e==null?void 0:e.onlineEnabled)??!0,setStorageConnectorType:O,sortKey:v,setSortKey:A,onToggleKey:X,onSearchChange:W,onTypeFiltersChange:G}),!p&&t.jsxs(R,{children:[t.jsx(x,{primary:!0,px:"5px",children:T}),t.jsx(x,{children:"out of"}),t.jsx(x,{primary:!0,px:"5px",children:I}),t.jsx(x,{children:"features displayed"}),se&&t.jsx(w,{ml:"5px",mt:"-3px",children:t.jsx(xe,{mode:je.bulk,possible:i.length>0,tooltipMainText:"Add all features to basket",tooltipSecondaryText:`${i.length} features`,handleClick:te(i,e),inBasket:ee(i,e)})})]}),!!i.length&&!!g.length&&!p&&t.jsx(w,{overflow:"auto",sx:{maxHeight:"calc(100vh - 260px)","> div":{width:"100%",margin:"0 auto",borderTop:"none"}},children:t.jsx(ve,{values:g,columnHeaders:g[0].map(({identifierName:s})=>({identifier:{name:s}})),actions:[{label:"statistics",handler:V}]})}),!p&&g.length===0&&t.jsx(be,{mainText:"No data available"}),p&&t.jsx(E,{}),ae&&!i.length&&!p&&t.jsx(w,{mb:"20px",children:t.jsx(we,{subject:"features",result:i.length,onReset:z})})]})]})};export{We as default};
