import { defineComponent, computed, createVNode } from 'vue';
import { RightOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../vue-components/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { useProvideOverride } from '../../menu/src/OverrideContext.mjs';
import useStyle from '../style/index.mjs';
import { dropdownProps } from './props.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { isValidElement } from '../../../utils/is.mjs';
import { cloneElement } from '../../../utils/vue/vnode.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import { getPlacements } from '../../../utils/placement.mjs';
import { omit } from '../../../utils/lang/omit.mjs';
import VcDropdown from '../../../vue-components/vc-dropdown/src/Dropdown.mjs';

var ADropdown = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ADropdown",
  inheritAttrs: false,
  props: initDefaultProps(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("dropdown", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    if (process.env.NODE_ENV !== "production") {
      [["visible", "open"], ["onVisibleChange", "onOpenChange"], ["onUpdate:visible", "onUpdate:open"]].forEach(([deprecatedName, newName]) => {
        devWarning(props[deprecatedName] === void 0, "Dropdown", `\`${deprecatedName}\` is deprecated which will be removed in next major version, please use \`${newName}\` instead.`);
      });
    }
    const transitionName = computed(() => {
      const {
        placement: placement2 = ""
      } = props;
      if (props.transitionName !== void 0)
        return props.transitionName;
      if (placement2.includes("top"))
        return `${rootPrefixCls.value}-slide-down`;
      return `${rootPrefixCls.value}-slide-up`;
    });
    useProvideOverride({
      prefixCls: computed(() => `${prefixCls.value}-menu`),
      expandIcon: computed(() => {
        return createVNode("span", {
          "class": `${prefixCls.value}-menu-submenu-arrow`
        }, [createVNode(RightOutlined, {
          "class": `${prefixCls.value}-menu-submenu-arrow-icon`
        }, null)]);
      }),
      mode: computed(() => "vertical"),
      selectable: computed(() => false),
      onClick: () => {
      },
      validator: ({
        mode
      }) => {
        devWarning(!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(!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" && isValidElement(expandIcon) ? expandIcon : createVNode("span", {
        "class": `${prefixCls.value}-menu-submenu-arrow`
      }, [createVNode(RightOutlined, {
        "class": `${prefixCls.value}-menu-submenu-arrow-icon`
      }, null)]);
      const fixedModeOverlay = isValidElement(overlayNode) ? cloneElement(overlayNode, {
        mode: "vertical",
        selectable,
        expandIcon: () => overlayNodeExpandIcon
      }) : overlayNode;
      return fixedModeOverlay;
    };
    const placement = computed(() => {
      if (!props.placement)
        return direction.value === "rtl" ? "bottomRight" : "bottomLeft";
      if (props.placement.includes("Center")) {
        const newPlacement = props.placement.slice(0, props.placement.indexOf("Center"));
        devWarning(!props.placement.includes("Center"), "Dropdown", `You are using '${props.placement}' placement in Dropdown, which is deprecated. Try to use '${newPlacement}' instead.`);
        return newPlacement;
      }
      return props.placement;
    });
    const mergedVisible = 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 = cloneElement(child, Object.assign({
        class: classNames((_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(overlayClassName, hashId.value, {
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      });
      const triggerActions = disabled ? [] : trigger;
      let alignPoint;
      if (triggerActions && triggerActions.includes("contextmenu"))
        alignPoint = true;
      const builtinPlacements = getPlacements({
        arrowPointAtCenter: typeof arrow === "object" && arrow.pointAtCenter,
        autoAdjustOverflow: true
      });
      const getDropdownProps = omit({
        ...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(createVNode(VcDropdown, getDropdownProps, {
        default: () => [dropdownTrigger],
        overlay: renderOverlay
      }));
    };
  }
});

export { ADropdown as default };
//# sourceMappingURL=Dropdown.mjs.map
