"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const shared_esmBundler = require("../../../../@vue/shared/dist/shared.esm-bundler.js");
const error = require("../../utils/error.js");
const runtime = require("../../utils/vue/props/runtime.js");
const Vue = require("vue");
const isEqual = require("../../../../lodash-es/isEqual.js");
const emptyValuesContextKey = Symbol("emptyValuesContextKey");
const SCOPE = "use-empty-values";
const DEFAULT_EMPTY_VALUES = [
  "",
  void 0,
  null
];
const DEFAULT_VALUE_ON_CLEAR = void 0;
const useEmptyValuesProps = runtime.buildProps({
  emptyValues: Array,
  valueOnClear: {
    type: runtime.definePropType([
      String,
      Number,
      Boolean,
      Function
    ]),
    default: void 0,
    validator: (val) => {
      val = shared_esmBundler.isFunction(val) ? val() : val;
      if (shared_esmBundler.isArray(val)) return val.every((item) => !item);
      return !val;
    }
  }
});
const useEmptyValues = (props, defaultValue) => {
  const config = Vue.getCurrentInstance() ? Vue.inject(emptyValuesContextKey, Vue.ref({})) : Vue.ref({});
  const emptyValues = Vue.computed(() => props.emptyValues || config.value.emptyValues || DEFAULT_EMPTY_VALUES);
  const valueOnClear = Vue.computed(() => {
    if (shared_esmBundler.isFunction(props.valueOnClear)) return props.valueOnClear();
    else if (props.valueOnClear !== void 0) return props.valueOnClear;
    else if (shared_esmBundler.isFunction(config.value.valueOnClear)) return config.value.valueOnClear();
    else if (config.value.valueOnClear !== void 0) return config.value.valueOnClear;
    return defaultValue !== void 0 ? defaultValue : DEFAULT_VALUE_ON_CLEAR;
  });
  const isEmptyValue = (value) => {
    let result = true;
    if (shared_esmBundler.isArray(value)) result = emptyValues.value.some((emptyValue) => {
      return isEqual.default(value, emptyValue);
    });
    else result = emptyValues.value.includes(value);
    return result;
  };
  if (!isEmptyValue(valueOnClear.value)) error.debugWarn(SCOPE, "value-on-clear should be a value of empty-values");
  return {
    emptyValues,
    valueOnClear,
    isEmptyValue
  };
};
exports.DEFAULT_EMPTY_VALUES = DEFAULT_EMPTY_VALUES;
exports.DEFAULT_VALUE_ON_CLEAR = DEFAULT_VALUE_ON_CLEAR;
exports.SCOPE = SCOPE;
exports.emptyValuesContextKey = emptyValuesContextKey;
exports.useEmptyValues = useEmptyValues;
exports.useEmptyValuesProps = useEmptyValuesProps;
