"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

var _vue = _interopRequireWildcard(require("vue"));

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

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

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

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

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var BUILT_IN_PLACEMENTS = {
  bottomLeft: {
    points: ['tl', 'bl'],
    offset: [0, 4],
    overflow: {
      adjustX: 0,
      adjustY: 1
    },
    ignoreShake: true
  },
  topLeft: {
    points: ['bl', 'tl'],
    offset: [0, -4],
    overflow: {
      adjustX: 0,
      adjustY: 1
    },
    ignoreShake: true
  }
};
var SelectTrigger = {
  name: 'SelectTrigger',
  inheritAttrs: false,
  props: {
    // Pass by outside user props
    disabled: _vueTypes.default.bool,
    showSearch: _vueTypes.default.bool,
    prefixCls: _vueTypes.default.string,
    dropdownPopupAlign: _vueTypes.default.object,
    dropdownClassName: _vueTypes.default.string,
    dropdownStyle: _vueTypes.default.object,
    transitionName: _vueTypes.default.string,
    animation: _vueTypes.default.string,
    getPopupContainer: _vueTypes.default.func,
    dropdownMatchSelectWidth: _vueTypes.default.bool,
    // Pass by Select
    isMultiple: _vueTypes.default.bool,
    dropdownPrefixCls: _vueTypes.default.string,
    dropdownVisibleChange: _vueTypes.default.func,
    popupElement: _vueTypes.default.node,
    open: _vueTypes.default.bool
  },
  created: function created() {
    this.triggerRef = (0, _util.createRef)();
  },
  methods: {
    getDropdownTransitionName: function getDropdownTransitionName() {
      var _this$$props = this.$props,
          transitionName = _this$$props.transitionName,
          animation = _this$$props.animation,
          dropdownPrefixCls = _this$$props.dropdownPrefixCls;

      if (!transitionName && animation) {
        return "".concat(dropdownPrefixCls, "-").concat(animation);
      }

      return transitionName;
    },
    forcePopupAlign: function forcePopupAlign() {
      var $trigger = this.triggerRef.current;

      if ($trigger) {
        $trigger.forcePopupAlign();
      }
    }
  },
  render: function render() {
    var _classNames,
        _this = this;

    var _this$$props2 = this.$props,
        disabled = _this$$props2.disabled,
        isMultiple = _this$$props2.isMultiple,
        dropdownPopupAlign = _this$$props2.dropdownPopupAlign,
        dropdownMatchSelectWidth = _this$$props2.dropdownMatchSelectWidth,
        dropdownClassName = _this$$props2.dropdownClassName,
        dropdownStyle = _this$$props2.dropdownStyle,
        dropdownVisibleChange = _this$$props2.dropdownVisibleChange,
        getPopupContainer = _this$$props2.getPopupContainer,
        dropdownPrefixCls = _this$$props2.dropdownPrefixCls,
        popupElement = _this$$props2.popupElement,
        open = _this$$props2.open; // TODO: [Legacy] Use new action when trigger fixed: https://github.com/react-component/trigger/pull/86
    // When false do nothing with the width
    // ref: https://github.com/ant-design/ant-design/issues/10927

    var stretch;

    if (dropdownMatchSelectWidth !== false) {
      stretch = dropdownMatchSelectWidth ? 'width' : 'minWidth';
    }

    return _vue.createVNode(_vcTrigger.default, {
      "ref": this.triggerRef,
      "action": disabled ? [] : ['click'],
      "popupPlacement": "bottomLeft",
      "builtinPlacements": BUILT_IN_PLACEMENTS,
      "popupAlign": dropdownPopupAlign,
      "prefixCls": dropdownPrefixCls,
      "popupTransitionName": this.getDropdownTransitionName(),
      "onPopupVisibleChange": dropdownVisibleChange,
      "popup": popupElement,
      "popupVisible": open,
      "getPopupContainer": getPopupContainer,
      "stretch": stretch,
      "popupClassName": (0, _classNames2.default)(dropdownClassName, (_classNames = {}, _defineProperty(_classNames, "".concat(dropdownPrefixCls, "--multiple"), isMultiple), _defineProperty(_classNames, "".concat(dropdownPrefixCls, "--single"), !isMultiple), _classNames)),
      "popupStyle": dropdownStyle
    }, {
      default: function _default() {
        return [(0, _propsUtil.getSlot)(_this)];
      }
    });
  }
};
var _default2 = SelectTrigger;
exports.default = _default2;