"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("react"),v=d=>{const{mapType:f}=d;return f=="POINTS_MAP"?D(d):g(d)},D=d=>{const{children:f,data:e,multipleMeasures:o,aggregationFormula:i}=d,s={locationsData:[],nationalData:{},measures:[],measureLabelMap:{}},l=e.meta.fields.findIndex((r,a)=>a>2&&!r.startsWith("_")),n=[];if(e&&e.data&&e.meta.fields&&e.meta.fields.length>=2){e.data.forEach(a=>{const t={label:a[e.meta.fields[0]],lat:a[e.meta.fields[1]],lng:a[e.meta.fields[2]],value:a[e.meta.fields[l]]||1,measure:e.meta.fields[l]},u={};if(o&&!s.measures.includes(e.meta.fields[l])&&s.measures.push(e.meta.fields[l]),e.meta.fields.length>l){t.children=[];for(let m=l+1;m<=e.meta.fields.length;m++){const p=e.meta.fields[m],c=a[e.meta.fields[m]];if(p){if(p.trim().startsWith("_"))u[p]=c;else if(c!=null)if(o){const b={label:a[e.meta.fields[0]],value:c,measure:e.meta.fields[m]};b.variables=u,n.push(b),s.measures.includes(e.meta.fields[m])||s.measures.push(e.meta.fields[m])}else t.children.push({label:e.meta.fields[m],value:c})}}}t.variables=u,n.push(t)});const r=[];n.forEach(a=>{let t=r.find(u=>u.label==a.label);t?i=="COUNT"?++t.value:i=="SUM"&&(t.value+=a.value):(t={label:a.label,value:i=="COUNT"?1:a.value?a.value:0},r.push(t))}),s.pointsData=n,s.locationsData=r,s.nationalData.value=0}return h.Children.map(f,r=>h.cloneElement(r,{transformedData:s,appliedFilters:e.appliedFilters}))},g=d=>{const{children:f,data:e,multipleMeasures:o}=d,i={locationsData:[],nationalData:{},measures:[],measureLabelMap:{}},s=e.meta.fields.findIndex((l,n)=>n!=0&&!l.startsWith("_"));return e&&e.data&&e.meta.fields&&e.meta.fields.length>=2&&(e.data.forEach(l=>{const n={label:l[e.meta.fields[0]],value:l[e.meta.fields[s]],measure:e.meta.fields[s]},r={};if(o&&!i.measures.includes(e.meta.fields[s])&&i.measures.push(e.meta.fields[s]),e.meta.fields.length>s){n.children=[];for(let a=s+1;a<=e.meta.fields.length;a++){const t=e.meta.fields[a],u=l[e.meta.fields[a]];if(t)if(t.trim().startsWith("_"))r[t]=u;else if(o){const m={label:l[e.meta.fields[0]],value:u,measure:e.meta.fields[a]};m.variables=r,i.locationsData.push(m),i.measures.includes(e.meta.fields[a])||i.measures.push(e.meta.fields[a])}else n.children.push({label:e.meta.fields[a],value:u})}}n.variables=r,i.locationsData.push(n)}),i.nationalData.value=0),h.Children.map(f,l=>h.cloneElement(l,{transformedData:i,appliedFilters:e.appliedFilters}))};exports.default=v;
