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

var MultiSmallPolygonMap = function MultiSmallPolygonMap(props) {
  var id = props.id,
      data = props.data,
      _props$pickable = props.pickable,
      pickable = _props$pickable === void 0 ? true : _props$pickable,
      _props$civicColor = props.civicColor,
      civicColor = _props$civicColor === void 0 ? "civicBlue" : _props$civicColor,
      _props$opacity = props.opacity,
      opacity = _props$opacity === void 0 ? 0.7 : _props$opacity,
      _props$getPolygon = props.getPolygon,
      getPolygon = _props$getPolygon === void 0 ? function (f) {
    return f.geometry.coordinates;
  } : _props$getPolygon,
      _props$filled = props.filled,
      filled = _props$filled === void 0 ? true : _props$filled,
      _props$stroked = props.stroked,
      stroked = _props$stroked === void 0 ? true : _props$stroked,
      _props$polygonWidth = props.polygonWidth,
      polygonWidth = _props$polygonWidth === void 0 ? 5 : _props$polygonWidth,
      _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,
      dataRange = props.dataRange,
      colorRange = props.colorRange;
  var colorScale = createColorScale(civicColor, scaleType, dataRange, colorRange);

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

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

    return colorScale();
  };

  var getLineWidth = createSizeScale(polygonWidth);
  return React.createElement(PolygonLayer, {
    key: shortid.generate(),
    id: id,
    data: data,
    pickable: pickable,
    opacity: opacity,
    getPolygon: getPolygon,
    filled: filled,
    getFillColor: getFillColor,
    stroked: stroked,
    getLineColor: getFillColor,
    getLineWidth: getLineWidth,
    lineWidthMinPixels: 1,
    onHover: onHoverSlide,
    onClick: onLayerClick,
    autoHighlight: autoHighlight,
    highlightColor: highlightColor,
    parameters: {
      depthTest: false
    },
    updateTriggers: {
      getFillColor: getFillColor,
      getLineColor: getFillColor
    }
  });
};

MultiSmallPolygonMap.propTypes = {
  id: string.isRequired,
  data: arrayOf(shape({})).isRequired,
  pickable: bool,
  civicColor: string,
  opacity: number,
  getPolygon: func,
  filled: bool,
  stroked: bool,
  polygonWidth: number,
  autoHighlight: bool,
  highlightColor: arrayOf(number),
  onHoverSlide: func,
  onLayerClick: func,
  scaleType: shape({
    color: string
  }),
  fieldName: shape({
    color: string
  }),
  dataRange: arrayOf(string),
  colorRange: arrayOf(arrayOf(number))
};
export default MultiSmallPolygonMap;