"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react = _interopRequireDefault(require("react"));

var _deck = _interopRequireWildcard(require("deck.gl"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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); }

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["default"].Children.map(children, function (child) {
    return _react["default"].cloneElement(child, {
      tooltipInfo: tooltipInfo,
      x: x,
      y: y
    });
  });

  var tooltipRender = tooltipInfo && x && y ? tooltip : null;
  return _react["default"].createElement("div", null, _react["default"].createElement(_deck["default"], _extends({
    className: "DeckGL"
  }, viewport, {
    getCursor: function getCursor() {
      return "crosshair";
    }
  }), _react["default"].createElement(_deck.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["default"].shape({}),
  data: _propTypes["default"].arrayOf(_propTypes["default"].shape({})).isRequired,
  getColor: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].arrayOf(_propTypes["default"].number)]),
  opacity: _propTypes["default"].number,
  getPath: _propTypes["default"].func,
  getWidth: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].number]),
  widthScale: _propTypes["default"].number,
  rounded: _propTypes["default"].bool,
  autoHighlight: _propTypes["default"].bool,
  highlightColor: _propTypes["default"].arrayOf(_propTypes["default"].number),
  onLayerClick: _propTypes["default"].func,
  visible: _propTypes["default"].bool,
  tooltipInfo: _propTypes["default"].shape({}),
  x: _propTypes["default"].number,
  y: _propTypes["default"].number,
  onHover: _propTypes["default"].func,
  children: _propTypes["default"].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
};
var _default = PathMap;
exports["default"] = _default;