"use strict";

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

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

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

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

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

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

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

var MultiChoroplethMap = function MultiChoroplethMap(props) {
  var id = props.id,
      data = props.data,
      _props$pickable = props.pickable,
      pickable = _props$pickable === void 0 ? true : _props$pickable,
      _props$opacity = props.opacity,
      opacity = _props$opacity === void 0 ? 0.7 : _props$opacity,
      _props$civicColor = props.civicColor,
      civicColor = _props$civicColor === void 0 ? "thermal" : _props$civicColor,
      _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$lineWidth = props.lineWidth,
      lineWidth = _props$lineWidth === void 0 ? 1 : _props$lineWidth,
      _props$polygonLineCol = props.polygonLineColor,
      polygonLineColor = _props$polygonLineCol === void 0 ? [169, 169, 169] : _props$polygonLineCol,
      _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 ? {
    color: "equal"
  } : _props$scaleType,
      fieldName = 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 choroplethColorScale = (0, _createLayers.createColorScale)(civicColor, scaleType, dataRange, colorRange);

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

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

  var getFillColor = function getFillColor(feature) {
    var fieldNameColor = fieldName.color;
    var value = feature.properties["".concat(fieldNameColor)];
    return value ? choroplethColorScale(value) : [0, 0, 0, 128];
  };

  var getLineColor = function getLineColor() {
    return polygonLineColor;
  };

  var getLineWidth = (0, _createLayers.createSizeScale)(lineWidth);
  return _react["default"].createElement(_deck.GeoJsonLayer, {
    key: _shortid["default"].generate(),
    id: id,
    pickable: pickable,
    data: data,
    opacity: opacity,
    getPolygon: getPolygon,
    filled: filled,
    getFillColor: getFillColor,
    stroked: stroked,
    getLineColor: getLineColor,
    getLineWidth: getLineWidth,
    lineWidthMinPixels: 1,
    lineWidthScale: 1,
    lineJointRounded: false,
    extruded: false,
    onHover: function onHover(info) {
      return onHoverSlide(info, index);
    },
    onClick: onLayerClick,
    autoHighlight: autoHighlight,
    highlightColor: highlightColor,
    parameters: {
      depthTest: false
    },
    updateTriggers: {
      getFillColor: getFillColor,
      getLineColor: getLineColor,
      getLineWidth: getLineWidth
    }
  });
};

MultiChoroplethMap.propTypes = {
  id: _propTypes.string.isRequired,
  data: (0, _propTypes.arrayOf)((0, _propTypes.shape)({})).isRequired,
  pickable: _propTypes.bool,
  civicColor: _propTypes.string,
  opacity: _propTypes.number,
  getPolygon: _propTypes.func,
  filled: _propTypes.bool,
  stroked: _propTypes.bool,
  lineWidth: _propTypes.number,
  polygonLineColor: (0, _propTypes.arrayOf)(_propTypes.number),
  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
  }).isRequired,
  dataRange: (0, _propTypes.arrayOf)(_propTypes.string),
  colorRange: (0, _propTypes.arrayOf)((0, _propTypes.arrayOf)(_propTypes.number)),
  index: _propTypes.number
};
var _default = MultiChoroplethMap;
exports["default"] = _default;