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