var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var get_data_layers_bounding_box_exports = {};
__export(get_data_layers_bounding_box_exports, {
  getDataLayersBoundingBox: () => getDataLayersBoundingBox
});
module.exports = __toCommonJS(get_data_layers_bounding_box_exports);
var import_react = __toESM(require("react"));
var import_react_is = require("react-is");
var import_constants = require("../constants.js");
var import_BubbleLayer = require("../slots/BubbleLayer.js");
var import_ConnectionLayer = require("../slots/ConnectionLayer.js");
var import_DotLayer = require("../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 = [
    import_constants.MAX_LONGITUDE,
    import_constants.MAX_LATITUDE,
    import_constants.MIN_LONGITUDE,
    import_constants.MIN_LATITUDE
  ];
  import_react.default.Children.forEach(children, (child) => {
    if ((0, import_react_is.isElement)(child)) {
      if (child.type === import_BubbleLayer.BubbleLayer || child.type === import_DotLayer.DotLayer) {
        const data = child.props.data;
        bounds = narrowDownBounds(data, bounds);
      } else if (child.type === import_ConnectionLayer.ConnectionLayer) {
        const connectionsProps = child.props;
        connectionsProps.data.forEach(({ path }) => {
          bounds = narrowDownBounds(path, bounds);
        });
      }
    }
  });
  return bounds;
};
