'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var OverrideContext = require('../../menu/src/OverrideContext.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var log = require('../../../utils/log.cjs');
var is = require('../../../utils/is.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var _class = require('../../../utils/dom/class.cjs');
var placement = require('../../../utils/placement.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var Dropdown = require('../../../vue-components/vc-dropdown/src/Dropdown.cjs');

var ADropdown = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ADropdown",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(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]) => {
        log.devWarning(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 = ""
      } = props;
      if (props.transitionName !== void 0)
        return props.transitionName;
      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(iconsVue.RightOutlined, {
          "class": `${prefixCls.value}-menu-submenu-arrow-icon`
        }, null)]);
      }),
      mode: vue.computed(() => "vertical"),
      selectable: vue.computed(() => false),
      onClick: () => {
      },
      validator: ({
        mode
      }) => {
        log.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 || {};
      log.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" && is.isValidElement(expandIcon) ? expandIcon : vue.createVNode("span", {
        "class": `${prefixCls.value}-menu-submenu-arrow`
      }, [vue.createVNode(iconsVue.RightOutlined, {
        "class": `${prefixCls.value}-menu-submenu-arrow-icon`
      }, null)]);
      const fixedModeOverlay = is.isValidElement(overlayNode) ? vnode.cloneElement(overlayNode, {
        mode: "vertical",
        selectable,
        expandIcon: () => overlayNodeExpandIcon
      }) : overlayNode;
      return fixedModeOverlay;
    };
    const placement$1 = vue.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"));
        log.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 = 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: _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 = _class.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 = placement.getPlacements({
        arrowPointAtCenter: typeof arrow === "object" && arrow.pointAtCenter,
        autoAdjustOverflow: true
      });
      const getDropdownProps = omit.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$1.value
      }, ["overlay", "onUpdate:visible"]);
      return wrapSSR(vue.createVNode(Dropdown.default, getDropdownProps, {
        default: () => [dropdownTrigger],
        overlay: renderOverlay
      }));
    };
  }
});

exports.default = ADropdown;
//# sourceMappingURL=Dropdown.cjs.map
