"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

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

var _reactDom = require("react-dom");

var _noop = _interopRequireDefault(require("lodash/noop"));

var _Tooltip = _interopRequireDefault(require("../tooltip/Tooltip"));

var _util = _interopRequireDefault(require("./util"));

var _excluded = ["children", "strict", "getOverflowContainer", "onHiddenBeforeChange", "title"];

function renderTitle(props) {
  if (props) {
    var trigger = props.trigger;

    if (trigger) {
      return _react.Children.map(trigger, function (item) {
        return /*#__PURE__*/(0, _react.cloneElement)(item, {
          ref: null,
          className: null
        });
      });
    }
  }
}

var OverflowTip = function OverflowTip(props) {
  var ref = (0, _react.useRef)(null);
  var defaultGetOverflowContainer = (0, _react.useCallback)(function () {
    var current = ref.current;

    if (current) {
      return (0, _reactDom.findDOMNode)(current);
    }
  }, [ref]);
  var children = props.children,
      strict = props.strict,
      _props$getOverflowCon = props.getOverflowContainer,
      getOverflowContainer = _props$getOverflowCon === void 0 ? defaultGetOverflowContainer : _props$getOverflowCon,
      _props$onHiddenBefore = props.onHiddenBeforeChange,
      onHiddenBeforeChange = _props$onHiddenBefore === void 0 ? _noop["default"] : _props$onHiddenBefore,
      _props$title = props.title,
      title = _props$title === void 0 ? renderTitle : _props$title,
      rest = (0, _objectWithoutProperties2["default"])(props, _excluded);
  var isOverFlow = (0, _react.useCallback)(function () {
    var element = getOverflowContainer();

    if (element) {
      return (0, _util["default"])(element);
    }

    return false;
  }, [getOverflowContainer]);
  var handleHiddenBeforeChange = (0, _react.useCallback)(function (hidden) {
    if (onHiddenBeforeChange(hidden) === false) {
      return false;
    }

    if (hidden) {
      return true;
    }

    return isOverFlow();
  }, [isOverFlow, onHiddenBeforeChange]);
  return /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], (0, _extends2["default"])({}, rest, {
    title: title,
    onHiddenBeforeChange: strict ? onHiddenBeforeChange : handleHiddenBeforeChange,
    ref: ref
  }), children);
};

OverflowTip.displayName = 'OverflowTip';
var _default = OverflowTip;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
