"use strict";

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

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _styles = require("@vincent_za/styles");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  ", ";\n  visibility: hidden;\n  position: absolute;\n  padding: 1rem ", ";\n  line-height: 1.1;\n  font-size: ", ";\n  font-family: ", ";\n  text-transform: uppercase;\n  background-color: ", ";\n  color: #D4D9D1;\n  ", ";\n  ", ";\n  border-radius: 2px;\n  white-space: nowrap;\n\n  &::before {\n    content: \"\";\n    position: absolute;\n    border-style: solid;\n    width: 0;\n    height: 0;\n  };\n\n  ", ";\n\n  ", ";\n\n  ", ";\n\n  ", ";\n\n  ", ":hover & {\n    ", "\n    ", "\n    ", "\n    ", "\n    ", "\n  };\n"]);

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

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  ", ";\n  &:hover {\n    z-index: 1\n  };\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) } })); }

// TODO: removed relative for now. cannot have a generic tooltip wrap baked into modals as the relative causes the cog to not be abs left 100%
var TooltipInnerWrap = _styledComponents.default.div(_templateObject(), function (props) {
  return props.isRelative && 'position: relative';
});

var Tooltip = _styledComponents.default.div(_templateObject2(), function (props) {
  return (props.isHidden || props.isTouchDevice) && 'display: none';
}, _styles.REM_UNIT_LG, _styles.REM_FONT_SIZE_SM, _styles.FONT_BOLD, _styles.ARSENIC, function (props) {
  return props.isErrorVariant && "\n    background-color: ".concat(props.variantColor, ";\n    color: ").concat(_styles.WHITE, ";\n  ");
}, function (props) {
  return props.isInfoVariant && "\n    background-color: ".concat(props.variantColor, ";\n    color: ").concat(_styles.WHITE, ";\n  ");
}, function (props) {
  return props.position === 'top' && "\n    bottom: 100%;\n    left: 50%;\n    border-bottom: 2px solid ".concat(props.variantColor, ";\n    margin-bottom: ").concat(_styles.REM_UNIT_MD, ";\n    transform: translateX(-50%);\n  ");
}, function (props) {
  return props.position === 'right' && "\n    left: 100%;\n    top: 50%;\n    border-left: 2px solid ".concat(props.variantColor, ";\n    margin-left: ").concat(_styles.REM_UNIT_MD, ";\n    transform: translateY(-50%);\n\n    &::before {\n      top: 50%;\n      right: 100%;\n      border-width: 6px 6px 6px 0;\n      border-color: transparent ").concat(props.variantColor, " transparent transparent;\n      transform: translateY(-50%);\n    };\n  ");
}, function (props) {
  return props.position === 'bottom' && "\n    top: 100%;\n    left: 50%;\n    border-top: 2px solid ".concat(props.variantColor, ";\n    margin-top: ").concat(_styles.REM_UNIT_MD, ";\n    transform: translateX(-50%);\n\n    &::before {\n      bottom: 100%;\n      left: 50%;\n      border-width: 0 6px 6px 6px;\n      border-color: transparent transparent ").concat(props.variantColor, " transparent;\n      transform: translateX(-50%);\n    };\n  ");
}, function (props) {
  return props.position === 'left' && "\n    right: 100%;\n    top: 50%;\n    border-right: 2px solid ".concat(props.variantColor, ";\n    margin-right: ").concat(_styles.REM_UNIT_MD, ";\n    transform: translateY(-50%);\n\n    &::before {\n      top: 50%;\n      left: 100%;\n      border-width: 6px 0 6px 6px;\n      border-color: transparent transparent transparent ").concat(props.variantColor, ";\n      transform: translateY(-50%);\n    };\n  ");
}, TooltipInnerWrap, function (props) {
  return !props.isDisabled && !props.isHidden && "\n      visibility: visible;\n      transition: margin 0.2s ease-out, visibility 0.4s ease-out;\n      transition-delay: 0.4s;\n    ";
}, function (props) {
  return props.position === 'top' && "margin-bottom: ".concat(_styles.REM_UNIT_LG, ";");
}, function (props) {
  return props.position === 'right' && "margin-left: ".concat(_styles.REM_UNIT_LG, ";");
}, function (props) {
  return props.position === 'bottom' && "margin-top: ".concat(_styles.REM_UNIT_LG, ";");
}, function (props) {
  return props.position === 'left' && "margin-right: ".concat(_styles.REM_UNIT_LG, ";");
});

var TooltipWrap =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(TooltipWrap, _React$PureComponent);

  function TooltipWrap() {
    _classCallCheck(this, TooltipWrap);

    return _possibleConstructorReturn(this, _getPrototypeOf(TooltipWrap).apply(this, arguments));
  }

  _createClass(TooltipWrap, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          isTouchDevice = _this$props.isTouchDevice,
          isInfoVariant = _this$props.isInfoVariant,
          isErrorVariant = _this$props.isErrorVariant,
          isDisabled = _this$props.isDisabled,
          isRelative = _this$props.isRelative,
          position = _this$props.position,
          tooltip = _this$props.tooltip,
          children = _this$props.children,
          className = _this$props.className,
          onClick = _this$props.onClick;
      return _react.default.createElement(TooltipInnerWrap, {
        isRelative: isRelative,
        className: className,
        onClick: onClick
      }, children, _react.default.createElement(Tooltip, {
        isTouchDevice: isTouchDevice,
        isErrorVariant: isErrorVariant,
        isInfoVariant: !isErrorVariant && isInfoVariant,
        isHidden: !tooltip,
        isDisabled: isDisabled,
        variantColor: isErrorVariant ? _styles.SUNSET_ORANGE : isInfoVariant ? _styles.VERY_LIGHT_TANGELO : '#ADCCC8',
        position: position
      }, tooltip));
    }
  }]);

  return TooltipWrap;
}(_react.default.PureComponent);

TooltipWrap.propTypes = {
  isTouchDevice: _propTypes.bool.isRequired,
  isInfoVariant: _propTypes.bool,
  isErrorVariant: _propTypes.bool,
  isDisabled: _propTypes.bool,
  isRelative: _propTypes.bool,
  position: _propTypes.string.isRequired,
  tooltip: _propTypes.string,
  children: _propTypes.node.isRequired,
  onClick: _propTypes.func,
  className: _propTypes.string
};
TooltipWrap.defaultProps = {
  isInfoVariant: false,
  isErrorVariant: false,
  isDisabled: false,
  isRelative: false,
  tooltip: undefined,
  onClick: function onClick() {},
  className: undefined
};
var _default = TooltipWrap;
exports.default = _default;