import { defineComponent, shallowRef, computed, watch, createVNode } from 'vue';
import '../../../utils/index.mjs';
import '../../../vue-components/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { useInjectFormItemContext, FormItemInputContext } from '../../form/src/FormItemContext.mjs';
import '../../menu/index.mjs';
import { Spin } from '../../spin/index.mjs';
import useStyle from '../style/index.mjs';
import { mentionsProps } from './props.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { flattenChildren, getOptionProps } from '../../../utils/vue/props.mjs';
import { getMergedStatus, getStatusClassNames } from '../../../utils/statusUtils.mjs';
import { useProvideOverride } from '../../menu/src/OverrideContext.mjs';
import { omit } from '../../../utils/lang/omit.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import VcMentions from '../../../vue-components/vc-mentions/src/Mentions.mjs';

function loadingFilterOption() {
  return true;
}
var AMentions = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AMentions",
  inheritAttrs: false,
  props: mentionsProps(),
  slots: Object,
  setup(props, {
    slots,
    emit,
    attrs,
    expose
  }) {
    var _a, _b, _c;
    if (process.env.NODE_ENV !== "production") {
      devWarning(!flattenChildren(((_a = slots.default) == null ? void 0 : _a.call(slots)) || []).length, "Mentions", "`Mentions.Option` is deprecated. Please use `options` instead.");
    }
    const {
      prefixCls,
      renderEmpty,
      direction
    } = useConfigInject("mentions", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const focused = shallowRef(false);
    const vcMentions = shallowRef(null);
    const value = shallowRef((_c = (_b = props.value) != null ? _b : props.defaultValue) != null ? _c : "");
    const formItemContext = useInjectFormItemContext();
    const formItemInputContext = FormItemInputContext.useInject();
    const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
    useProvideOverride({
      prefixCls: computed(() => `${prefixCls.value}-menu`),
      mode: computed(() => "vertical"),
      selectable: computed(() => false),
      onClick: () => {
      },
      validator: ({
        mode
      }) => {
        devWarning(!mode || mode === "vertical", "Mentions", `mode="${mode}" is not supported for Mentions's Menu.`);
      }
    });
    watch(() => props.value, (val) => {
      value.value = val;
    });
    const handleFocus = (e) => {
      focused.value = true;
      emit("focus", e);
    };
    const handleBlur = (e) => {
      focused.value = false;
      emit("blur", e);
      formItemContext.onFieldBlur();
    };
    const handleSelect = (...args) => {
      emit("select", ...args);
      focused.value = true;
    };
    const handleChange = (val) => {
      if (props.value === void 0)
        value.value = val;
      emit("update:value", val);
      emit("change", val);
      formItemContext.onFieldChange();
    };
    const getNotFoundContent = () => {
      const notFoundContent = props.notFoundContent;
      if (notFoundContent !== void 0)
        return notFoundContent;
      if (slots.notFoundContent)
        return slots.notFoundContent();
      return renderEmpty("Select");
    };
    const getOptions = () => {
      var _a2;
      return flattenChildren(((_a2 = slots.default) == null ? void 0 : _a2.call(slots)) || []).map((item) => {
        var _a3, _b2;
        return {
          ...getOptionProps(item),
          label: (_b2 = (_a3 = item.children) == null ? void 0 : _a3.default) == null ? void 0 : _b2.call(_a3)
        };
      });
    };
    const focus = () => {
      vcMentions.value.focus();
    };
    const blur = () => {
      vcMentions.value.blur();
    };
    expose({
      focus,
      blur
    });
    const mentionsfilterOption = computed(() => props.loading ? loadingFilterOption : props.filterOption);
    return () => {
      const {
        disabled,
        getPopupContainer,
        rows = 1,
        id = formItemContext.id.value,
        ...restProps
      } = props;
      const {
        hasFeedback,
        feedbackIcon
      } = formItemInputContext;
      const {
        class: className,
        ...otherAttrs
      } = attrs;
      const otherProps = omit(restProps, ["defaultValue", "onUpdate:value", "prefixCls"]);
      const mergedClassName = classNames({
        [`${prefixCls.value}-disabled`]: disabled,
        [`${prefixCls.value}-focused`]: focused.value,
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      }, getStatusClassNames(prefixCls.value, mergedStatus.value), !hasFeedback && className, hashId.value);
      const getMentionsProps = {
        prefixCls: prefixCls.value,
        ...otherProps,
        disabled,
        direction: direction.value,
        filterOption: mentionsfilterOption.value,
        getPopupContainer,
        options: props.loading ? [{
          value: "ANTDV_SEARCHING",
          disabled: true,
          label: createVNode(Spin, {
            "size": "small"
          }, null)
        }] : props.options || getOptions(),
        class: mergedClassName,
        ...otherAttrs,
        rows,
        onChange: handleChange,
        onSelect: handleSelect,
        onFocus: handleFocus,
        onBlur: handleBlur,
        ref: vcMentions,
        value: value.value,
        id
      };
      const mentions = createVNode(VcMentions, {
        ...getMentionsProps,
        "dropdownClassName": hashId.value
      }, {
        notFoundContent: getNotFoundContent,
        option: slots.option
      });
      if (hasFeedback) {
        return wrapSSR(createVNode("div", {
          "class": classNames(`${prefixCls.value}-affix-wrapper`, getStatusClassNames(`${prefixCls.value}-affix-wrapper`, mergedStatus.value, hasFeedback), className, hashId.value)
        }, [mentions, createVNode("span", {
          "class": `${prefixCls.value}-suffix`
        }, [feedbackIcon])]));
      }
      return wrapSSR(mentions);
    };
  }
});

export { AMentions as default };
//# sourceMappingURL=Mentions.mjs.map
