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

import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, ref, computed, createVNode, mergeProps } from 'vue';
import { o as omit_1 } from '../_chunks/dep-350764bc.mjs';
import { i as isArray_1 } from '../_chunks/dep-b57180d0.mjs';
import { i as isNumber_1 } from '../_chunks/dep-3f21269a.mjs';
import { Popup } from '../popup/index.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import { useTNodeJSX } from '../hooks/tnode.mjs';
import _DropdownMenu from './dropdown-menu.mjs';
import props from './props.mjs';
import useDropdownOptions from './hooks/useDropdownOptions.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-0d3dd4b5.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-6884627f.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../utils/withInstall.mjs';
import '../popup/popup.mjs';
import '../_chunks/dep-84acf3c2.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '@popperjs/core';
import '../_chunks/dep-876fb3ec.mjs';
import '../utils/dom.mjs';
import '../utils/easing.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../_common/js/utils/set-style.mjs';
import '../hooks/useVModel.mjs';
import '../popup/props.mjs';
import '../popup/container.mjs';
import '../_chunks/dep-bf1e33c8.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../hooks/useResizeObserver.mjs';
import '../popup/style/css.mjs';
import '../popup/type.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';
import '@ldesign/icons-vue-next';
import '../divider/index.mjs';
import '../divider/divider.mjs';
import '../divider/props.mjs';
import '../divider/style/css.mjs';
import '../divider/type.mjs';
import '../hooks/useGlobalIcon.mjs';
import './dropdown-item.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../utils/helper.mjs';
import '../_chunks/dep-60fae668.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import './dropdown-item-props.mjs';
import '../hooks/slot.mjs';

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(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 = defineComponent({
  name: "TDropdown",
  props: props,
  setup: function setup(props2, _ref) {
    var attrs = _ref.attrs;
    var renderTNodeJSX = useTNodeJSX();
    var COMPONENT_NAME = usePrefixClass("dropdown");
    var popupElem = ref(null);
    var isPopupVisible = ref(false);
    var manualCloseTimeout = computed(function () {
      var _props2$popupProps;
      var delay = (_props2$popupProps = props2.popupProps) === null || _props2$popupProps === void 0 ? void 0 : _props2$popupProps.delay;
      if (isNumber_1(delay)) return delay + 10;
      if (isArray_1(delay)) return delay[1] + 10;
      return 160;
    });
    var handleMenuClick = function handleMenuClick(data, context) {
      var _props2$onClick;
      if (props2.hideAfterItemClick) {
        var _props2$popupProps2, _props2$popupProps2$o, _props2$popupProps$on, _props2$popupProps3;
        setTimeout(function () {
          return isPopupVisible.value = false;
        }, manualCloseTimeout.value);
        (_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, false, context);
        (_props2$popupProps$on = (_props2$popupProps3 = props2.popupProps)["on-visible-change"]) === null || _props2$popupProps$on === void 0 ? void 0 : _props2$popupProps$on.call(_props2$popupProps3, 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);
    };
    var handleVisibleChange = function handleVisibleChange(visible, context) {
      var _props2$popupProps4, _props2$popupProps4$o, _props2$popupProps5, _props2$popupProps5$o;
      isPopupVisible.value = visible;
      (_props2$popupProps4 = props2.popupProps) === null || _props2$popupProps4 === void 0 ? void 0 : (_props2$popupProps4$o = _props2$popupProps4.onVisibleChange) === null || _props2$popupProps4$o === void 0 ? void 0 : _props2$popupProps4$o.call(_props2$popupProps4, visible, context);
      (_props2$popupProps5 = props2.popupProps) === null || _props2$popupProps5 === void 0 ? void 0 : (_props2$popupProps5$o = _props2$popupProps5["on-visible-change"]) === null || _props2$popupProps5$o === void 0 ? void 0 : _props2$popupProps5$o.call(_props2$popupProps5, visible, context);
    };
    return function () {
      var _renderTNodeJSX, _props2$popupProps6;
      var trigger = (_renderTNodeJSX = renderTNodeJSX("default")) === null || _renderTNodeJSX === void 0 ? void 0 : _renderTNodeJSX[0];
      var options = useDropdownOptions(props2);
      var popupParams = _objectSpread(_objectSpread(_objectSpread({}, attrs), {}, {
        disabled: props2.disabled,
        placement: props2.placement,
        trigger: props2.trigger
      }, omit_1(props2.popupProps, ["onVisibleChange", "on-visible-change"])), {}, {
        overlayInnerClassName: [COMPONENT_NAME.value, (_props2$popupProps6 = props2.popupProps) === null || _props2$popupProps6 === void 0 ? void 0 : _props2$popupProps6.overlayInnerClassName]
      });
      return createVNode(Popup, mergeProps({
        "destroyOnClose": true,
        "ref": popupElem,
        "visible": isPopupVisible.value,
        "onVisibleChange": handleVisibleChange,
        "expandAnimation": true
      }, popupParams), {
        "default": function _default() {
          return [trigger];
        },
        content: function content() {
          return createVNode(_DropdownMenu, mergeProps(omit_1(props2, "onClick"), {
            "options": options.value,
            "onClick": handleMenuClick
          }), null);
        }
      });
    };
  }
});

export { _Dropdown as default };
//# sourceMappingURL=dropdown.mjs.map
