import { ofetch } from 'ofetch' import { useComponentsConfig } from '../config' import type { ReuseTopic, ReuseType } from '../types/reuses' import { useTranslation } from '../composables/useTranslation' let reuseTypesRequest: Promise> | null = null export function useFetchReuseTypes() { const config = useComponentsConfig() const { locale } = useTranslation() return async (): Promise> => { if (reuseTypesRequest) { return reuseTypesRequest } return await (reuseTypesRequest = ofetch>('api/1/reuses/types/', { baseURL: config.apiBase, query: { lang: locale }, })) } } export function getType(types: Array, id: string): string { const type = types.find(t => t.id === id) return type ? type.label : '' } export function getTopic(topics: Array, id: string): string { const topic = topics.find(t => t.id === id) return topic ? topic.label : '' }