"use strict";

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

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

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

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _tslib = require("tslib");

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _raf = _interopRequireDefault(require("raf"));

var _mobx = require("mobx");

var _mobxReact = require("mobx-react");

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

var _isEqual = _interopRequireDefault(require("lodash/isEqual"));

var _isFragment = _interopRequireDefault(require("../../pro/lib/_util/isFragment"));

var _autobind = _interopRequireDefault(require("../../pro/lib/_util/autobind"));

var _focusable = _interopRequireWildcard(require("../../pro/lib/_util/focusable"));

var _utils = require("../../pro/lib/data-set/utils");

var _browser = require("../_util/browser");

var _KeyCode = _interopRequireDefault(require("../_util/KeyCode"));

var _TaskRunner = _interopRequireDefault(require("../_util/TaskRunner"));

var _Popup = _interopRequireDefault(require("./Popup"));

var _EventManager = _interopRequireDefault(require("../_util/EventManager"));

var _enum = require("./enum");

var _TriggerChild = _interopRequireDefault(require("./TriggerChild"));

function isHTMLInputElement(target) {
  return target.tagName.toLowerCase() === 'input';
}

function isButton(target) {
  return target.tagName.toLowerCase() === 'button' || isHTMLInputElement(target) && target.type === 'button';
}

function isPointsEq(a1, a2) {
  return a1[0] === a2[0] && a1[1] === a2[1];
}

function _getPopupClassNameFromAlign(builtinPlacements, prefixCls, align) {
  var points = align.points;
  var found = Object.keys(builtinPlacements).find(function (placement) {
    return {}.hasOwnProperty.call(builtinPlacements, placement) && isPointsEq(builtinPlacements[placement].points, points);
  });
  return found ? "".concat(prefixCls, "-popup-placement-").concat(found) : '';
}

function getAlignFromPlacement(builtinPlacements, placementStr, align) {
  var baseAlign = builtinPlacements[placementStr] || {};
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, baseAlign), align);
}

function getPopupAlign(props) {
  var popupPlacement = props.popupPlacement,
      popupAlign = props.popupAlign,
      builtinPlacements = props.builtinPlacements;

  if (popupPlacement && builtinPlacements) {
    return getAlignFromPlacement(builtinPlacements, popupPlacement, popupAlign);
  }

  return popupAlign;
}

function contains(root, n) {
  if (root) {
    var node = n;

    while (node) {
      if (node === root || root.contains && root.contains(node)) {
        return true;
      }

      node = node.parentNode;
    }
  }

  return false;
}

function isChildrenFunction(fn) {
  return typeof fn === 'function';
}

var Trigger = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Trigger, _Component);

  var _super = (0, _createSuper2["default"])(Trigger);

  function Trigger(props, context) {
    var _this;

    (0, _classCallCheck2["default"])(this, Trigger);
    _this = _super.call(this, props, context);
    _this.focusTime = 0;
    _this.preClickTime = 0;
    _this.animateFrameId = 0;
    (0, _mobx.runInAction)(function () {
      _this.popupHidden = 'popupHidden' in props ? props.popupHidden : props.defaultPopupHidden;
      _this.align = getPopupAlign(props);
    });
    return _this;
  }

  (0, _createClass2["default"])(Trigger, [{
    key: "saveRef",
    value: function saveRef(node) {
      this.popup = node;
    }
  }, {
    key: "setActiveElement",
    value: function setActiveElement(activeElement) {
      var _this2 = this;

      this.activeElement = activeElement;
      var activeElementEvent = (0, _utils.getIf)(this, 'activeElementEvent', function () {
        return new _EventManager["default"]();
      });

      if (activeElement) {
        if (this.relatedTarget) {
          var target = this.target;

          if (target && document.activeElement === document.body) {
            this.activeElement = null;
            target.focus();
          }

          this.relatedTarget = null;
        } else {
          activeElementEvent.clear().setTarget(activeElement).addEventListener('blur', function () {
            var target = _this2.target;

            if (target && document.activeElement === document.body) {
              _this2.setActiveElement(null);

              target.focus();
            }
          }, {
            once: true
          });
        }
      } else {
        activeElementEvent.clear();
      }
    }
  }, {
    key: "getFocusableElements",
    value: function getFocusableElements(elements) {
      this.focusElements = elements;
      var target = this.target,
          activeElement = this.activeElement;

      if (target && activeElement && (!elements || !elements.includes(activeElement))) {
        if (!elements || !elements.length) {
          this.setActiveElement(null);
          target.focus();
        }
      }
    }
  }, {
    key: "renderTriggerChild",
    value: function renderTriggerChild(child) {
      var _this3 = this;

      if (child) {
        if ((0, _isFragment["default"])(child)) {
          var children = child.props.children;
          return _react.Children.map(children, function (fragmentChild) {
            return _this3.renderTriggerChild(fragmentChild);
          });
        }

        if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
          var newChildProps = {
            key: child.key
          };

          if (this.isContextMenuToShow()) {
            newChildProps.onContextMenu = this.handleEvent;
          }

          if (this.isClickToHide() || this.isClickToShow()) {
            newChildProps.onClick = this.handleEvent;
            newChildProps.onMouseDown = this.handleEvent;
          }

          if (this.isMouseEnterToShow()) {
            newChildProps.onMouseEnter = this.handleEvent;
            var mouseEnterDelay = this.props.mouseEnterDelay;

            if (mouseEnterDelay && !this.isMouseLeaveToHide()) {
              newChildProps.onMouseLeave = this.cancelPopupTask;
            }
          }

          if (this.isMouseLeaveToHide()) {
            newChildProps.onMouseLeave = this.handleEvent;
            var mouseLeaveDelay = this.props.mouseLeaveDelay;

            if (mouseLeaveDelay && !this.isMouseEnterToShow()) {
              newChildProps.onMouseEnter = this.cancelPopupTask;
            }
          }

          if (this.isFocusToShow() || this.isBlurToHide()) {
            newChildProps.onFocus = this.handleEvent;
            newChildProps.onBlur = this.handleEvent;
          }

          newChildProps.onKeyDown = this.handleEvent;
          newChildProps.popupHidden = this.popupHidden;
          return /*#__PURE__*/_react["default"].createElement(_TriggerChild["default"], (0, _extends2["default"])({}, newChildProps), child);
        }
      }

      return child;
    }
  }, {
    key: "render",
    value: function render() {
      var _this4 = this;

      var _this$props = this.props,
          children = _this$props.children,
          childrenProps = _this$props.childrenProps;
      var popup = this.getPopup();
      var newChildren = isChildrenFunction(children) ? children(this.renderTriggerChild, childrenProps) : _react.Children.map(children, function (child) {
        return _this4.renderTriggerChild(child);
      });
      return [newChildren, popup];
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      var popupHidden = nextProps.popupHidden;

      if (popupHidden !== this.popupHidden && popupHidden !== undefined) {
        this.popupHidden = popupHidden;
      }

      var newAlign = getPopupAlign(nextProps);

      if (!(0, _isEqual["default"])(this.align, newAlign)) {
        this.align = newAlign;
      }
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this5 = this;

      this.mounted = true;

      if (!(0, _browser.isChrome)() && ((0, _browser.isSafari)() || (0, _browser.isWeChat)())) {
        this.mouseDownEvent = new _EventManager["default"](document).addEventListener('mousedown', function (e) {
          if (!_this5.popupHidden) {
            var target = e.target;

            if (isButton(target)) {
              _this5.relatedTarget = target;
            } else {
              var parent = (0, _focusable.findFocusableParent)(target);

              if (parent && isButton(parent)) {
                _this5.relatedTarget = parent;
              }
            }
          }
        });
      }
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      var popupHidden = this.popupHidden;

      if (this.documentEvent) {
        this.documentEvent.clear();
      }

      if (!popupHidden) {
        var documentEvent = (0, _utils.getIf)(this, 'documentEvent', function () {
          return new _EventManager["default"](typeof window === 'undefined' ? undefined : document);
        });
        documentEvent.addEventListener('scroll', this.handleDocumentScroll, true);

        if ((this.isClickToHide() || this.isContextMenuToShow()) && !this.isBlurToHide()) {
          documentEvent.addEventListener('mousedown', this.handleDocumentMouseDown);
        }
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.cancelPopupTask();

      if (this.documentEvent) {
        this.documentEvent.clear();
      }

      if (this.activeElementEvent) {
        this.activeElementEvent.clear();
      }

      if (this.mouseDownEvent) {
        this.mouseDownEvent.clear();
      }
    }
  }, {
    key: "cancelPopupTask",
    value: function cancelPopupTask() {
      if (this.popupTask) {
        this.popupTask.cancel();
      }
    }
  }, {
    key: "handlePopupKeyDown",
    value: function handlePopupKeyDown(e) {
      var focusTarget = this.focusTarget,
          activeElement = this.activeElement;

      if (activeElement && focusTarget && e.keyCode === _KeyCode["default"].TAB) {
        var focusElements = this.focusElements;
        var shiftKey = e.shiftKey;

        if (focusElements && focusElements.indexOf(activeElement) === (shiftKey ? 0 : focusElements.length - 1)) {
          if (shiftKey) {
            e.preventDefault();
          }

          focusTarget.focus();
        }
      }
    }
  }, {
    key: "handleTargetBlur",
    value: function handleTargetBlur(e, child) {
      var popup = this.popup,
          focusTarget = this.focusTarget;
      var relatedTarget = (0, _browser.isIE)() ? document.activeElement : e.relatedTarget || this.relatedTarget;

      if (popup && relatedTarget && popup.element.contains(relatedTarget)) {
        e.stopPropagation();
        this.setActiveElement(relatedTarget);
        this.currentTriggerChild = child;

        if (!focusTarget) {
          this.focusTarget = e.target;
        }

        return false;
      }

      if (focusTarget) {
        this.focusTarget = null;
        this.setActiveElement(null);
        this.currentTriggerChild = null;

        if (focusTarget !== relatedTarget) {
          this.handleTriggerEvent('Blur', child, e);
        }
      }

      return true;
    }
  }, {
    key: "handleTriggerEvent",
    value: function handleTriggerEvent(eventName, child, e) {
      var handle = this.props["on".concat(eventName)];
      var childHandle = child.props["on".concat(eventName)];

      if (childHandle) {
        childHandle(e);
      }

      if (!e.isDefaultPrevented()) {
        if (handle) {
          handle(e);
        }

        if (!e.isDefaultPrevented()) {
          this["handle".concat(eventName)].call(this, e);
        }
      }
    }
  }, {
    key: "handleEvent",
    value: function handleEvent(eventName, child, e) {
      if (this.isBlurToHide() && eventName === 'Blur' && !this.handleTargetBlur(e, child)) {
        if (!this.target) {
          this.target = e.target;
        }
      } else {
        this.handleTriggerEvent(eventName, child, e);
      }
    }
  }, {
    key: "handlePopupMouseDown",
    value: function handlePopupMouseDown(e) {
      var fix = false;
      var popup = this.popup;
      var popupElement = popup && popup.element;
      var target = e.target;

      if (!e.isDefaultPrevented()) {
        var element = (0, _focusable["default"])(target) ? target : (0, _focusable.findFocusableParent)(target, popupElement);

        if (element) {
          e.stopPropagation();
        } else {
          fix = true;
        }
      } else {
        fix = true;
      }

      if (fix && this.isBlurToHide()) {
        var ownerDocument = target.ownerDocument;

        if (ownerDocument) {
          var activeElement = ownerDocument.activeElement;

          if (activeElement && activeElement !== ownerDocument.body) {
            var el = (0, _reactDom.findDOMNode)(this);

            if (el && el.contains(activeElement)) {
              e.preventDefault();
            }
          }
        }
      }
    }
  }, {
    key: "handlePopupBlur",
    value: function handlePopupBlur(e) {
      if (this.isBlurToHide()) {
        var activeElement = this.activeElement,
            currentTriggerChild = this.currentTriggerChild;

        if (activeElement && currentTriggerChild) {
          this.handleTargetBlur(e, currentTriggerChild);
        }
      }
    }
  }, {
    key: "handleContextMenu",
    value: function handleContextMenu(e) {
      e.preventDefault();
      this.setPopupHidden(false);
    }
  }, {
    key: "handleKeyDown",
    value: function handleKeyDown(e) {
      var tabIntoPopupContent = this.props.tabIntoPopupContent;

      if (!this.popupHidden && tabIntoPopupContent && this.focusElements && e.keyCode === _KeyCode["default"].TAB && !e.shiftKey) {
        var _this$focusElements = (0, _slicedToArray2["default"])(this.focusElements, 1),
            firstFocusElement = _this$focusElements[0];

        if (firstFocusElement) {
          e.preventDefault();
          firstFocusElement.focus();
        }
      }
    }
  }, {
    key: "handleFocus",
    value: function handleFocus() {
      if (this.isFocusToShow()) {
        var focusDelay = this.props.focusDelay;
        this.focusTime = Date.now();
        this.delaySetPopupHidden(false, focusDelay);
      }
    }
  }, {
    key: "handleBlur",
    value: function handleBlur() {
      if (this.isBlurToHide()) {
        var blurDelay = this.props.blurDelay;
        this.delaySetPopupHidden(true, blurDelay);
      }
    }
  }, {
    key: "handleDocumentMouseDown",
    value: function handleDocumentMouseDown(e) {
      if (this.popup) {
        var target = e.target;

        if (!contains((0, _reactDom.findDOMNode)(this), target) && !contains((0, _reactDom.findDOMNode)(this.popup), target)) {
          this.setPopupHidden(true);
        }
      }
    }
  }, {
    key: "handleDocumentScroll",
    value: function handleDocumentScroll(_ref) {
      var target = _ref.target;

      if (this.popup && target !== document && !contains((0, _reactDom.findDOMNode)(this.popup), target)) {
        if (this.animateFrameId) {
          _raf["default"].cancel(this.animateFrameId);
        }

        this.animateFrameId = (0, _raf["default"])(this.forcePopupAlign);
      }
    }
  }, {
    key: "handleMouseDown",
    value: function handleMouseDown() {
      this.preClickTime = Date.now();
    }
  }, {
    key: "handleClick",
    value: function handleClick(e) {
      var popupHidden = this.popupHidden;

      if (this.focusTime) {
        if (Math.abs(this.preClickTime - this.focusTime) < 20) {
          return;
        }

        this.focusTime = 0;
      }

      this.preClickTime = 0;

      if (this.isClickToHide() && !popupHidden || popupHidden && this.isClickToShow()) {
        e.preventDefault();
        this.setPopupHidden(!popupHidden);
      }
    }
  }, {
    key: "handleMouseEnter",
    value: function handleMouseEnter() {
      var mouseEnterDelay = this.props.mouseEnterDelay;
      this.delaySetPopupHidden(false, mouseEnterDelay);
    }
  }, {
    key: "handleMouseLeave",
    value: function handleMouseLeave() {
      var mouseLeaveDelay = this.props.mouseLeaveDelay;
      this.delaySetPopupHidden(true, mouseLeaveDelay);
    }
  }, {
    key: "handlePopupMouseEnter",
    value: function handlePopupMouseEnter(e) {
      this.cancelPopupTask();
      var onPopupMouseEnter = this.props.onPopupMouseEnter;

      if (onPopupMouseEnter) {
        onPopupMouseEnter(e);
      }
    }
  }, {
    key: "handlePopupMouseLeave",
    value: function handlePopupMouseLeave(e) {
      var _this$props2 = this.props,
          mouseLeaveDelay = _this$props2.mouseLeaveDelay,
          onPopupMouseLeave = _this$props2.onPopupMouseLeave;
      this.delaySetPopupHidden(true, mouseLeaveDelay);

      if (onPopupMouseLeave) {
        onPopupMouseLeave(e);
      }
    }
  }, {
    key: "getPopup",
    value: function getPopup() {
      var _this$props3 = this.props,
          prefixCls = _this$props3.prefixCls,
          popupCls = _this$props3.popupCls,
          popupStyle = _this$props3.popupStyle,
          popupClassName = _this$props3.popupClassName,
          onPopupAnimateAppear = _this$props3.onPopupAnimateAppear,
          onPopupAnimateEnter = _this$props3.onPopupAnimateEnter,
          onPopupAnimateLeave = _this$props3.onPopupAnimateLeave,
          onPopupAnimateEnd = _this$props3.onPopupAnimateEnd,
          onPopupAlign = _this$props3.onPopupAlign,
          onPopupMouseEnter = _this$props3.onPopupMouseEnter,
          onPopupMouseLeave = _this$props3.onPopupMouseLeave,
          getPopupStyleFromAlign = _this$props3.getPopupStyleFromAlign,
          _this$props3$getRootD = _this$props3.getRootDomNode,
          getRootDomNode = _this$props3$getRootD === void 0 ? this.getRootDomNode : _this$props3$getRootD,
          transitionName = _this$props3.transitionName,
          getPopupContainer = _this$props3.getPopupContainer,
          forceRender = _this$props3.forceRender;

      if (this.mounted || !getPopupContainer) {
        var hidden = this.popupHidden;

        if (!hidden || this.popup || forceRender) {
          var mouseProps = {
            onMouseEnter: this.isMouseEnterToShow() ? this.handlePopupMouseEnter : onPopupMouseEnter,
            onMouseLeave: this.isMouseLeaveToHide() ? this.handlePopupMouseLeave : onPopupMouseLeave
          };
          return /*#__PURE__*/_react["default"].createElement(_Popup["default"], (0, _extends2["default"])({
            key: "popup",
            ref: this.saveRef,
            transitionName: transitionName,
            className: (0, _classnames["default"])("".concat(prefixCls, "-popup"), popupCls, popupClassName),
            style: popupStyle,
            hidden: hidden,
            align: this.align,
            onAlign: onPopupAlign,
            onMouseDown: this.handlePopupMouseDown,
            onKeyDown: this.handlePopupKeyDown,
            onBlur: this.handlePopupBlur,
            getFocusableElements: this.getFocusableElements,
            getRootDomNode: getRootDomNode,
            onAnimateAppear: onPopupAnimateAppear,
            onAnimateEnter: onPopupAnimateEnter,
            onAnimateLeave: onPopupAnimateLeave,
            onAnimateEnd: onPopupAnimateEnd,
            getStyleFromAlign: getPopupStyleFromAlign,
            getClassNameFromAlign: this.getPopupClassNameFromAlign,
            getPopupContainer: getPopupContainer,
            forceRender: forceRender
          }, mouseProps), this.getPopupContent());
        }
      }
    }
  }, {
    key: "getRootDomNode",
    value: function getRootDomNode() {
      return (0, _reactDom.findDOMNode)(this);
    }
  }, {
    key: "getPopupClassNameFromAlign",
    value: function getPopupClassNameFromAlign(align) {
      var className = [];
      var _this$props4 = this.props,
          popupPlacement = _this$props4.popupPlacement,
          builtinPlacements = _this$props4.builtinPlacements,
          prefixCls = _this$props4.prefixCls,
          getCls = _this$props4.getPopupClassNameFromAlign;

      if (popupPlacement && builtinPlacements) {
        className.push(_getPopupClassNameFromAlign(builtinPlacements, prefixCls, align));
      }

      if (getCls) {
        var cls = getCls(align);

        if (cls) {
          className.push(cls);
        }
      }

      return className.join(' ');
    }
  }, {
    key: "forcePopupAlign",
    value: function forcePopupAlign() {
      if (!this.popupHidden && this.popup) {
        this.popup.forceAlign();
      }
    }
  }, {
    key: "getPopupWrapper",
    value: function getPopupWrapper() {
      if (!this.popupHidden && this.popup) {
        return this.popup.wrapper;
      }
    }
  }, {
    key: "getPopupContent",
    value: function getPopupContent() {
      var _this$props5 = this.props,
          popupContent = _this$props5.popupContent,
          children = _this$props5.children;
      return typeof popupContent === 'function' ? popupContent({
        trigger: children
      }) : popupContent;
    }
  }, {
    key: "popupHiddenBeforeChange",
    value: function popupHiddenBeforeChange(hidden) {
      var _this$props$onPopupHi = this.props.onPopupHiddenBeforeChange,
          onPopupHiddenBeforeChange = _this$props$onPopupHi === void 0 ? _noop["default"] : _this$props$onPopupHi;

      if (onPopupHiddenBeforeChange(hidden) === false) {
        return false;
      } // if (hidden === false) {
      //   return !isEmpty(this.getPopupContent());
      // }


      return true;
    }
  }, {
    key: "setPopupHidden",
    value: function setPopupHidden(hidden) {
      this.cancelPopupTask();

      if (this.popupHidden !== hidden) {
        var _this$props6 = this.props,
            popupHidden = _this$props6.popupHidden,
            _this$props6$onPopupH = _this$props6.onPopupHiddenChange,
            onPopupHiddenChange = _this$props6$onPopupH === void 0 ? _noop["default"] : _this$props6$onPopupH;

        if (this.popupHiddenBeforeChange(hidden) !== false) {
          if (popupHidden === undefined) {
            this.popupHidden = hidden;
          }

          onPopupHiddenChange(hidden);
        }
      }
    }
  }, {
    key: "delaySetPopupHidden",
    value: function delaySetPopupHidden(popupHidden, delay) {
      var _this6 = this;

      this.cancelPopupTask();

      if (delay) {
        (0, _utils.getIf)(this, 'popupTask', function () {
          return new _TaskRunner["default"]();
        }).delay(delay, function () {
          _this6.setPopupHidden(popupHidden);
        });
      } else {
        this.setPopupHidden(popupHidden);
      }
    }
  }, {
    key: "isClickToShow",
    value: function isClickToShow() {
      var _this$props7 = this.props,
          _this$props7$action = _this$props7.action,
          action = _this$props7$action === void 0 ? [] : _this$props7$action,
          _this$props7$showActi = _this$props7.showAction,
          showAction = _this$props7$showActi === void 0 ? [] : _this$props7$showActi;
      return action.indexOf(_enum.Action.click) !== -1 || showAction.indexOf(_enum.ShowAction.click) !== -1;
    }
  }, {
    key: "isContextMenuToShow",
    value: function isContextMenuToShow() {
      var _this$props8 = this.props,
          _this$props8$action = _this$props8.action,
          action = _this$props8$action === void 0 ? [] : _this$props8$action,
          _this$props8$showActi = _this$props8.showAction,
          showAction = _this$props8$showActi === void 0 ? [] : _this$props8$showActi;
      return action.indexOf(_enum.Action.contextMenu) !== -1 || showAction.indexOf(_enum.ShowAction.contextMenu) !== -1;
    }
  }, {
    key: "isClickToHide",
    value: function isClickToHide() {
      var _this$props9 = this.props,
          _this$props9$action = _this$props9.action,
          action = _this$props9$action === void 0 ? [] : _this$props9$action,
          _this$props9$hideActi = _this$props9.hideAction,
          hideAction = _this$props9$hideActi === void 0 ? [] : _this$props9$hideActi;
      return action.indexOf(_enum.Action.click) !== -1 || hideAction.indexOf(_enum.HideAction.click) !== -1;
    }
  }, {
    key: "isMouseEnterToShow",
    value: function isMouseEnterToShow() {
      var _this$props10 = this.props,
          _this$props10$action = _this$props10.action,
          action = _this$props10$action === void 0 ? [] : _this$props10$action,
          _this$props10$showAct = _this$props10.showAction,
          showAction = _this$props10$showAct === void 0 ? [] : _this$props10$showAct;
      return action.indexOf(_enum.Action.hover) !== -1 || showAction.indexOf(_enum.ShowAction.mouseEnter) !== -1;
    }
  }, {
    key: "isMouseLeaveToHide",
    value: function isMouseLeaveToHide() {
      var _this$props11 = this.props,
          _this$props11$action = _this$props11.action,
          action = _this$props11$action === void 0 ? [] : _this$props11$action,
          _this$props11$hideAct = _this$props11.hideAction,
          hideAction = _this$props11$hideAct === void 0 ? [] : _this$props11$hideAct;
      return action.indexOf(_enum.Action.hover) !== -1 || hideAction.indexOf(_enum.HideAction.mouseLeave) !== -1;
    }
  }, {
    key: "isFocusToShow",
    value: function isFocusToShow() {
      var _this$props12 = this.props,
          _this$props12$action = _this$props12.action,
          action = _this$props12$action === void 0 ? [] : _this$props12$action,
          _this$props12$showAct = _this$props12.showAction,
          showAction = _this$props12$showAct === void 0 ? [] : _this$props12$showAct;
      return action.indexOf(_enum.Action.focus) !== -1 || showAction.indexOf(_enum.ShowAction.focus) !== -1;
    }
  }, {
    key: "isBlurToHide",
    value: function isBlurToHide() {
      var _this$props13 = this.props,
          _this$props13$action = _this$props13.action,
          action = _this$props13$action === void 0 ? [] : _this$props13$action,
          _this$props13$hideAct = _this$props13.hideAction,
          hideAction = _this$props13$hideAct === void 0 ? [] : _this$props13$hideAct,
          getContextConfig = _this$props13.getContextConfig;
      var formAutoFocus = getContextConfig ? getContextConfig('formAutoFocus') : false;
      return action.indexOf(_enum.Action.focus) !== -1 || hideAction.indexOf(_enum.HideAction.blur) !== -1 || formAutoFocus;
    }
  }]);
  return Trigger;
}(_react.Component);

Trigger.displayName = 'Trigger';
Trigger.defaultProps = {
  focusDelay: 150,
  blurDelay: 0,
  mouseEnterDelay: 100,
  mouseLeaveDelay: 100,
  transitionName: 'slide-up',
  defaultPopupHidden: true
};
(0, _tslib.__decorate)([_mobx.observable], Trigger.prototype, "popupHidden", void 0);
(0, _tslib.__decorate)([_mobx.observable], Trigger.prototype, "mounted", void 0);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "saveRef", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "getFocusableElements", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "renderTriggerChild", null);
(0, _tslib.__decorate)([_mobx.action], Trigger.prototype, "componentWillReceiveProps", null);
(0, _tslib.__decorate)([_mobx.action], Trigger.prototype, "componentDidMount", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "cancelPopupTask", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handlePopupKeyDown", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handleTargetBlur", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handleEvent", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handlePopupMouseDown", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handlePopupBlur", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handleDocumentMouseDown", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handleDocumentScroll", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handlePopupMouseEnter", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "handlePopupMouseLeave", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "getRootDomNode", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "getPopupClassNameFromAlign", null);
(0, _tslib.__decorate)([_autobind["default"]], Trigger.prototype, "forcePopupAlign", null);
(0, _tslib.__decorate)([_mobx.action], Trigger.prototype, "setPopupHidden", null);
Trigger = (0, _tslib.__decorate)([_mobxReact.observer], Trigger);
var _default = Trigger;
exports["default"] = _default;
//# sourceMappingURL=Trigger.js.map
