import{u as ie,g4 as ne,r as i,bH as le,bo as ce,bI as L,o as de,q as R,bw as me,bx as ue,j as t,D as M,ee as pe,$ as y,f as d,L as v,en as he,eo as fe,gW as ge,gX as xe,bS as je,gY as O,bT as ve}from"./index-46ma1THH.js";import{P as be}from"./Panel-CnxQ3Lqy.js";import{s as we}from"./sort-BOLIcXtz.js";import{F as Fe}from"./FilterResult-CWV4237e.js";import{u as ye}from"./Deprecated-CcWZugSq.js";import{F as Se}from"./FeatureDrawer-Bk4Fz7M-.js";import{u as Te}from"./useDrawer-CScr3Y0w.js";import{s as Ie,F as Ce}from"./FeatureFilters-BE0wmtut.js";import{u as Pe}from"./useFeatureFilters-DTSd2vm9.js";import{u as ke}from"./useFeatureGroupView-BGqRdiCP.js";import{u as De}from"./useUserPermissions-DiAMkzC6.js";import"./StatisticsTables-C8cLXJBs.js";import"./randomArrayString---X8tfjV.js";import"./generateCategoricalChart-ysjj5Swo.js";import"./bump-BmRQ39WQ.js";import"./linear-Fo8SwKqx.js";import"./string-CFFdVFMV.js";import"./max-DBeXZoyG.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]})))},ze=()=>{const{id:a,fgId:r,fsId:o}=ie(),{data:e,isLoading:m}=ke(+a,+r,+o),{currentData:h}=ne(),[c,$]=i.useState(void 0),[b,A]=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 B=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:K}=Te(),u=L(s=>s.featureGroupDataPreview),g=L(s=>s.loading.effects.featureGroupDataPreview.fetch),J=i.useCallback(s=>()=>{S(de(s,R.project.value,{fsId:o,fgId:r,id:a}))},[a,r,o,S]),[C,W]=i.useState(null),Y=(s,p)=>{const l=JSON.parse(JSON.stringify(p));l&&(l.features=l.features.filter(({name:F})=>F===s),l.name=s),W(l)},_=i.useCallback(s=>{I(s),Y(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,F]=s;return we(p,l,F)(j.slice())}return j},[j,b]),P=i.useMemo(()=>u?Le(w,u.rows):[],[u,w]),{dataFiltered:n,types:q,search:U,typeFilters:V,keyFilter:X,onReset:Z,onTypeFiltersChange:z,onSearchChange:Q,onToggleKey:G}=Pe(w,"",e==null?void 0:e.onlineEnabled,e==null?void 0:e.eventTime),{isActiveFeatures:ee,handleBasket:te,isSwitch:se}=ye(),x=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:K,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:J(R.project.featureGroup.edit),onClickRefresh:B,pathnamePostFix:"/data-preview",editRightText:E?"Your role is not allowed to perform this action":void 0}),t.jsxs(y,{mt:"10px",gap:"20px",flexDirection:"column",children:[t.jsx(Ce,{search:U,typeFilters:V,types:q,keyFilter:X,storageConnectorType:c||(u==null?void 0:u.storage),enableStorageConnectorFilter:(e==null?void 0:e.onlineEnabled)??!0,setStorageConnectorType:$,sortKey:b,setSortKey:A,onToggleKey:G,onSearchChange:Q,onTypeFiltersChange:z}),!g&&t.jsxs(y,{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(y,{ml:"5px",gap:"5px",children:[t.jsx(d,{children:"- last"}),t.jsx(d,{primary:!0,children:x.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&&!!x.length&&!g&&t.jsx(v,{overflow:"auto",sx:{maxHeight:"calc(100vh - 260px)","> div":{width:"100%",margin:"0 auto",borderTop:"none"}},children:t.jsx(ge,{values:x,columnHeaders:x[0].map(({identifierName:s})=>({identifier:{name:s},cellRender:s===(e==null?void 0:e.eventTime)?xe({value:p=>{try{return O(p)}catch{return p}}},N):N})),actions:[{label:"statistics",handler:_}],sx:{table:{height:"fit-content"}}})}),!g&&x.length===0&&t.jsx(je,{mainText:"No data available"}),g&&t.jsx(M,{}),re&&!n.length&&!g&&t.jsx(v,{mb:"20px",children:t.jsx(Fe,{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{ze as default};
