'use client'; import { useQuery } from '@tanstack/react-query'; import { apiFetch } from '@/lib/api/client'; import { getVocabularyDef, type VocabularyKey } from '@/lib/vocabularies'; interface VocabulariesResponse { data: Record; } /** * Fetches the effective per-port vocabulary list for a key. Falls back * to the shipped defaults when the request hasn't resolved or the key * is missing from the response. Cached for 5 minutes - vocabularies * change rarely and the admin Vocabularies page invalidates by save. */ export function useVocabulary(key: VocabularyKey): readonly string[] { const def = getVocabularyDef(key); const { data } = useQuery({ queryKey: ['vocabularies'], queryFn: () => apiFetch('/api/v1/vocabularies'), staleTime: 5 * 60 * 1000, }); return data?.data[key] ?? def.defaults; }