"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("react/jsx-runtime"),N=require("react"),S=require("semantic-ui-react"),W=require("./BigNumberItem.js"),X=require("../utils/parseUtils.js"),ee=require("lodash"),te=G=>{const{group:o,app:r,parent:i,nColumns:_,height:T,blockName:m,measures:d,dimension1:n,dimension2:y,data:s,numberFontSize:B,backgroundColor:M,numberColor:k,labelColor:q,unselectedBackgroundColor:L,unselectedNumberColor:P,unselectedLabelColor:O,labelFontSize:D,intl:U,onUnSetFilter:g,onSetFilter:a,appliedFilters:h,hasParentFilters:b,effectiveFilter:re,parentAppliedFilters:f,sort:w,order:z,showZeroValues:K}=G,u=d[r]?Object.keys(d[r]).find(e=>d[r][e].selected):null,x=m,[F,v]=N.useState([]),Y=d[r]&&d[r].format?d[r].format:{style:"percent",minimumFractionDigits:1,maximumFractionDigits:1},Z=(e,t)=>{const l=e[u],c=t[u],A=z==="asc"?1:-1;if(w==="alpha"){const I=C(e.value)||"",R=C(t.value)||"";return A*I.localeCompare(R)}else{const I=parseFloat(l)||0,R=parseFloat(c)||0;return A*(I-R)}},C=e=>{var l;if(!s||!s.metadata||!s.metadata.types)return null;const t=s.metadata.types.filter(c=>c.dimension==n);return t&&t.length>0?(l=t[0].items.filter(c=>c.code==e)[0])==null?void 0:l.value:null},$=N.useRef(ee.debounce((e,t)=>{e.length==0?(a({app:r,group:o,parent:i,param:t,value:[]}),g({app:r,group:m,parent:i,param:t})):(a({app:r,group:o,param:t,parent:i,value:[...e]}),a({app:r,group:m,param:t,parent:i,value:[...e]}))},400)).current,H=(e,t)=>{if(b&&(!f||f.length===0))return;let l=[...F];l.includes(e)?l=l.filter(c=>c!==e):l.push(e),v(l),$(l,t)},E=s.children.filter(e=>K==="true"?e[u]!==null&&e[u]!==void 0:e[u]&&e[u]>0).sort(Z);N.useEffect(()=>{a({app:r,group:o,param:n,value:[Number.MIN_SAFE_INTEGER]}),g({app:r,group:m,parent:i,param:n})},[]),s.children.map(e=>e.value);const j=E.map(e=>e.value);N.useEffect(()=>{const e=h?h.filter(t=>!j.includes(t)):[];if(b&&f.length==0)console.log(m,"RESETING FILTER; PARENT IS EMPTY"),a({app:r,group:o,param:n,value:[Number.MIN_SAFE_INTEGER]}),g({app:r,group:x,param:n}),v([]);else if(e.length>0){const t=h.filter(l=>j.indexOf(l)>-1);t.length==0?(v([]),a({app:r,group:o,param:n,value:[Number.MIN_SAFE_INTEGER]}),g({app:r,group:x,param:n})):(a({app:r,group:o,param:n,value:t}),a({app:r,group:x,parent:i,param:n,value:t}))}else v(h)},[s]);const J=F?F.length:0,Q=E?E.length:0,V=b&&(!f||f.length===0);return n==null?p.jsx("h2",{children:"Select a dimension to start configuring the component"}):p.jsx(S.Container,{fluid:!0,style:{padding:"0px",margin:"0px",height:`${T}px`},children:p.jsxs(S.Grid,{fluid:!0,celled:!0,stackable:!0,columns:_,style:{border:"1px solid #EEE"},children:[p.jsx(S.Grid.Row,{children:p.jsxs(S.Grid.Column,{width:16,textAlign:"right",children:["Selected    ",J,"/",Q]})}),s.children&&E.map((e,t)=>p.jsx(W.BigNumberItem,{idx:t,child:e,isDisabled:V,selectedKey:u,appliedFilters:F,dimension1:n,dimension2:y,app:r,group:o,parent:i,blockName:m,hasParentFilters:b,onSetFilter:l=>{},handleClick:()=>H(e.value,e.type),onUnSetFilter:g,intl:U,numberFontSize:B,labelFontSize:D,backgroundColor:M,numberColor:k,labelColor:q,unselectedBackgroundColor:L,unselectedNumberColor:P,unselectedLabelColor:O,formatObject:Y,decode:X.decode,getLabel:C},t))]})})};exports.default=te;
