import{u as ne,h9 as le,r as i,bW as ce,bx as de,bX as L,t as me,x as M,bG as ue,bH as pe,j as t,L as N,ee as he,q as y,d,F as v,en as fe,eo as xe,h_ as ge,h$ as je,c5 as ve,i0 as A,c6 as Fe}from"./index-DNBEEyYo.js";import{P as we}from"./Panel-LhPx0w--.js";import{s as be}from"./sort-BOLIcXtz.js";import{F as ye}from"./FilterResult-BeVdIco_.js";import{u as Se}from"./Deprecated-DmDD0-tM.js";import{F as Te}from"./FeatureDrawer-BxYJR9c3.js";import{u as Pe}from"./useDrawer-CYePSrCY.js";import{s as Ce,F as Ie}from"./FeatureFilters-DtP7PViD.js";import{u as ke}from"./useFeatureFilters-C5S7nVk2.js";import{u as De}from"./useFeatureGroupView-DPDbQRsB.js";import{u as Ee}from"./useUserPermissions-j5Zhfxzb.js";import"./StatisticsTables-eKzOr7AN.js";import"./randomArrayString---X8tfjV.js";import"./PieChart-CDc3QLRP.js";import"./generateCategoricalChart-BC7jg59_.js";import"./isEqual-Caw4eDkN.js";import"./bump-BmRQ39WQ.js";import"./linear-C3cNlZpH.js";import"./string-cKWu9XK9.js";import"./max-DBeXZoyG.js";import"./BarChart-Bo6mG_3p.js";const Re=(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(A(r[h][m])):r[h][m]})))},tt=()=>{const{id:a,fgId:r,fsId:o}=ne(),{data:e,isLoading:m}=De(+a,+r,+o),{currentData:h}=le(),[c,B]=i.useState(void 0),[F,H]=i.useState("name (A -> Z)"),f=ce(),S=de();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:$,selectedName:T,handleSelectItemByName:P,handleClose:_}=Pe(),u=L(s=>s.featureGroupDataPreview),x=L(s=>s.loading.effects.featureGroupDataPreview.fetch),q=i.useCallback(s=>()=>{S(me(s,M.project.value,{fsId:o,fgId:r,id:a}))},[a,r,o,S]),[C,J]=i.useState(null),W=(s,p)=>{const l=JSON.parse(JSON.stringify(p));l&&(l.features=l.features.filter(({name:b})=>b===s),l.name=s),J(l)},U=i.useCallback(s=>{P(s),W(s,e)},[e,P]),j=i.useMemo(()=>(e==null?void 0:e.features)||[],[e]),w=i.useMemo(()=>{const s=Ce[F];if(s){const[p,l,b]=s;return be(p,l,b)(j.slice())}return j},[j,F]),I=i.useMemo(()=>u?Le(w,u.rows):[],[u,w]),{dataFiltered:n,types:V,search:X,typeFilters:Y,keyFilter:Z,onReset:z,onTypeFiltersChange:Q,onSearchChange:G,onToggleKey:ee}=ke(w,"",e==null?void 0:e.onlineEnabled,e==null?void 0:e.eventTime),{isActiveFeatures:te,handleBasket:se,isSwitch:re}=Se(),g=i.useMemo(()=>Re(n,I),[n,I]),k=j.length,D=n.length,ae=k!==D,{canEdit:oe,isLoading:ie,isDataScientist:E,isFeatureStoreRestricted:R}=Ee();return ue(`${pe.dataPreview} ${e==null?void 0:e.name}`),!e||m?t.jsx(N,{}):t.jsxs(t.Fragment,{children:[t.jsx(Te,{isOpen:!!T&&!!C&&e&&$,fgId:e.id,feature:C,handleToggle:_,projectId:+a,featurestoreId:+o,name:T}),t.jsx(we,{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:!oe||E||R||ie,onClickEdit:q(M.project.featureGroup.edit),onClickRefresh:K,pathnamePostFix:"/data-preview",editRightText:E||R?"Your role is not allowed to perform this action":void 0}),t.jsxs(y,{mt:"10px",gap:"20px",flexDirection:"column",children:[t.jsx(Ie,{search:X,typeFilters:Y,types:V,keyFilter:Z,storageConnectorType:c||(u==null?void 0:u.storage),enableStorageConnectorFilter:(e==null?void 0:e.onlineEnabled)??!0,setStorageConnectorType:B,sortKey:F,setSortKey:H,onToggleKey:ee,onSearchChange:G,onTypeFiltersChange:Q}),!x&&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:g.length}),t.jsx(d,{children:"rows"})]}),re&&t.jsx(v,{ml:"5px",mt:"-3px",children:t.jsx(fe,{mode:xe.bulk,possible:n.length>0,tooltipMainText:"Add all features to basket",tooltipSecondaryText:`${n.length} features`,handleClick:se(n,e),inBasket:te(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(ge,{values:g,columnHeaders:g[0].map(({identifierName:s})=>({identifier:{name:s},cellRender:s===(e==null?void 0:e.eventTime)?je({value:p=>{try{return A(p)}catch{return p}}},O):O})),actions:[{label:"statistics",handler:U}],sx:{table:{height:"fit-content"}}})}),!x&&g.length===0&&t.jsx(ve,{mainText:"No data available"}),x&&t.jsx(N,{}),ae&&!n.length&&!x&&t.jsx(v,{mb:"20px",children:t.jsx(ye,{subject:"features",result:n.length,onReset:z})})]})]})},O=({value:a,isHovered:r})=>t.jsx(v,{sx:{p:"8px",...Fe,maxWidth:"400px",...r&&{overflow:"initial",whiteSpace:"initial",height:"100%"}},children:a});export{tt as default};
