import React from "react";
import { PathLayer } from "deck.gl";
import { number, string, bool, func, arrayOf, shape, oneOfType } from "prop-types";
import { createColorScale, updateQuantileScale, updateEqualScale, createSizeScale } from "./createLayers";

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,
      index = props.index;
  var colorScale = createColorScale(civicColor, scaleType, dataRange, colorRange);

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

  if (scaleType && scaleType.color === "quantile") {
    colorScale = 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 = createSizeScale(lineWidth);
  return React.createElement(PathLayer, {
    key: id,
    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: function onHover(info) {
      return onHoverSlide(info, index);
    },
    onClick: onLayerClick,
    updateTriggers: {
      getColor: getColor,
      getWidth: getWidth
    }
  });
};

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