import { computed, getCurrentInstance, inject, provide, unref } from 'vue' import type { MaybeRef, Ref } from 'vue' export function useGlobalConfig( key: string, defaultValue: unknown = undefined, ): Ref { const config = inject('GLOBAL_CONFIG') as MaybeRef if (key) return computed(() => unref(config)?.[key] ?? defaultValue) else return config } export function provideGlobalConfig(config, app) { const inSetup = !!getCurrentInstance() const provideFn = app?.provide ?? (inSetup ? provide : undefined) if (!provideFn) return provideFn('GLOBAL_CONFIG', config) return config }