import { defineComponent, inject, PropType, provide, renderSlot, Component, computed, type ComputedRef, } from 'vue'; import { RACE_KEY } from './consts'; const injectKey = 'wc3ui-config'; type InternalAPI = { readonly theme: ComputedRef } type IConfigAPI = { theme: ComputedRef } export type WidgetsList = Record; export default defineComponent({ props: { theme: { type: String as PropType, default: RACE_KEY.HUMAN, }, }, setup(props, ctx) { // Use computed so theme stays reactive when prop changes const theme = computed(() => props.theme); const api: InternalAPI = { theme }; provide(injectKey, api); return () => renderSlot(ctx.slots, 'default'); }, }); export function useConfig(): IConfigAPI { const config = inject(injectKey) as InternalAPI | undefined; return { // Return a computed ref so consumers can track reactivity with .value theme: computed(() => config?.theme.value ?? RACE_KEY.HUMAN), }; }