"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 getIconSizeScale = function getIconSizeScale(zoom) {
  return zoom > 11.5 ? 6 : zoom > 10.5 ? 5 : zoom > 9.5 ? 4 : zoom > 8.5 ? 3 : zoom > 7.5 ? 2 : 1;
};

var MultiIconMap = function MultiIconMap(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$getPosition = props.getPosition,
      getPosition = _props$getPosition === void 0 ? function (f) {
    return f.geometry.coordinates;
  } : _props$getPosition,
      iconAtlas = props.iconAtlas,
      iconMapping = props.iconMapping,
      _props$getSizeScale = props.getSizeScale,
      getSizeScale = _props$getSizeScale === void 0 ? getIconSizeScale : _props$getSizeScale,
      _props$getIcon = props.getIcon,
      getIcon = _props$getIcon === void 0 ? function (f) {
    return f.properties.type;
  } : _props$getIcon,
      _props$iconSize = props.iconSize,
      iconSize = _props$iconSize === void 0 ? 10 : _props$iconSize,
      _props$autoHighlight = props.autoHighlight,
      autoHighlight = _props$autoHighlight === void 0 ? true : _props$autoHighlight,
      _props$highlightColor = props.highlightColor,
      highlightColor = _props$highlightColor === void 0 ? [0, 0, 128, 128] : _props$highlightColor,
      onHoverSlide = props.onHoverSlide,
      onLayerClick = props.onLayerClick,
      viewport = props.viewport,
      _props$civicColor = props.civicColor,
      civicColor = _props$civicColor === void 0 ? "civicYellow" : _props$civicColor,
      scaleType = props.scaleType,
      _props$fieldName = props.fieldName,
      fieldName = _props$fieldName === void 0 ? {} : _props$fieldName,
      dataRange = props.dataRange,
      colorRange = props.colorRange;
  var colorScale = (0, _createLayers.createColorScale)(civicColor, scaleType, dataRange, colorRange);

  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 getSize = (0, _createLayers.createSizeScale)(iconSize, scaleType, fieldName);
  var zoom = viewport.zoom;
  var sizeScale = getSizeScale(zoom);
  return _react["default"].createElement(_deck.IconLayer, {
    key: _shortid["default"].generate(),
    id: id,
    data: data,
    pickable: pickable,
    opacity: opacity,
    getPosition: getPosition,
    iconAtlas: iconAtlas,
    iconMapping: iconMapping,
    sizeScale: sizeScale,
    getIcon: getIcon,
    getSize: getSize,
    getColor: getColor,
    autoHighlight: autoHighlight,
    highlightColor: highlightColor,
    onHover: onHoverSlide,
    onClick: onLayerClick
  });
};

MultiIconMap.propTypes = {
  id: _propTypes.string.isRequired,
  data: (0, _propTypes.arrayOf)((0, _propTypes.shape)({})).isRequired,
  pickable: _propTypes.bool,
  civicColor: _propTypes.string,
  opacity: _propTypes.number,
  getPosition: _propTypes.func,
  iconAtlas: _propTypes.string,
  iconMapping: (0, _propTypes.shape)({
    x: _propTypes.number,
    y: _propTypes.number,
    width: _propTypes.number,
    height: _propTypes.number,
    mask: _propTypes.bool
  }),
  getSizeScale: _propTypes.func,
  getIcon: _propTypes.func,
  iconSize: _propTypes.number,
  autoHighlight: _propTypes.bool,
  highlightColor: (0, _propTypes.arrayOf)(_propTypes.number),
  onHoverSlide: _propTypes.func,
  onLayerClick: _propTypes.func,
  scaleType: (0, _propTypes.shape)({
    area: _propTypes.string,
    color: _propTypes.string
  }),
  fieldName: (0, _propTypes.shape)({
    area: _propTypes.string,
    color: _propTypes.string
  }),
  dataRange: (0, _propTypes.arrayOf)(_propTypes.string),
  colorRange: (0, _propTypes.arrayOf)((0, _propTypes.arrayOf)(_propTypes.number)),
  viewport: (0, _propTypes.shape)({})
};
var _default = MultiIconMap;
exports["default"] = _default;