"use strict";

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

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

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

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

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

var _rcDropdown = _interopRequireDefault(require("../components/rc-dropdown"));

var _ReactNodeValidate = require("../utils/ReactNodeValidate");

var _context = require("../config-provider/context");

var _components = require("../components");

var RightLine = _components.Icons.RightLine;
var Placements = (0, _ReactNodeValidate.tuple)('topLeft', 'topCenter', 'topRight', 'bottomLeft', 'bottomCenter', 'bottomRight');

var Dropdown = function Dropdown(props) {
  var _React$useContext = React.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName,
      getCtxPopupContainer = _React$useContext.getPopupContainer;

  var dropdownPrefix = getPrefixClassName('dropdown');

  var getTransitionName = function getTransitionName() {
    var transitionName = props.transitionName;

    if (transitionName !== undefined) {
      return transitionName;
    } // if (placement.indexOf('top') >= 0) {
    //   return `${dropdownPrefix}-slide-down`;
    // }
    // return `${dropdownPrefix}-slide-up`;

  };

  var renderOverlay = function renderOverlay() {
    var overlay = props.overlay;
    var overlayNode;

    if (typeof overlay === 'function') {
      overlayNode = overlay();
    } else {
      overlayNode = overlay;
    }

    overlayNode = React.Children.only(typeof overlayNode === 'string' ? /*#__PURE__*/React.createElement("span", null, overlayNode) : overlayNode);
    var overlayProps = overlayNode.props;
    var _overlayProps$selecta = overlayProps.selectable,
        selectable = _overlayProps$selecta === void 0 ? false : _overlayProps$selecta,
        _overlayProps$focusab = overlayProps.focusable,
        focusable = _overlayProps$focusab === void 0 ? true : _overlayProps$focusab,
        expandIcon = overlayProps.expandIcon;
    var overlayNodeExpandIcon = typeof expandIcon !== 'undefined' && /*#__PURE__*/React.isValidElement(expandIcon) ? expandIcon : /*#__PURE__*/React.createElement("span", {
      className: "".concat(dropdownPrefix, "-menu-submenu-arrow")
    }, /*#__PURE__*/React.createElement(RightLine, {
      className: "".concat(dropdownPrefix, "-menu-submenu-arrow-icon")
    }));
    var fixedModeOverlay = typeof overlayNode.type === 'string' ? overlayNode : (0, _ReactNodeValidate.cloneElement)(overlayNode, {
      mode: 'vertical',
      selectable: selectable,
      focusable: focusable,
      expandIcon: overlayNodeExpandIcon
    });
    return fixedModeOverlay;
  };

  var getPlacement = function getPlacement() {
    var placement = props.placement;

    if (placement !== undefined) {
      return placement;
    } // return direction === 'rtl' ? ('bottomRight' as Placement) : ('bottomLeft' as Placement);


    return 'bottomLeft';
  };

  var arrow = props.arrow,
      children = props.children,
      trigger = props.trigger,
      disabled = props.disabled,
      getPopupContainer = props.getPopupContainer,
      overlayClassName = props.overlayClassName;
  var child = React.Children.only(children);
  var dropdownTrigger = (0, _ReactNodeValidate.cloneElement)(child, {
    className: (0, _classnames.default)("".concat(dropdownPrefix, "-trigger"), child.props.className),
    disabled: disabled
  });
  var overlayClassNameCustomized = (0, _classnames.default)(overlayClassName, {// [`${prefixCls}-rtl`]: direction === 'rtl',
  });
  var triggerActions = disabled ? [] : trigger;
  var alignPoint;

  if (triggerActions && triggerActions.indexOf('contextMenu') !== -1) {
    alignPoint = true;
  }

  return /*#__PURE__*/React.createElement(_rcDropdown.default, Object.assign({
    arrow: arrow,
    alignPoint: alignPoint
  }, props, {
    overlayClassName: overlayClassNameCustomized,
    prefixCls: dropdownPrefix,
    getPopupContainer: getPopupContainer || getCtxPopupContainer,
    transitionName: getTransitionName(),
    trigger: triggerActions,
    overlay: function overlay() {
      return renderOverlay();
    },
    placement: getPlacement()
  }), dropdownTrigger);
}; // Dropdown.Button = DropdownButton;


Dropdown.displayName = 'Dropdown';
Dropdown.defaultProps = {
  mouseEnterDelay: 0.15,
  mouseLeaveDelay: 0.1,
  trigger: ['click']
};
var _default = Dropdown;
exports.default = _default;