/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var omit = require('lodash/omit');
var components_popup_index = require('../popup/index.js');
var hooks_useConfig = require('../../hooks/use-config.js');
var hooks_lnode = require('../../hooks/lnode.js');
var components_dropdown_dropdownMenu = require('./dropdown-menu.js');
var components_dropdown_props = require('./props.js');
var components_dropdown_hooks_useDropdownOptions = require('./hooks/use-dropdown-options.js');
require('../../utils/map-props.js');
require('vue');
require('../../utils/with-install.js');
require('lodash');
require('../../config.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../../chunks/set-style.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('../../utils/helper.js');
require('lodash/camelCase');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('../popup/props.js');
require('../popup/container.js');
require('../config-provider/useConfig.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/kebabCase');
require('../../hooks/render-lnode.js');
require('@ldesign/icons-vue');
require('../divider/index.js');
require('../divider/divider.js');
require('../divider/props.js');
require('../../hooks/use-global-icon.js');
require('./dropdown-item.js');
require('../../utils/ripple.js');
require('lodash/get');

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

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

var _Dropdown = VueCompositionAPI.defineComponent({
  name: "LDropdown",
  props: {
    ...components_dropdown_props.DropdownProps
  },
  setup(props2, _ref) {
    let {
      emit
    } = _ref;
    const dropdownClass = hooks_useConfig.usePrefixClass("dropdown");
    const isPopupVisible = VueCompositionAPI.ref(false);
    const handleMenuClick = (data, context) => {
      var _props2$onClick;
      if (props2.hideAfterItemClick) {
        var _props2$popupProps, _props2$popupProps$on;
        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 === 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);
    };
    const handleVisibleChange = (visible, context) => {
      var _props2$popupProps2, _props2$popupProps2$o;
      isPopupVisible.value = visible;
      (_props2$popupProps2 = props2.popupProps) === null || _props2$popupProps2 === void 0 ? void 0 : (_props2$popupProps2$o = _props2$popupProps2.onVisibleChange) === null || _props2$popupProps2$o === void 0 ? void 0 : _props2$popupProps2$o.call(_props2$popupProps2, visible, context);
    };
    return {
      dropdownClass,
      handleMenuClick,
      isPopupVisible,
      handleVisibleChange
    };
  },
  render() {
    var _this$popupProps, _renderTNodeJSX;
    const h = arguments[0];
    const popupParams = {
      disabled: this.disabled,
      placement: this.placement,
      trigger: this.trigger,
      ...omit__default["default"](this.popupProps, "onVisibleChange"),
      overlayInnerClassName: [this.dropdownClass, (_this$popupProps = this.popupProps) === null || _this$popupProps === void 0 ? void 0 : _this$popupProps.overlayInnerClassName]
    };
    const renderTNodeJSX = hooks_lnode.useLNodeJSX();
    const options = components_dropdown_hooks_useDropdownOptions["default"](this.$props, this.$slots);
    const trigger = (_renderTNodeJSX = renderTNodeJSX("default")) === null || _renderTNodeJSX === void 0 ? void 0 : _renderTNodeJSX[0];
    return h(components_popup_index.Popup, {
      "props": {
        ...{
          destroyOnClose: true,
          visible: this.isPopupVisible,
          onVisibleChange: this.handleVisibleChange,
          expandAnimation: true,
          ...popupParams
        }
      }
    }, [h(components_dropdown_dropdownMenu["default"], {
      "slot": "content",
      "props": {
        ...{
          ...this.$props,
          options: options.value,
          onClick: this.handleMenuClick
        }
      }
    }), trigger]);
  }
});

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