const activeModuleIds = ref<string[]>([])
const loaded = ref(false)

export function useModules() {
    async function loadModules(): Promise<void> {
        const api = useApi()
        const data = await api.get<{ modules: string[] }>('/modules', {}, { toast: false })
        activeModuleIds.value = data.modules ?? []
        loaded.value = true
    }

    function isModuleActive(id: string): boolean {
        return activeModuleIds.value.includes(id)
    }

    function resetModules(): void {
        activeModuleIds.value = []
        loaded.value = false
    }

    return { activeModuleIds, loaded, loadModules, isModuleActive, resetModules }
}
