'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var react = require('@carbon/react');
var PropTypes = require('prop-types');
var classnames = require('classnames');
var iconsReact = require('@carbon/icons-react');
var Settings = require('../../constants/Settings.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var _excluded = ["triggerText", "direction", "align", "renderIcon", "useAutoPositioning", "showIcon", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var iotPrefix = Settings.settings.iotPrefix;

// will remove this method later
var getTooltipMenuOffset = function getTooltipMenuOffset() {
  return {
    top: 0,
    left: 0
  };
};
var Tooltip = function Tooltip(_ref) {
  var _ref$triggerText = _ref.triggerText,
    triggerText = _ref$triggerText === void 0 ? '' : _ref$triggerText,
    _ref$direction = _ref.direction,
    direction = _ref$direction === void 0 ? 'bottom' : _ref$direction,
    _ref$align = _ref.align,
    align = _ref$align === void 0 ? 'center' : _ref$align,
    IconCustomElement = _ref.renderIcon,
    _ref$useAutoPositioni = _ref.useAutoPositioning,
    useAutoPositioning = _ref$useAutoPositioni === void 0 ? false : _ref$useAutoPositioni,
    _ref$showIcon = _ref.showIcon,
    showIcon = _ref$showIcon === void 0 ? true : _ref$showIcon,
    children = _ref.children,
    other = _objectWithoutProperties__default.default(_ref, _excluded);
  var newAlign;
  // This function is to pass the old direction, align property to the new align property since The align and direction props have been merged into the align prop
  if (direction === 'bottom' && align === 'center') {
    newAlign = 'bottom';
  } else if (direction === 'bottom' && align === 'end') {
    newAlign = 'bottom-end';
  } else if (direction === 'top' && align === 'start') {
    newAlign = 'top-start';
  } else if (direction === 'top' && align === 'center') {
    newAlign = 'top';
  } else if (direction === 'top' && align === 'end') {
    newAlign = 'top-end';
  } else if (direction === 'right' && align === 'start') {
    newAlign = 'right-start';
  } else if (direction === 'right' && align === 'center') {
    newAlign = 'right';
  } else if (direction === 'right' && align === 'end') {
    newAlign = 'right-end';
  } else if (direction === 'left' && align === 'start') {
    newAlign = 'left-start';
  } else if (direction === 'left' && align === 'center') {
    newAlign = 'left';
  } else if (direction === 'left' && align === 'end') {
    newAlign = 'left-end';
  } else {
    newAlign = 'bottom-start';
  }
  return /*#__PURE__*/React__namespace.createElement("div", {
    className: classnames__default.default("".concat(iotPrefix, "--tooltip"), _defineProperty__default.default({}, "".concat(iotPrefix, "--tooltip--with-label"), !!(showIcon && triggerText)))
  }, showIcon && triggerText ? triggerText : null, " ", /*#__PURE__*/React__namespace.createElement(react.Tooltip, _extends__default.default({
    label: children,
    align: newAlign,
    autoAlign: useAutoPositioning
  }, other), /*#__PURE__*/React__namespace.createElement("div", null, !showIcon ?
  // No icon
  triggerText :
  // Show icon
  IconCustomElement ? /*#__PURE__*/React__namespace.createElement(IconCustomElement, null) : /*#__PURE__*/React__namespace.createElement(iconsReact.Information, null))));
};
Tooltip.propTypes = _objectSpread(_objectSpread({}, Tooltip.propTypes), {}, {
  triggerText: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.element]),
  direction: PropTypes__default.default.string,
  renderIcon: PropTypes__default.default.node,
  useAutoPositioning: PropTypes__default.default.bool,
  showIcon: PropTypes__default.default.bool
});
Tooltip.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "Tooltip",
  "props": {
    "triggerText": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "element"
        }]
      },
      "required": false
    },
    "direction": {
      "defaultValue": {
        "value": "'bottom'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "align": {
      "defaultValue": {
        "value": "'center'",
        "computed": false
      },
      "required": false
    },
    "useAutoPositioning": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "showIcon": {
      "defaultValue": {
        "value": "true",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "renderIcon": {
      "description": "",
      "type": {
        "name": "node"
      },
      "required": false
    }
  }
};
var Tooltip$1 = Tooltip;

exports.Tooltip = Tooltip;
exports.default = Tooltip$1;
exports.getTooltipMenuOffset = getTooltipMenuOffset;
