'use strict';

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

var vue = require('vue');
var classNames = require('../_util/classNames.js');
var index$1 = require('../_util/vue-types/index.js');
require('../vc-mentions/index.js');
var mentionsProps$1 = require('../vc-mentions/src/mentionsProps.js');
require('../hooks/index.js');
var index$2 = require('../_util/props-util/index.js');
var FormItemContext = require('../form/FormItemContext.js');
var omit = require('../_util/omit.js');
var Option = require('../vc-mentions/src/Option.js');
var statusUtils = require('../_util/statusUtils.js');
var OverrideContext = require('../menu/src/OverrideContext.js');
var warning = require('../_util/warning.js');
require('../spin/index.js');
var devWarning = require('../vc-util/devWarning.js');
var index$3 = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var Spin = require('../spin/Spin.js');
var Mentions$1 = require('../vc-mentions/src/Mentions.js');

function loadingFilterOption() {
  return true;
}
const getMentions = (value = "", config = {}) => {
  const {
    prefix = "@",
    split = " "
  } = config;
  const prefixList = Array.isArray(prefix) ? prefix : [prefix];
  return value.split(split).map((str = "") => {
    let hitPrefix = null;
    prefixList.some((prefixStr) => {
      const startStr = str.slice(0, prefixStr.length);
      if (startStr === prefixStr) {
        hitPrefix = prefixStr;
        return true;
      }
      return false;
    });
    if (hitPrefix !== null) {
      return {
        prefix: hitPrefix,
        value: str.slice(hitPrefix.length)
      };
    }
    return null;
  }).filter((entity) => !!entity && !!entity.value);
};
const mentionsProps = () => ({
  ...mentionsProps$1.mentionsProps,
  "loading": {
    type: Boolean,
    default: void 0
  },
  "onFocus": {
    type: Function
  },
  "onBlur": {
    type: Function
  },
  "onSelect": {
    type: Function
  },
  "onChange": {
    type: Function
  },
  "onPressenter": {
    type: Function
  },
  "onUpdate:value": {
    type: Function
  },
  "notFoundContent": index$1.default.any,
  "defaultValue": String,
  "id": String,
  "status": String
});
const Mentions = /* @__PURE__ */ vue.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.default(!index$2.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$3.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
      }) => {
        warning.default(!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 index$2.flattenChildren(((_a2 = slots.default) == null ? void 0 : _a2.call(slots)) || []).map((item) => {
        var _a3, _b2;
        return {
          ...index$2.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.default(restProps, ["defaultValue", "onUpdate:value", "prefixCls"]);
      const mergedClassName = classNames.default({
        [`${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 mentionsProps2 = {
        prefixCls: prefixCls.value,
        ...otherProps,
        disabled,
        direction: direction.value,
        filterOption: mentionsfilterOption.value,
        getPopupContainer,
        options: props.loading ? [{
          value: "ANTDV_SEARCHING",
          disabled: true,
          label: vue.createVNode(Spin.default, {
            "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$1.default, vue.mergeProps(mentionsProps2, {
        "dropdownClassName": hashId.value
      }), {
        notFoundContent: getNotFoundContent,
        option: slots.option
      });
      if (hasFeedback) {
        return wrapSSR(vue.createVNode("div", {
          "class": classNames.default(`${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);
    };
  }
});
const MentionsOption = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  ...Option.optionOptions,
  name: "AMentionsOption",
  props: Option.optionProps
});
var index = Object.assign(Mentions, {
  Option: MentionsOption,
  getMentions,
  install: (app) => {
    app.component(Mentions.name, Mentions);
    app.component(MentionsOption.name, MentionsOption);
    return app;
  }
});

exports.MentionsOption = MentionsOption;
exports.default = index;
exports.mentionsProps = mentionsProps;
//# sourceMappingURL=index.js.map
