"use strict";

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

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

var _core = require("@emotion/core");

var _lodash = require("lodash");

var _window = _interopRequireDefault(require("global/window"));

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

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  font-family: Helvetica, Arial, sans-serif;\n  font-size: 14px;\n  position: absolute;\n  padding: 4px;\n  margin: 8px;\n  background: rgba(0, 0, 0, 0.75);\n  color: #ffffff;\n  max-width: 250px;\n  z-index: 9;\n  pointer-events: none;\n"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var tooltip = (0, _core.css)(_templateObject());

var MapTooltip = function MapTooltip(props) {
  var tooltipInfo = props.tooltipInfo,
      x = props.x,
      y = props.y,
      formatPrimaryField = props.formatPrimaryField,
      formatSecondaryField = props.formatSecondaryField,
      primaryName = props.primaryName,
      primaryField = props.primaryField,
      secondaryName = props.secondaryName,
      secondaryField = props.secondaryField,
      isHex = props.isHex;
  var xPosition = x < (0, _lodash.get)(_window["default"], "innerWidth", 1000) * 0.66 ? x : x - (0, _lodash.get)(_window["default"], "innerWidth", 1000) * 0.1;
  var yPostition = y < 375 ? y : y - 50;

  var getProperty = function getProperty(property, formatFunction) {
    if (formatFunction) {
      return formatFunction(property);
    }

    return property;
  };

  return (0, _core.jsx)("div", {
    css: tooltip,
    style: {
      left: xPosition,
      top: yPostition
    }
  }, primaryName && (0, _core.jsx)("div", null, "".concat(primaryName, ": ").concat(getProperty(tooltipInfo.properties[primaryField], formatPrimaryField))), secondaryName && (0, _core.jsx)("div", null, "".concat(secondaryName, ": ").concat(getProperty(tooltipInfo.properties[secondaryField], formatSecondaryField))), isHex && (0, _core.jsx)("div", null, (0, _core.jsx)("div", null, "elevation: ", tooltipInfo.elevationValue), (0, _core.jsx)("div", null, "coordinates: ", tooltipInfo.centroid.join(", "))));
};

MapTooltip.propTypes = {
  tooltipInfo: _propTypes["default"].shape({}),
  x: _propTypes["default"].number,
  y: _propTypes["default"].number,
  formatPrimaryField: _propTypes["default"].func,
  formatSecondaryField: _propTypes["default"].func,
  primaryName: _propTypes["default"].string,
  primaryField: _propTypes["default"].string,
  secondaryName: _propTypes["default"].string,
  secondaryField: _propTypes["default"].string,
  isHex: _propTypes["default"].bool
};
MapTooltip.defaultProps = {
  formatPrimaryField: null,
  formatSecondaryField: null
};
var _default = MapTooltip;
exports["default"] = _default;