import{j as e,d as r,aR as X,T as Z,bB as Y,c as d,aQ as O,r as l,f as ee,A as te,fl as se,dq as y,p as v,dy as ae,dz as ne,aV as B,bA as R}from"./index-CK33qGU_.js";import{F as re}from"./FilterResult-DPWa8YHE.js";import{s as h,S as w}from"./sort-BOLIcXtz.js";import{u as ie}from"./Deprecated-D5xZ0QMJ.js";import{F as oe,K as H,u as le}from"./useFeatureFilters-b9dUmI_5.js";import{F as ce}from"./FeatureFilters-DtwvB_P-.js";import{m as xe}from"./min-Esn8rYAn.js";const pe=(t,c,a=0)=>{const s=t.length,i=a&&a<s?a:s,n=i*c;return{data:t.slice(n-i,n>s?s:n),totalPages:s?Math.ceil(s/i):1}},me={"name (A -> Z)":["name",h.string,w.asc],"name (Z -> A)":["name",h.string,w.desc]},ue=({search:t,onSearchChange:c,typeFilters:a,onTypeFiltersChange:s,types:i,onToggleKey:n,keyFilter:k,sortKey:o,setSortKey:g})=>e.jsx(r,{width:"100%",flexDirection:"column",alignItems:"center",children:e.jsxs(r,{width:"100%",children:[e.jsx(X,{variant:"white",value:t,icon:Z.glass,placeholder:"Find feature",onChange:c}),e.jsx(Y,{maxWidth:"180px",width:"max-content",ml:"15px",variant:"white",isMulti:!0,value:a,options:i,placeholder:"type",onChange:s,noDataMessage:"type all"}),e.jsx(d,{ml:"10px",sx:{label:{div:{bg:"white"}}},children:e.jsx(oe,{icon:Z.target,checked:k===H.label,onChange:n(H.label),children:"Label (target) features only"})}),e.jsx(O,{label:"sort by",labelPosition:"inline",width:"max-content",variant:"white",value:o,ml:"auto",options:Object.keys(me),onChange:g})]})}),q={"10 features":10,"20 features":20,"50 features":50,"100 features":100,"200 features":200,"all features":void 0},de={"name (A -> Z)":["name",h.string,w.asc],"name (Z -> A)":["name",h.string,w.desc]},we=({data:t,renderChild:c,extraActions:a,type:s=y.fg,...i})=>{var M;const[n,k]=l.useState("20 features"),[o,g]=l.useState("name (A -> Z)"),x=q[n]||1,[f,S]=l.useState(1),{isActiveFeatures:V,handleBasket:$,isSwitch:z}=ie(),{dataFiltered:j,types:I,search:A,typeFilters:D,keyFilter:L,onTypeFiltersChange:P,onSearchChange:K,onToggleKey:E,onReset:G}=le(t.features??[],"",t.onlineEnabled,"eventTime"in t?t.eventTime:""),{data:T,totalPages:p}=l.useMemo(()=>pe(j,f,x),[j,x,f]),m=l.useMemo(()=>{const u=de[o];if(u){const[W,_,N]=u;return ee(h(W,_,N),F=>{const C=F.findIndex(te("name","Feature Group"));return C>0?[F[C],...F.filter((he,U)=>C!==U)]:F})(T)}return T},[T,o]),b=((M=t==null?void 0:t.features)==null?void 0:M.length)??0,J=j.length,Q=b!==J;return l.useEffect(()=>{S(1)},[x]),e.jsxs(r,{width:"100%",flexDirection:"column",alignItems:"center",children:[e.jsxs(r,{sx:{...se.stickyHeader},pt:"20px",mt:"-20px",children:[s===y.fg&&e.jsx(ce,{search:A,typeFilters:D,types:I,keyFilter:L,enableStorageConnectorFilter:!1,sortKey:o,setSortKey:g,onToggleKey:E,onSearchChange:K,onTypeFiltersChange:P}),s===y.td&&e.jsx(ue,{search:A,typeFilters:D,types:I,keyFilter:L,sortKey:o,setSortKey:g,onToggleKey:E,onSearchChange:K,onTypeFiltersChange:P}),e.jsxs(r,{width:"100%",mt:"10px",alignItems:"center",children:[e.jsxs(r,{children:[e.jsx(v,{primary:!0,px:"5px",children:xe(x,b)}),e.jsx(v,{children:"features displayed out of"}),e.jsx(v,{primary:!0,px:"5px",children:b}),e.jsx(v,{children:"features"})]}),a&&e.jsx(r,{ml:"10px",children:a}),z&&s===y.fg&&e.jsx(d,{ml:"10px",children:e.jsx(ae,{mode:ne.bulk,possible:m.length>0,tooltipMainText:"Add all features to basket",tooltipSecondaryText:`${m.length} features`,handleClick:$(m,t),inBasket:V(m,t)})}),e.jsx(d,{ml:"auto",sx:{span:{mt:"4px"}},children:e.jsx(O,{variant:"white",value:n,label:"show",labelPosition:"side",options:Object.keys(q),onChange:k})}),p>1&&e.jsx(d,{sx:{span:{marginTop:"4px"}},children:e.jsx(B,{ml:"10px",as:"span",text:"go to page",align:"left",children:e.jsx(R,{variant:"white",disabled:p===1,totalPages:p,currentPage:f,onChange:S})})})]})]}),e.jsxs(r,{sx:{gap:"20px",mt:"10px",mb:"20px",flexDirection:"column",width:"100%"},...i,children:[m.map(u=>e.jsx(d,{children:c({type:s,parent:t,data:u})},u.name)),b>x&&e.jsx(B,{mt:"10px",mb:"10px",as:"span",text:"go to page",align:"left",children:e.jsx(R,{variant:"white",disabled:p===1,totalPages:p,currentPage:f,onChange:S})}),Q&&e.jsx(re,{subject:"features",result:j.length,onReset:G})]})]})};export{we as F};
