"use strict";

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

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

var _vue = require("vue");

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

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

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

var _vcTrigger = _interopRequireDefault(require("../vc-trigger"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

var _classNames2 = _interopRequireDefault(require("../_util/classNames"));

var _createRef = _interopRequireDefault(require("../_util/createRef"));

var _excluded = ["empty"];

var getBuiltInPlacements = function getBuiltInPlacements(dropdownMatchSelectWidth) {
  // Enable horizontal overflow auto-adjustment when a custom dropdown width is provided
  var adjustX = typeof dropdownMatchSelectWidth !== 'number' ? 0 : 1;
  return {
    bottomLeft: {
      points: ['tl', 'bl'],
      offset: [0, 4],
      overflow: {
        adjustX: adjustX,
        adjustY: 1
      }
    },
    bottomRight: {
      points: ['tr', 'br'],
      offset: [0, 4],
      overflow: {
        adjustX: adjustX,
        adjustY: 1
      }
    },
    topLeft: {
      points: ['bl', 'tl'],
      offset: [0, -4],
      overflow: {
        adjustX: adjustX,
        adjustY: 1
      }
    },
    topRight: {
      points: ['br', 'tr'],
      offset: [0, -4],
      overflow: {
        adjustX: adjustX,
        adjustY: 1
      }
    }
  };
};

var SelectTrigger = (0, _vue.defineComponent)({
  name: 'SelectTrigger',
  inheritAttrs: false,
  created: function created() {
    this.popupRef = (0, _createRef.default)();
  },
  methods: {
    getPopupElement: function getPopupElement() {
      return this.popupRef.current;
    }
  },
  render: function render() {
    var _this = this;

    var _this$$props$this$$at = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.$props), this.$attrs),
        _this$$props$this$$at2 = _this$$props$this$$at.empty,
        empty = _this$$props$this$$at2 === void 0 ? false : _this$$props$this$$at2,
        props = (0, _objectWithoutProperties2.default)(_this$$props$this$$at, _excluded);

    var _ref = props,
        visible = _ref.visible,
        dropdownAlign = _ref.dropdownAlign,
        prefixCls = _ref.prefixCls,
        popupElement = _ref.popupElement,
        dropdownClassName = _ref.dropdownClassName,
        dropdownStyle = _ref.dropdownStyle,
        dropdownMatchSelectWidth = _ref.dropdownMatchSelectWidth,
        containerWidth = _ref.containerWidth,
        dropdownRender = _ref.dropdownRender,
        animation = _ref.animation,
        transitionName = _ref.transitionName,
        direction = _ref.direction,
        getPopupContainer = _ref.getPopupContainer,
        getTriggerDOMNode = _ref.getTriggerDOMNode;
    var dropdownPrefixCls = "".concat(prefixCls, "-dropdown");
    var popupNode = popupElement;

    if (dropdownRender) {
      popupNode = dropdownRender({
        menuNode: popupElement,
        props: props
      });
    }

    var builtInPlacements = getBuiltInPlacements(dropdownMatchSelectWidth);
    var mergedTransitionName = animation ? "".concat(dropdownPrefixCls, "-").concat(animation) : transitionName;
    var popupStyle = (0, _objectSpread2.default)({
      minWidth: "".concat(containerWidth, "px")
    }, dropdownStyle);

    if (typeof dropdownMatchSelectWidth === 'number') {
      popupStyle.width = "".concat(dropdownMatchSelectWidth, "px");
    } else if (dropdownMatchSelectWidth) {
      popupStyle.width = "".concat(containerWidth, "px");
    }

    return (0, _vue.createVNode)(_vcTrigger.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
      "showAction": [],
      "hideAction": [],
      "popupPlacement": direction === 'rtl' ? 'bottomRight' : 'bottomLeft',
      "builtinPlacements": builtInPlacements,
      "prefixCls": dropdownPrefixCls,
      "popupTransitionName": mergedTransitionName,
      "popup": (0, _vue.createVNode)("div", {
        "ref": this.popupRef
      }, [popupNode]),
      "popupAlign": dropdownAlign,
      "popupVisible": visible,
      "getPopupContainer": getPopupContainer,
      "popupClassName": (0, _classNames2.default)(dropdownClassName, (0, _defineProperty2.default)({}, "".concat(dropdownPrefixCls, "-empty"), empty)),
      "popupStyle": popupStyle,
      "getTriggerDOMNode": getTriggerDOMNode
    }), {
      default: function _default() {
        return [(0, _propsUtil.getSlot)(_this)[0]];
      }
    });
  }
});
SelectTrigger.props = {
  dropdownAlign: _vueTypes.default.object,
  visible: _vueTypes.default.looseBool,
  disabled: _vueTypes.default.looseBool,
  dropdownClassName: _vueTypes.default.string,
  dropdownStyle: _vueTypes.default.object,
  empty: _vueTypes.default.looseBool,
  prefixCls: _vueTypes.default.string,
  popupClassName: _vueTypes.default.string,
  animation: _vueTypes.default.string,
  transitionName: _vueTypes.default.string,
  getPopupContainer: _vueTypes.default.func,
  dropdownRender: _vueTypes.default.func,
  containerWidth: _vueTypes.default.number,
  dropdownMatchSelectWidth: _vueTypes.default.oneOfType([Number, Boolean]).def(true),
  popupElement: _vueTypes.default.any,
  direction: _vueTypes.default.string,
  getTriggerDOMNode: _vueTypes.default.func
};
var _default2 = SelectTrigger;
exports.default = _default2;