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, { PathLayer } from "deck.gl";

var PathMap = function PathMap(props) {
  var viewport = props.viewport,
      data = props.data,
      getColor = props.getColor,
      opacity = props.opacity,
      getPath = props.getPath,
      getWidth = props.getWidth,
      widthScale = props.widthScale,
      rounded = props.rounded,
      autoHighlight = props.autoHighlight,
      highlightColor = props.highlightColor,
      onLayerClick = props.onLayerClick,
      visible = props.visible,
      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: function getCursor() {
      return "crosshair";
    }
  }), React.createElement(PathLayer, {
    id: "path-layer",
    className: "PathMap",
    pickable: true,
    data: data,
    getColor: getColor,
    opacity: opacity,
    getPath: getPath,
    getWidth: getWidth,
    widthScale: widthScale,
    widthMinPixels: 1,
    rounded: rounded,
    autoHighlight: autoHighlight,
    highlightColor: highlightColor,
    onClick: onLayerClick,
    onHover: onHover,
    parameters: {
      depthTest: false
    },
    updateTriggers: {
      instanceColors: getColor
    },
    visible: visible
  })), tooltipRender);
};

PathMap.propTypes = {
  viewport: PropTypes.shape({}),
  data: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
  getColor: PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.number)]),
  opacity: PropTypes.number,
  getPath: PropTypes.func,
  getWidth: PropTypes.oneOfType([PropTypes.func, PropTypes.number]),
  widthScale: PropTypes.number,
  rounded: PropTypes.bool,
  autoHighlight: PropTypes.bool,
  highlightColor: PropTypes.arrayOf(PropTypes.number),
  onLayerClick: PropTypes.func,
  visible: PropTypes.bool,
  tooltipInfo: PropTypes.shape({}),
  x: PropTypes.number,
  y: PropTypes.number,
  onHover: PropTypes.func,
  children: PropTypes.node
};
PathMap.defaultProps = {
  getColor: function getColor() {
    return [0, 0, 0];
  },
  opacity: 0.9,
  getPath: function getPath(d) {
    return d.geometry.coordinates;
  },
  getWidth: function getWidth() {
    return 10;
  },
  widthScale: 1,
  rounded: false,
  autoHighlight: true,
  highlightColor: [0, 0, 128, 191],
  visible: true
};
export default PathMap;