import { openmrsFetch, restBaseUrl, type Location } from '@openmrs/esm-framework'; import useSWR from 'swr'; export function useSearchableLocations(searchTerm: string) { const apiUrl = `${restBaseUrl}/location?q=${searchTerm}&v=full`; const { data, error, isLoading, isValidating } = useSWR<{ data: { results: Array } }, Error>( searchTerm ? apiUrl : null, // Only fetch if there's a search term openmrsFetch, ); return { locations: data ? data.data?.results : [], isLoading, error, isValidating, }; }