"use strict";

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

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

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

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

var _shortid = _interopRequireDefault(require("shortid"));

var _createLayers = require("./createLayers");

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

var MultiPathMap = function MultiPathMap(props) {
  var id = props.id,
      _props$pickable = props.pickable,
      pickable = _props$pickable === void 0 ? true : _props$pickable,
      data = props.data,
      _props$civicColor = props.civicColor,
      civicColor = _props$civicColor === void 0 ? "civicYellow" : _props$civicColor,
      _props$opacity = props.opacity,
      opacity = _props$opacity === void 0 ? 0.7 : _props$opacity,
      _props$getPath = props.getPath,
      getPath = _props$getPath === void 0 ? function (f) {
    return f.geometry.coordinates;
  } : _props$getPath,
      _props$lineWidth = props.lineWidth,
      lineWidth = _props$lineWidth === void 0 ? 25 : _props$lineWidth,
      _props$rounded = props.rounded,
      rounded = _props$rounded === void 0 ? false : _props$rounded,
      _props$autoHighlight = props.autoHighlight,
      autoHighlight = _props$autoHighlight === void 0 ? true : _props$autoHighlight,
      _props$highlightColor = props.highlightColor,
      highlightColor = _props$highlightColor === void 0 ? [255, 255, 0, 100] : _props$highlightColor,
      onHoverSlide = props.onHoverSlide,
      onLayerClick = props.onLayerClick,
      _props$scaleType = props.scaleType,
      scaleType = _props$scaleType === void 0 ? {} : _props$scaleType,
      _props$fieldName = props.fieldName,
      fieldName = _props$fieldName === void 0 ? {} : _props$fieldName,
      _props$dataRange = props.dataRange,
      dataRange = _props$dataRange === void 0 ? [] : _props$dataRange,
      _props$colorRange = props.colorRange,
      colorRange = _props$colorRange === void 0 ? [] : _props$colorRange;
  var colorScale = (0, _createLayers.createColorScale)(civicColor, scaleType, dataRange, colorRange);

  if (scaleType && scaleType.color === "equal") {
    colorScale = (0, _createLayers.updateEqualScale)(data, colorScale, civicColor, dataRange, colorRange, fieldName);
  }

  if (scaleType && scaleType.color === "quantile") {
    colorScale = (0, _createLayers.updateQuantileScale)(data, colorScale, civicColor, colorRange, fieldName);
  }

  var getColor = function getColor(feature) {
    var fieldNameColor = fieldName.color;

    if (fieldName && fieldNameColor) {
      var value = feature.properties[fieldNameColor];
      return value ? colorScale(value) : [0, 0, 0, 128];
    }

    return colorScale();
  };

  var getWidth = (0, _createLayers.createSizeScale)(lineWidth);
  return _react["default"].createElement(_deck.PathLayer, {
    key: _shortid["default"].generate(),
    id: id,
    pickable: pickable,
    data: data,
    getColor: getColor,
    opacity: opacity,
    getPath: getPath,
    getWidth: getWidth,
    widthScale: 1,
    widthMinPixels: 1,
    rounded: rounded,
    autoHighlight: autoHighlight,
    highlightColor: highlightColor,
    onHover: onHoverSlide,
    onClick: onLayerClick,
    updateTriggers: {
      getColor: getColor,
      getWidth: getWidth
    }
  });
};

MultiPathMap.propTypes = {
  id: _propTypes.string.isRequired,
  data: (0, _propTypes.arrayOf)((0, _propTypes.shape)({})).isRequired,
  pickable: _propTypes.bool,
  civicColor: _propTypes.string,
  opacity: _propTypes.number,
  getPath: _propTypes.func,
  lineWidth: _propTypes.number,
  rounded: _propTypes.bool,
  autoHighlight: _propTypes.bool,
  highlightColor: (0, _propTypes.arrayOf)(_propTypes.number),
  onHoverSlide: _propTypes.func,
  onLayerClick: _propTypes.func,
  scaleType: (0, _propTypes.shape)({
    color: _propTypes.string
  }),
  fieldName: (0, _propTypes.shape)({
    color: _propTypes.string
  }),
  dataRange: (0, _propTypes.oneOfType)([(0, _propTypes.arrayOf)(_propTypes.number), (0, _propTypes.arrayOf)(_propTypes.string)]),
  colorRange: (0, _propTypes.arrayOf)((0, _propTypes.arrayOf)(_propTypes.number))
};
var _default = MultiPathMap;
exports["default"] = _default;