'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
require('../../menu/index.cjs');
var index$1 = require('../../spin/index.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var log = require('../../../utils/log.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var statusUtils = require('../../../utils/statusUtils.cjs');
var OverrideContext = require('../../menu/src/OverrideContext.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var _class = require('../../../utils/dom/class.cjs');
var Mentions = require('../../../vue-components/vc-mentions/src/Mentions.cjs');

function loadingFilterOption() {
  return true;
}
var AMentions = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AMentions",
  inheritAttrs: false,
  props: props.mentionsProps(),
  slots: Object,
  setup(props, {
    slots,
    emit,
    attrs,
    expose
  }) {
    var _a, _b, _c;
    if (process.env.NODE_ENV !== "production") {
      log.devWarning(!props$1.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.default("mentions", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const focused = vue.shallowRef(false);
    const vcMentions = vue.shallowRef(null);
    const value = vue.shallowRef((_c = (_b = props.value) != null ? _b : props.defaultValue) != null ? _c : "");
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const mergedStatus = vue.computed(() => statusUtils.getMergedStatus(formItemInputContext.status, props.status));
    OverrideContext.useProvideOverride({
      prefixCls: vue.computed(() => `${prefixCls.value}-menu`),
      mode: vue.computed(() => "vertical"),
      selectable: vue.computed(() => false),
      onClick: () => {
      },
      validator: ({
        mode
      }) => {
        log.devWarning(!mode || mode === "vertical", "Mentions", `mode="${mode}" is not supported for Mentions's Menu.`);
      }
    });
    vue.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 props$1.flattenChildren(((_a2 = slots.default) == null ? void 0 : _a2.call(slots)) || []).map((item) => {
        var _a3, _b2;
        return {
          ...props$1.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 = vue.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.omit(restProps, ["defaultValue", "onUpdate:value", "prefixCls"]);
      const mergedClassName = _class.classNames({
        [`${prefixCls.value}-disabled`]: disabled,
        [`${prefixCls.value}-focused`]: focused.value,
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      }, statusUtils.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: vue.createVNode(index$1.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 = vue.createVNode(Mentions.default, {
        ...getMentionsProps,
        "dropdownClassName": hashId.value
      }, {
        notFoundContent: getNotFoundContent,
        option: slots.option
      });
      if (hasFeedback) {
        return wrapSSR(vue.createVNode("div", {
          "class": _class.classNames(`${prefixCls.value}-affix-wrapper`, statusUtils.getStatusClassNames(`${prefixCls.value}-affix-wrapper`, mergedStatus.value, hasFeedback), className, hashId.value)
        }, [mentions, vue.createVNode("span", {
          "class": `${prefixCls.value}-suffix`
        }, [feedbackIcon])]));
      }
      return wrapSSR(mentions);
    };
  }
});

exports.default = AMentions;
//# sourceMappingURL=Mentions.cjs.map
