function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import PropTypes from "prop-types";
import React from "react";
import DeckGL, { ScreenGridLayer } from "deck.gl";

var ScreenGridMap = function ScreenGridMap(props) {
  var viewport = props.viewport,
      data = props.data,
      getPosition = props.getPosition,
      opacity = props.opacity,
      colorDomain = props.colorDomain,
      colorRange = props.colorRange,
      cellSizePixels = props.cellSizePixels,
      autoHighlight = props.autoHighlight,
      onLayerClick = props.onLayerClick,
      visible = props.visible,
      gpuAggregation = props.gpuAggregation,
      getSize = props.getSize,
      getWeight = props.getWeight,
      getCursor = props.getCursor,
      aggregation = props.aggregation,
      tooltipInfo = props.tooltipInfo,
      x = props.x,
      y = props.y,
      onHover = props.onHover,
      children = props.children;
  var tooltip = React.Children.map(children, function (child) {
    return React.cloneElement(child, {
      tooltipInfo: tooltipInfo,
      x: x,
      y: y
    });
  });
  var tooltipRender = tooltipInfo && x && y ? tooltip : null;
  return React.createElement("div", null, React.createElement(DeckGL, _extends({
    className: "DeckGL"
  }, viewport, {
    getCursor: getCursor
  }), React.createElement(ScreenGridLayer, {
    id: "screengrid-layer",
    className: "ScreenGridMap",
    pickable: true,
    data: data,
    getPosition: getPosition,
    opacity: opacity,
    colorDomain: colorDomain,
    colorRange: colorRange,
    cellSizePixels: cellSizePixels,
    autoHighlight: autoHighlight,
    onClick: onLayerClick,
    updateTriggers: {
      instanceColors: colorRange
    },
    visible: visible,
    gpuAggregation: gpuAggregation,
    getSize: getSize,
    getWeight: getWeight,
    onHover: onHover,
    aggregation: aggregation
  })), tooltipRender);
};

ScreenGridMap.propTypes = {
  viewport: PropTypes.shape({}),
  data: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
  getPosition: PropTypes.func,
  opacity: PropTypes.number,
  colorDomain: PropTypes.arrayOf(PropTypes.number),
  colorRange: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
  cellSizePixels: PropTypes.number,
  autoHighlight: PropTypes.bool,
  onLayerClick: PropTypes.func,
  visible: PropTypes.bool,
  gpuAggregation: PropTypes.bool,
  getSize: PropTypes.func,
  getWeight: PropTypes.func,
  getCursor: PropTypes.func,
  aggregation: PropTypes.oneOf(["SUM", "MIN", "MEAN", "MAX"]),
  tooltipInfo: PropTypes.shape({}),
  x: PropTypes.number,
  y: PropTypes.number,
  onHover: PropTypes.func,
  children: PropTypes.node
};
ScreenGridMap.defaultProps = {
  getPosition: function getPosition(d) {
    return d.geometry.coordinates;
  },
  opacity: 0.8,
  colorRange: [[255, 255, 204], [161, 218, 180], [65, 182, 196], [34, 94, 168]],
  cellSizePixels: 25,
  autoHighlight: true,
  visible: true,
  gpuAggregation: false,
  getSize: function getSize() {
    return 1;
  },
  getWeight: function getWeight() {
    return 1;
  },
  getCursor: function getCursor() {
    return "crosshair";
  },
  aggregation: "SUM"
};
export default ScreenGridMap;