import { inject, computed, unref, provide } from "vue";
import { f as defaultsKey } from "../../../keys-D5Pj1dmf.mjs";
const useProvideDefaults = (defaults, mergeDefaults) => {
  const injectedDefaults = inject(defaultsKey, null);
  const mergedDefaults = computed(() => {
    const _defaults = unref(defaults);
    if (!injectedDefaults) {
      return _defaults ?? {};
    }
    const merged = { ...injectedDefaults.value };
    if (_defaults) {
      if (mergeDefaults) {
        if (typeof mergeDefaults === "function") {
          return mergeDefaults(merged, _defaults);
        } else if (mergeDefaults === true) {
          return deepMerge(merged, _defaults);
        }
        return Object.assign(merged, _defaults);
      }
      return _defaults;
    }
    return merged;
  });
  provide(defaultsKey, mergedDefaults);
};
function isPlainObject(value) {
  return value !== null && typeof value === "object" && value.constructor === Object && Object.prototype.toString.call(value) === "[object Object]";
}
function deepMerge(target, source, visited = /* @__PURE__ */ new WeakSet()) {
  if (visited.has(source)) {
    return target;
  }
  visited.add(source);
  const result = { ...target };
  for (const key in source) {
    const sourceValue = source[key];
    const targetValue = target[key];
    if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
      result[key] = deepMerge(
        targetValue,
        sourceValue,
        visited
      );
    } else if (Array.isArray(sourceValue)) {
      result[key] = [...sourceValue];
    } else {
      result[key] = sourceValue;
    }
  }
  return result;
}
export {
  useProvideDefaults
};
//# sourceMappingURL=index.mjs.map
