import { computed, inject, provide, ref, unref } from "vue";
import { deepMerge } from "@veno-ui/utils";
const DefaultsKey = Symbol.for("veno-ui:defaults");
function createDefaults(options) {
  return ref(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?.scoped);
    const reset = unref(options?.reset);
    const root = unref(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
