'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../hooks/index.cjs');
var log = require('../../../utils/log.cjs');
var index = require('../../../hooks/create-context/index.cjs');

const ContextKey = Symbol("ContextProps");
const InternalContextKey = Symbol("InternalContextProps");
function useProvideFormItemContext(props, useValidation = vue.computed(() => true)) {
  const formItemFields = vue.ref(/* @__PURE__ */ new Map());
  const addFormItemField = (key, type) => {
    formItemFields.value.set(key, type);
    formItemFields.value = new Map(formItemFields.value);
  };
  const removeFormItemField = (key) => {
    formItemFields.value.delete(key);
    formItemFields.value = new Map(formItemFields.value);
  };
  const instance = vue.getCurrentInstance();
  vue.watch([useValidation, formItemFields], () => {
    if (process.env.NODE_ENV !== "production") {
      if (useValidation.value && formItemFields.value.size > 1) {
        log.devWarning(
          false,
          "Form.Item",
          `FormItem can only collect one field item, you haved set ${[
            ...formItemFields.value.values()
          ].map((v) => `\`${v.name}\``).join(", ")} ${formItemFields.value.size} field items.
        You can set not need to be collected fields into \`a-form-item-rest\``
        );
        let cur = instance;
        while (cur.parent) {
          console.warn("at", cur.type);
          cur = cur.parent;
        }
      }
    }
  });
  vue.provide(ContextKey, props);
  vue.provide(InternalContextKey, {
    addFormItemField,
    removeFormItemField
  });
}
const defaultContext = {
  id: vue.computed(() => void 0),
  onFieldBlur: () => {
  },
  onFieldChange: () => {
  },
  clearValidate: () => {
  }
};
const defaultInternalContext = {
  addFormItemField: () => {
  },
  removeFormItemField: () => {
  }
};
function useInjectFormItemContext() {
  const internalContext = vue.inject(InternalContextKey, defaultInternalContext);
  const formItemFieldKey = Symbol("FormItemFieldKey");
  const instance = vue.getCurrentInstance();
  internalContext.addFormItemField(formItemFieldKey, instance.type);
  vue.onBeforeUnmount(() => {
    internalContext.removeFormItemField(formItemFieldKey);
  });
  vue.provide(InternalContextKey, defaultInternalContext);
  vue.provide(ContextKey, defaultContext);
  return vue.inject(ContextKey, defaultContext);
}
var AFormItemRest = vue.defineComponent({
  compatConfig: { MODE: 3 },
  name: "AFormItemRest",
  setup(_, { slots }) {
    vue.provide(InternalContextKey, defaultInternalContext);
    vue.provide(ContextKey, defaultContext);
    return () => {
      var _a;
      return (_a = slots.default) == null ? void 0 : _a.call(slots);
    };
  }
});
const FormItemInputContext = index.createContext({});
const NoFormStatus = vue.defineComponent({
  name: "NoFormStatus",
  setup(_, { slots }) {
    FormItemInputContext.useProvide({});
    return () => {
      var _a;
      return (_a = slots.default) == null ? void 0 : _a.call(slots);
    };
  }
});

exports.FormItemInputContext = FormItemInputContext;
exports.NoFormStatus = NoFormStatus;
exports.default = AFormItemRest;
exports.useInjectFormItemContext = useInjectFormItemContext;
exports.useProvideFormItemContext = useProvideFormItemContext;
//# sourceMappingURL=FormItemContext.cjs.map
