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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, createVNode, mergeProps } from 'vue';
import omit from 'lodash/omit';
import isArray from 'lodash/isArray';
import isNumber from 'lodash/isNumber';
import { Popup } from '../popup/index.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import _DropdownMenu from './dropdown-menu.js';
import props from './props.js';
import useDropdownOptions from './hooks/useDropdownOptions.js';
import '../utils/withInstall.js';
import '../popup/popup.js';
import '@babel/runtime/helpers/slicedToArray';
import '@popperjs/core';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isObject';
import '../utils/dom.js';
import '../_chunks/dep-512eb181.js';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/set-style.js';
import '../hooks/useVModel.js';
import '../popup/props.js';
import '../popup/container.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/isUndefined';
import '../hooks/useResizeObserver.js';
import '../popup/style';
import '../popup/type.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_chunks/dep-ac28b67c.js';
import '../config-provider/type.js';
import '@ldesign/icons-vue-next';
import '../divider/index.js';
import '../divider/divider.js';
import '../divider/props.js';
import '../divider/style';
import '../divider/type.js';
import '../hooks/useGlobalIcon.js';
import './dropdown-item.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import './dropdown-item-props.js';
import '../hooks/slot.js';

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(delay)) return delay + 10;
      if (isArray(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(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(props2, "onClick"), {
            "options": options.value,
            "onClick": handleMenuClick
          }), null);
        }
      });
    };
  }
});

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