import { inject, ref, computed, unref, provide } from "vue";
import { deepMerge } from "../../utils/dist/index.mjs";
const DefaultsKey = Symbol.for("veno-ui:defaults");
function createDefaults(options) {
  return ref(options != null ? options : {});
}
function useDefaults() {
  const defaults = inject(DefaultsKey);
  if (!defaults)
    throw new Error("[VenoUi] Could not find defaults instance");
  return defaults;
}
function provideDefaults(defaults, options) {
  const injectedDefaults = useDefaults();
  const providedDefaults = ref(defaults);
  const newDefaults = computed(() => {
    const scoped = unref(options == null ? void 0 : options.scoped);
    const reset = unref(options == null ? void 0 : options.reset);
    const root = unref(options == null ? void 0 : options.root);
    let properties = deepMerge(providedDefaults.value, {
      prev: injectedDefaults.value
    });
    if (scoped)
      return properties;
    if (reset || root) {
      const len = Number(reset || Infinity);
      for (let i = 0; i <= len; i++) {
        if (!properties.prev)
          break;
        properties = properties.prev;
      }
      return properties;
    }
    return deepMerge(properties.prev, properties);
  });
  provide(DefaultsKey, newDefaults);
  return newDefaults;
}
export {
  DefaultsKey,
  createDefaults,
  provideDefaults,
  useDefaults
};
//# sourceMappingURL=index.mjs.map
