import { isString } from "lodash-es";
import React from "react";
import { isElement } from "react-is";
import { BubbleLayer } from "../components/BubbleLayer/BubbleLayer.js";
import { ChoroplethLayer } from "../components/ChoroplethLayer/ChoroplethLayer.js";
import { ConnectionLayer } from "../components/ConnectionLayer/ConnectionLayer.js";
import { DotLayer } from "../components/DotLayer/DotLayer.js";
const extractLayersData = (children) => {
  let flattenData = [];
  React.Children.forEach(children, (child) => {
    if (isElement(child)) {
      const layerId = child.props.layerId;
      switch (child.type) {
        case BubbleLayer:
        case DotLayer: {
          const data = child.props.data;
          data.forEach((dataPoint) => {
            const extendedDataPoint = {
              ...dataPoint,
              "layer-name": layerId
            };
            flattenData = flattenData.concat(extendedDataPoint);
          });
          break;
        }
        case ConnectionLayer: {
          const data = child.props.data;
          data.forEach((connection, connectionIndex) => {
            connection.path.forEach((path, pathIndex) => {
              const parsedPath = {
                ...path,
                "connection-name": `connection-${connectionIndex + 1}`,
                "connection-item-index": pathIndex,
                "layer-name": layerId
              };
              flattenData.push(parsedPath);
            });
          });
          break;
        }
        case ChoroplethLayer: {
          const { data, regionAccessor } = child.props;
          data.forEach((dataEntry) => {
            const region = isString(regionAccessor) ? dataEntry[regionAccessor] : regionAccessor(dataEntry);
            const choroplethLayerData = {
              ...dataEntry,
              region,
              "layer-name": layerId
            };
            flattenData.push(choroplethLayerData);
          });
          break;
        }
      }
    }
  });
  return flattenData;
};
export {
  extractLayersData
};
//# sourceMappingURL=extract-layers-data.js.map
