import{u as ne,eK as le,r as o,bf as ce,b4 as de,bh as L,o as me,q as N,bb as ue,bc as pe,j as t,L as R,dq as fe,d as E,p as x,c as b,dy as he,dz as ge,g8 as xe,bp as be}from"./index-CK33qGU_.js";import{P as je}from"./Panel-q_vviXAK.js";import{s as ve}from"./sort-BOLIcXtz.js";import{F as we}from"./FilterResult-DPWa8YHE.js";import{u as Fe}from"./Deprecated-D5xZ0QMJ.js";import{F as ye}from"./FeatureDrawer-DIX-DX-2.js";import{u as Se}from"./useDrawer-DHLGKb6N.js";import{N as Ce}from"./NoData-CuLyR2Bg.js";import{F as Ie,s as Pe}from"./FeatureFilters-DtwvB_P-.js";import{u as Te}from"./useFeatureFilters-b9dUmI_5.js";import{u as ke}from"./useFeatureGroupView-CYNDCcvd.js";import{u as De}from"./useUserPermissions-CGy0I-II.js";import"./CardActionButton-DcsFpjJz.js";import"./useDownload-hrjXceJg.js";import"./useProject-BzBQtp4J.js";import"./length-fOfC3W0h.js";import"./StatisticsTables-CBsa7eUJ.js";import"./randomArrayString---X8tfjV.js";import"./generateCategoricalChart-q6giuYur.js";import"./bump-BOZP-SHu.js";import"./linear-DWGfDWoG.js";import"./string-CFFdVFMV.js";import"./max-DBeXZoyG.js";import"./storage-connector-BuEuJyVA.js";import"./FileUploaderButton-Bppadu35.js";import"./dumbPluralize-CcxDsNiu.js";const Le=(a,r)=>r.map(i=>i.filter(({identifierName:e})=>a.map(j=>j.name).includes(e))),ot=()=>{const{id:a,fgId:r,fsId:i}=ne(),{data:e,isLoading:j}=ke(+a,+r,+i),{currentData:O}=le(),[m,K]=o.useState(void 0),[v,M]=o.useState("name (A -> Z)"),u=ce(),F=de();o.useEffect(()=>((async()=>{await u.featureGroupDataPreview.fetch({projectId:+a,featureStoreId:+i,featureGroupId:+r,storage:m})})(),()=>{u.featureGroupDataPreview.clear()}),[a,r,u,m,O,i]);const B=o.useCallback(()=>{u.featureGroupDataPreview.fetch({projectId:+a,featureStoreId:+i,featureGroupId:+r,storage:m})},[u.featureGroupDataPreview,a,i,r,m]),{isOpen:H,selectedName:y,handleSelectItemByName:S,handleClose:A}=Se(),c=L(s=>s.featureGroupDataPreview),p=L(s=>s.loading.effects.featureGroupDataPreview.fetch),$=o.useCallback(s=>()=>{F(me(s,N.project.value,{fsId:i,fgId:r,id:a}))},[a,r,i,F]),[C,q]=o.useState(null),J=(s,d)=>{const l=JSON.parse(JSON.stringify(d));l&&(l.features=l.features.filter(({name:g})=>g===s),l.name=s),q(l)},V=(s,d)=>{const[l=[]]=Object.values(d);return l.map((g,ie)=>s.map(({name:D})=>({identifierName:D,value:d[D][ie]})))},z=o.useCallback(s=>{S(s),J(s,e)},[e,S]),f=o.useMemo(()=>(e==null?void 0:e.features)||[],[e]),w=o.useMemo(()=>{const s=Pe[v];if(s){const[d,l,g]=s;return ve(d,l,g)(f.slice())}return f},[f,v]),I=o.useMemo(()=>c?V(w,c.rows):[],[c,w]),{dataFiltered:n,types:U,search:W,typeFilters:Y,keyFilter:Z,onReset:_,onTypeFiltersChange:Q,onSearchChange:X,onToggleKey:G}=Te(w,"",e==null?void 0:e.onlineEnabled,e==null?void 0:e.eventTime),{isActiveFeatures:ee,handleBasket:te,isSwitch:se}=Fe(),h=o.useMemo(()=>Le(n,I),[n,I]),P=f.length,T=n.length,ae=P!==T,{canEdit:re,isLoading:oe,isDataScientist:k}=De();return ue(`${pe.dataPreview} ${e==null?void 0:e.name}`),!e||j?t.jsx(R,{}):t.jsxs(t.Fragment,{children:[t.jsx(ye,{isOpen:!!y&&!!C&&e&&H,fgId:e.id,feature:C,handleToggle:A,projectId:+a,featurestoreId:+i,name:y}),t.jsx(je,{type:fe.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:$(N.featureGroup.edit),onClickRefresh:B,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:W,typeFilters:Y,types:U,keyFilter:Z,storageConnectorType:m||(c==null?void 0:c.storage),enableStorageConnectorFilter:(e==null?void 0:e.onlineEnabled)??!0,setStorageConnectorType:K,sortKey:v,setSortKey:M,onToggleKey:G,onSearchChange:X,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(b,{ml:"5px",mt:"-3px",children:t.jsx(he,{mode:ge.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&&!!h.length&&!p&&t.jsx(b,{overflow:"auto",sx:{maxHeight:"calc(100vh - 260px)","> div":{width:"100%",margin:"0 auto",borderTop:"none"}},children:t.jsx(xe,{values:h,columnHeaders:h[0].map(({identifierName:s})=>({identifier:{name:s},cellRender:Ne})),actions:[{label:"statistics",handler:z}],sx:{table:{height:"fit-content"}}})}),!p&&h.length===0&&t.jsx(Ce,{mainText:"No data available"}),p&&t.jsx(R,{}),ae&&!n.length&&!p&&t.jsx(b,{mb:"20px",children:t.jsx(we,{subject:"features",result:n.length,onReset:_})})]})]})},Ne=({value:a,isHovered:r})=>t.jsx(b,{sx:{p:"8px",...be,maxWidth:"400px",...r&&{overflow:"initial",whiteSpace:"initial",height:"100%"}},children:a});export{ot as default};
