import React from "react";
import { isElement } from "react-is";
import {
  MAX_LATITUDE,
  MAX_LONGITUDE,
  MIN_LATITUDE,
  MIN_LONGITUDE
} from "../constants.js";
import { BubbleLayer } from "../slots/BubbleLayer.js";
import { ConnectionLayer } from "../slots/ConnectionLayer.js";
import { DotLayer } from "../slots/DotLayer.js";
const narrowDownBounds = (coordinates, initialBounds) => {
  const bounds = [...initialBounds];
  coordinates.forEach(({ latitude, longitude }) => {
    bounds[0] = Math.min(bounds[0], longitude);
    bounds[1] = Math.min(bounds[1], latitude);
    bounds[2] = Math.max(bounds[2], longitude);
    bounds[3] = Math.max(bounds[3], latitude);
  });
  return bounds;
};
const getDataLayersBoundingBox = (children) => {
  let bounds = [
    MAX_LONGITUDE,
    MAX_LATITUDE,
    MIN_LONGITUDE,
    MIN_LATITUDE
  ];
  React.Children.forEach(children, (child) => {
    if (isElement(child)) {
      if (child.type === BubbleLayer || child.type === DotLayer) {
        const data = child.props.data;
        bounds = narrowDownBounds(data, bounds);
      } else if (child.type === ConnectionLayer) {
        const connectionsProps = child.props;
        connectionsProps.data.forEach(({ path }) => {
          bounds = narrowDownBounds(path, bounds);
        });
      }
    }
  });
  return bounds;
};
export {
  getDataLayersBoundingBox
};
//# sourceMappingURL=get-data-layers-bounding-box.js.map
