import{j as e,$ as r,b2 as X,C as Z,c3 as Y,L as h,bd as O,r as l,p as ee,A as te,f_ as se,ee as y,f as w,en as ae,eo as ne,bF as $,c2 as B}from"./index-46ma1THH.js";import{F as re}from"./FilterResult-CWV4237e.js";import{s as d,S as v}from"./sort-BOLIcXtz.js";import{u as ie}from"./Deprecated-CcWZugSq.js";import{F as oe,K as R,u as le}from"./useFeatureFilters-DTSd2vm9.js";import{F as ce}from"./FeatureFilters-BE0wmtut.js";import{m as xe}from"./min-C0KmOMTA.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",d.string,v.asc],"name (Z -> A)":["name",d.string,v.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(h,{ml:"10px",sx:{label:{div:{bg:"white"}}},children:e.jsx(oe,{icon:Z.target,checked:k===R.label,onChange:n(R.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})]})}),H={"10 features":10,"20 features":20,"50 features":50,"100 features":100,"200 features":200,"all features":void 0},he={"name (A -> Z)":["name",d.string,v.asc],"name (Z -> A)":["name",d.string,v.desc]},ve=({data:t,renderChild:c,extraActions:a,type:s=y.fg,...i})=>{var E;const[n,k]=l.useState("20 features"),[o,g]=l.useState("name (A -> Z)"),x=H[n]||1,[f,C]=l.useState(1),{isActiveFeatures:_,handleBasket:q,isSwitch:G}=ie(),{dataFiltered:j,types:L,search:T,typeFilters:I,keyFilter:P,onTypeFiltersChange:A,onSearchChange:K,onToggleKey:M,onReset:J}=le(t.features??[],"",t.onlineEnabled,"eventTime"in t?t.eventTime:""),{data:S,totalPages:p}=l.useMemo(()=>pe(j,f,x),[j,x,f]),m=l.useMemo(()=>{const u=he[o];if(u){const[z,N,Q]=u;return ee(d(z,N,Q),F=>{const D=F.findIndex(te("name","Feature Group"));return D>0?[F[D],...F.filter((de,V)=>D!==V)]:F})(S)}return S},[S,o]),b=((E=t==null?void 0:t.features)==null?void 0:E.length)??0,U=j.length,W=b!==U;return l.useEffect(()=>{C(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:T,typeFilters:I,types:L,keyFilter:P,enableStorageConnectorFilter:!1,sortKey:o,setSortKey:g,onToggleKey:M,onSearchChange:K,onTypeFiltersChange:A}),s===y.td&&e.jsx(ue,{search:T,typeFilters:I,types:L,keyFilter:P,sortKey:o,setSortKey:g,onToggleKey:M,onSearchChange:K,onTypeFiltersChange:A}),e.jsxs(r,{width:"100%",mt:"10px",alignItems:"center",children:[e.jsxs(r,{children:[e.jsx(w,{primary:!0,px:"5px",children:xe(x,b)}),e.jsx(w,{children:"features displayed out of"}),e.jsx(w,{primary:!0,px:"5px",children:b}),e.jsx(w,{children:"features"})]}),a&&e.jsx(r,{ml:"10px",children:a}),G&&s===y.fg&&e.jsx(h,{ml:"10px",children:e.jsx(ae,{mode:ne.bulk,possible:m.length>0,tooltipMainText:"Add all features to basket",tooltipSecondaryText:`${m.length} features`,handleClick:q(m,t),inBasket:_(m,t)})}),e.jsx(h,{ml:"auto",sx:{span:{mt:"4px"}},children:e.jsx(O,{variant:"white",value:n,label:"show",labelPosition:"side",options:Object.keys(H),onChange:k})}),p>1&&e.jsx(h,{sx:{span:{marginTop:"4px"}},children:e.jsx($,{ml:"10px",as:"span",text:"go to page",align:"left",children:e.jsx(B,{variant:"white",disabled:p===1,totalPages:p,currentPage:f,onChange:C})})})]})]}),e.jsxs(r,{sx:{gap:"20px",mt:"10px",mb:"20px",flexDirection:"column",width:"100%"},...i,children:[m.map(u=>e.jsx(h,{children:c({type:s,parent:t,data:u})},u.name)),b>x&&e.jsx($,{mt:"10px",mb:"10px",as:"span",text:"go to page",align:"left",children:e.jsx(B,{variant:"white",disabled:p===1,totalPages:p,currentPage:f,onChange:C})}),W&&e.jsx(re,{subject:"features",result:j.length,onReset:J})]})]})};export{ve as F};
