"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 _d = require("d3");

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

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

var getLineWidthScale = (0, _d.scaleThreshold)().domain([7, 7.5, 8, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.5, 13.5, 14]).range([24, 18, 12, 6.75, 5.75, 4.75, 3.75, 2.75, 1.75, 1.5, 1.25, 1, 0.75, 0.5, 0.25]);

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$lineWidth = props.lineWidth,
      lineWidth = _props$lineWidth === void 0 ? 5 : _props$lineWidth,
      _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,
      index = props.index,
      viewport = props.viewport;
  var colorScale = (0, _createLayers.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 zoom = viewport.zoom;
  var sizeScale = getLineWidthScale(zoom);
  var getLineWidth = (0, _createLayers.createSizeScale)(lineWidth);
  return _react["default"].createElement(_deck.GeoJsonLayer, {
    key: _shortid["default"].generate(),
    id: id,
    data: data,
    pickable: pickable,
    opacity: opacity,
    getPolygon: getPolygon,
    filled: filled,
    getFillColor: getFillColor,
    stroked: stroked,
    getLineColor: getFillColor,
    getLineWidth: getLineWidth,
    lineWidthMinPixels: 1,
    lineWidthScale: sizeScale,
    onHover: function onHover(info) {
      return onHoverSlide(info, index);
    },
    onClick: onLayerClick,
    autoHighlight: autoHighlight,
    highlightColor: highlightColor,
    parameters: {
      depthTest: false
    },
    updateTriggers: {
      getFillColor: getFillColor,
      getLineColor: getFillColor
    }
  });
};

MultiSmallPolygonMap.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,
  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.arrayOf)(_propTypes.string),
  colorRange: (0, _propTypes.arrayOf)((0, _propTypes.arrayOf)(_propTypes.number)),
  index: _propTypes.number,
  viewport: (0, _propTypes.shape)({})
};
var _default = MultiSmallPolygonMap;
exports["default"] = _default;