/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var omit = require('lodash/omit');
var popup_index = require('../popup/index.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var dropdown_dropdownMenu = require('./dropdown-menu.js');
var dropdown_props = require('./props.js');
var dropdown_hooks_useDropdownOptions = require('./hooks/useDropdownOptions.js');
require('../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('../_common/js/utils/set-style.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../utils/event.js');
require('../popup/props.js');
require('../popup/container.js');
require('lodash/isFunction');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../popup/plugin.js');
require('../config-provider/useConfig.js');
require('lodash/isEmpty');
require('../hooks/render-tnode.js');
require('lodash/isObject');
require('@ldesign/icons-vue');
require('../divider/index.js');
require('../divider/divider.js');
require('../divider/props.js');
require('../hooks/useGlobalIcon.js');
require('./dropdown-item.js');
require('../utils/ripple.js');
require('../config.js');
require('./dropdown-item-props.js');
require('lodash/get');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _Dropdown = VueCompositionAPI.defineComponent({
  name: "TDropdown",
  props: _objectSpread({}, dropdown_props["default"]),
  setup: function setup(props2, _ref) {
    var emit = _ref.emit;
    var dropdownClass = hooks_useConfig.usePrefixClass("dropdown");
    var isPopupVisible = VueCompositionAPI.ref(false);
    var handleMenuClick = function handleMenuClick(data, context) {
      var _props2$onClick;
      if (props2.hideAfterItemClick) {
        var _props2$popupProps, _props2$popupProps$on, _props2$popupProps2, _props2$popupProps2$o;
        isPopupVisible.value = false;
        (_props2$popupProps = props2.popupProps) === null || _props2$popupProps === void 0 ? void 0 : (_props2$popupProps$on = _props2$popupProps.onVisibleChange) === null || _props2$popupProps$on === void 0 ? void 0 : _props2$popupProps$on.call(_props2$popupProps, false, context);
        (_props2$popupProps2 = props2.popupProps) === null || _props2$popupProps2 === void 0 ? void 0 : (_props2$popupProps2$o = _props2$popupProps2["on-visible-change"]) === null || _props2$popupProps2$o === void 0 ? void 0 : _props2$popupProps2$o.call(_props2$popupProps2, false, context);
      }
      props2 === null || props2 === void 0 ? void 0 : (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, data, context);
      emit("click", data, context);
    };
    var handleVisibleChange = function handleVisibleChange(visible, context) {
      var _props2$popupProps3, _props2$popupProps3$o, _props2$popupProps4, _props2$popupProps4$o;
      isPopupVisible.value = visible;
      (_props2$popupProps3 = props2.popupProps) === null || _props2$popupProps3 === void 0 ? void 0 : (_props2$popupProps3$o = _props2$popupProps3.onVisibleChange) === null || _props2$popupProps3$o === void 0 ? void 0 : _props2$popupProps3$o.call(_props2$popupProps3, visible, context);
      (_props2$popupProps4 = props2.popupProps) === null || _props2$popupProps4 === void 0 ? void 0 : (_props2$popupProps4$o = _props2$popupProps4["on-visible-change"]) === null || _props2$popupProps4$o === void 0 ? void 0 : _props2$popupProps4$o.call(_props2$popupProps4, visible, context);
    };
    return {
      dropdownClass: dropdownClass,
      handleMenuClick: handleMenuClick,
      isPopupVisible: isPopupVisible,
      handleVisibleChange: handleVisibleChange
    };
  },
  render: function render() {
    var _this$popupProps, _renderTNodeJSX;
    var h = arguments[0];
    var popupParams = _objectSpread(_objectSpread({
      disabled: this.disabled,
      placement: this.placement,
      trigger: this.trigger
    }, omit__default["default"](this.popupProps, ["onVisibleChange", "on-visible-change"])), {}, {
      overlayInnerClassName: [this.dropdownClass, (_this$popupProps = this.popupProps) === null || _this$popupProps === void 0 ? void 0 : _this$popupProps.overlayInnerClassName]
    });
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var options = dropdown_hooks_useDropdownOptions["default"](this.$props, this.$slots);
    var trigger = (_renderTNodeJSX = renderTNodeJSX("default")) === null || _renderTNodeJSX === void 0 ? void 0 : _renderTNodeJSX[0];
    return h(popup_index.Popup, {
      "props": _objectSpread({}, _objectSpread({
        destroyOnClose: true,
        visible: this.isPopupVisible,
        onVisibleChange: this.handleVisibleChange,
        expandAnimation: true
      }, popupParams))
    }, [h(dropdown_dropdownMenu["default"], {
      "slot": "content",
      "props": _objectSpread({}, _objectSpread(_objectSpread({}, this.$props), {}, {
        options: options.value,
        onClick: this.handleMenuClick
      }))
    }), trigger]);
  }
});

exports["default"] = _Dropdown;
//# sourceMappingURL=dropdown.js.map
