import type { Project } from '~/types/project'

interface ProjectsResponse {
  data: Project[]
  meta: { lang: string }
}

export function useFetchProjects() {
  const config = useRuntimeConfig()
  const { locale } = useI18n()

  return useFetch<ProjectsResponse>('/projects', {
    baseURL: config.public.apiUrl as string,
    headers: {
      'X-API-Key': config.public.apiKey as string,
      'Accept-Language': locale.value,
    },
    transform: (response) => response.data,
    default: () => [],
  })
}
