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

export interface ProjectNavigation {
  prev: { slug: string; title: string } | null
  next: { slug: string; title: string } | null
}

interface ProjectResponse {
  data: Project
  meta: { lang: string }
  navigation: ProjectNavigation
}

interface ProjectError {
  error: {
    code: string
    message: string
  }
}

export function useFetchProject(slug: string | Ref<string>) {
  const config = useRuntimeConfig()
  const { locale } = useI18n()
  const slugValue = toValue(slug)

  return useFetch<ProjectResponse, ProjectError>(`/projects/${slugValue}`, {
    baseURL: config.public.apiUrl as string,
    headers: {
      'X-API-Key': config.public.apiKey as string,
      'Accept-Language': locale.value,
    },
  })
}
