'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var index$1 = require('../_util/props-util/index.js');
var classNames = require('../_util/classNames.js');
var vnode = require('../_util/vnode.js');
require('../vc-dropdown/index.js');
require('../hooks/index.js');
var devWarning = require('../vc-util/devWarning.js');
var omit = require('../_util/omit.js');
var placements = require('../_util/placements.js');
var warning = require('../_util/warning.js');
var OverrideContext = require('../menu/src/OverrideContext.js');
var index = require('./style/index.js');
var props = require('./props.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var Dropdown$1 = require('../vc-dropdown/Dropdown.js');

var Dropdown = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ADropdown",
  inheritAttrs: false,
  props: initDefaultProps.default(props.dropdownProps(), {
    mouseEnterDelay: 0.15,
    mouseLeaveDelay: 0.1,
    placement: "bottomLeft",
    trigger: "hover"
  }),
  // emits: ['visibleChange', 'update:visible'],
  slots: Object,
  setup(props, {
    slots,
    attrs,
    emit
  }) {
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer
    } = useConfigInject.default("dropdown", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    if (process.env.NODE_ENV !== "production") {
      [["visible", "open"], ["onVisibleChange", "onOpenChange"], ["onUpdate:visible", "onUpdate:open"]].forEach(([deprecatedName, newName]) => {
        warning.default(props[deprecatedName] === void 0, "Dropdown", `\`${deprecatedName}\` is deprecated which will be removed in next major version, please use \`${newName}\` instead.`);
      });
    }
    const transitionName = vue.computed(() => {
      const {
        placement: placement2 = "",
        transitionName: transitionName2
      } = props;
      if (transitionName2 !== void 0)
        return transitionName2;
      if (placement2.includes("top"))
        return `${rootPrefixCls.value}-slide-down`;
      return `${rootPrefixCls.value}-slide-up`;
    });
    OverrideContext.useProvideOverride({
      prefixCls: vue.computed(() => `${prefixCls.value}-menu`),
      expandIcon: vue.computed(() => {
        return vue.createVNode("span", {
          "class": `${prefixCls.value}-menu-submenu-arrow`
        }, [vue.createVNode(CloseOutlined.RightOutlined, {
          "class": `${prefixCls.value}-menu-submenu-arrow-icon`
        }, null)]);
      }),
      mode: vue.computed(() => "vertical"),
      selectable: vue.computed(() => false),
      onClick: () => {
      },
      validator: ({
        mode
      }) => {
        warning.default(!mode || mode === "vertical", "Dropdown", `mode="${mode}" is not supported for Dropdown's Menu.`);
      }
    });
    const renderOverlay = () => {
      var _a, _b, _c;
      const overlay = props.overlay || ((_a = slots.overlay) == null ? void 0 : _a.call(slots));
      const overlayNode = Array.isArray(overlay) ? overlay[0] : overlay;
      if (!overlayNode)
        return null;
      const overlayProps = overlayNode.props || {};
      devWarning.default(!overlayProps.mode || overlayProps.mode === "vertical", "Dropdown", `mode="${overlayProps.mode}" is not supported for Dropdown's Menu.`);
      const {
        selectable = false,
        expandIcon = (_c = (_b = overlayNode.children) == null ? void 0 : _b.expandIcon) == null ? void 0 : _c.call(_b)
      } = overlayProps;
      const overlayNodeExpandIcon = typeof expandIcon !== "undefined" && index$1.isValidElement(expandIcon) ? expandIcon : vue.createVNode("span", {
        "class": `${prefixCls.value}-menu-submenu-arrow`
      }, [vue.createVNode(CloseOutlined.RightOutlined, {
        "class": `${prefixCls.value}-menu-submenu-arrow-icon`
      }, null)]);
      const fixedModeOverlay = index$1.isValidElement(overlayNode) ? vnode.cloneElement(overlayNode, {
        mode: "vertical",
        selectable,
        expandIcon: () => overlayNodeExpandIcon
      }) : overlayNode;
      return fixedModeOverlay;
    };
    const placement = vue.computed(() => {
      const placement2 = props.placement;
      if (!placement2)
        return direction.value === "rtl" ? "bottomRight" : "bottomLeft";
      if (placement2.includes("Center")) {
        const newPlacement = placement2.slice(0, placement2.indexOf("Center"));
        devWarning.default(!placement2.includes("Center"), "Dropdown", `You are using '${placement2}' placement in Dropdown, which is deprecated. Try to use '${newPlacement}' instead.`);
        return newPlacement;
      }
      return placement2;
    });
    const mergedVisible = vue.computed(() => {
      return typeof props.visible === "boolean" ? props.visible : props.open;
    });
    const handleVisibleChange = (val) => {
      emit("update:visible", val);
      emit("visibleChange", val);
      emit("update:open", val);
      emit("openChange", val);
    };
    return () => {
      var _a, _b;
      const {
        arrow,
        trigger,
        disabled,
        overlayClassName
      } = props;
      const child = (_a = slots.default) == null ? void 0 : _a.call(slots)[0];
      const dropdownTrigger = vnode.cloneElement(child, Object.assign({
        class: classNames.default((_b = child == null ? void 0 : child.props) == null ? void 0 : _b.class, {
          [`${prefixCls.value}-rtl`]: direction.value === "rtl"
        }, `${prefixCls.value}-trigger`)
      }, disabled ? {
        disabled
      } : {}));
      const overlayClassNameCustomized = classNames.default(overlayClassName, hashId.value, {
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      });
      const triggerActions = disabled ? [] : trigger;
      let alignPoint;
      if (triggerActions && triggerActions.includes("contextmenu"))
        alignPoint = true;
      const builtinPlacements = placements.default({
        arrowPointAtCenter: typeof arrow === "object" && arrow.pointAtCenter,
        autoAdjustOverflow: true
      });
      const dropdownProps2 = omit.default({
        ...props,
        ...attrs,
        visible: mergedVisible.value,
        builtinPlacements,
        overlayClassName: overlayClassNameCustomized,
        arrow: !!arrow,
        alignPoint,
        prefixCls: prefixCls.value,
        getPopupContainer: getPopupContainer == null ? void 0 : getPopupContainer.value,
        transitionName: transitionName.value,
        trigger: triggerActions,
        onVisibleChange: handleVisibleChange,
        placement: placement.value
      }, ["overlay", "onUpdate:visible"]);
      return wrapSSR(vue.createVNode(Dropdown$1.default, dropdownProps2, {
        default: () => [dropdownTrigger],
        overlay: renderOverlay
      }));
    };
  }
});

exports.default = Dropdown;
//# sourceMappingURL=dropdown.js.map
