import{u as ne,e3 as le,r as a,b0 as ce,aR as de,dC as ue,b2 as R,g as me,e as L,gR as pe,aX as fe,aY as ge,j as t,a_ as N,dF as he,a as E,f as x,O as w,dH as xe,dI as je,gS as ve}from"./index-d6499a22.js";import{P as Fe}from"./Panel-b19e8cc0.js";import{F as we}from"./FilterResult-550b3b9f.js";import{u as ye}from"./Deprecated-ec8916ed.js";import{F as Se}from"./FeatureDrawer-bd460a1c.js";import{N as be}from"./NoData-789df290.js";import{F as Ie,s as Ce}from"./FeatureFilters-d7ede7cc.js";import{u as Pe}from"./useFeatureFilters-659d6dec.js";import{u as Te}from"./useFeatureGroupView-0bc6732c.js";import{u as ke}from"./useUserPermissions-3851a25d.js";import"./CardActionButton-ccf1bc35.js";import"./StatisticsTables-f4036ad4.js";import"./generateCategoricalChart-1633db29.js";import"./index-ddf2d065.js";import"./index-038a72d6.js";import"./point-ea70dc51.js";import"./utils-2cbbb028.js";import"./index-da50fbe6.js";import"./file-utils-b5704e1c.js";import"./useCurrentProject-b23444be.js";import"./useProject-0d0fdeb3.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:O}=le(),[u,M]=a.useState(void 0),[[v],B]=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,O,o]);const H=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:A}=ue(),c=R(s=>s.featureGroupDataPreview),p=R(s=>s.loading.effects.featureGroupDataPreview.fetch),$=a.useCallback(s=>()=>{y(me(s,L.project.value,{fsId:o,fgId:n,id:r}))},[r,n,o,y]),[I,J]=a.useState(null),Y=(s,d)=>{const l=JSON.parse(JSON.stringify(d));l&&(l.features=l.features.filter(({name:h})=>h===s),l.name=s),J(l)},_=(s,d)=>{const[l=[]]=Object.values(d);return l.map((h,ie)=>s.map(({name:D})=>({identifierName:D,value:d[D][ie]})))},U=a.useCallback(s=>{b(s),Y(s,e)},[e,b]),f=a.useMemo(()=>(e==null?void 0:e.features)||[],[e]),F=a.useMemo(()=>{const s=Ce[v];if(s){const[d,l,h]=s;return pe(d,l,h)(f.slice())}return f},[f,v]),C=a.useMemo(()=>c?_(F,c.rows):[],[c,F]),{dataFiltered:i,types:V,search:X,typeFilters:Z,keyFilter:q,onReset:z,onTypeFiltersChange:Q,onSearchChange:W,onToggleKey:G}=Pe(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,C),[i,C]),P=f.length,T=i.length,ae=P!==T,{canEdit:re,isLoading:oe,isDataScientist:k}=ke();return fe(`${ge.dataPreview} ${e==null?void 0:e.name}`),!e||j?t.jsx(N,{}):t.jsxs(t.Fragment,{children:[t.jsx(Se,{isOpen:!!S&&!!I&&e&&K,fgId:e.id,feature:I,handleToggle:A,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:$(L.featureGroup.edit),onClickRefresh:H,pathnamePostFix:"/data-preview",editRightText:k?"Your role is not allowed to perform this action":void 0}),t.jsxs(E,{mt:"10px",gap:"20px",flexDirection:"column",children:[t.jsx(Ie,{search:X,typeFilters:Z,types:V,keyFilter:q,storageConnectorType:u||(c==null?void 0:c.storage),enableStorageConnectorFilter:(e==null?void 0:e.onlineEnabled)??!0,setStorageConnectorType:M,sortKey:v,setSortKey:B,onToggleKey:G,onSearchChange:W,onTypeFiltersChange:Q}),!p&&t.jsxs(E,{children:[t.jsx(x,{primary:!0,px:"5px",children:T}),t.jsx(x,{children:"out of"}),t.jsx(x,{primary:!0,px:"5px",children:P}),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:U}]})}),!p&&g.length===0&&t.jsx(be,{mainText:"No data available"}),p&&t.jsx(N,{}),ae&&!i.length&&!p&&t.jsx(w,{mb:"20px",children:t.jsx(we,{subject:"features",result:i.length,onReset:z})})]})]})};export{We as default};
