import { useQuery } from '@tanstack/react-query'
import { tags as tagsApi, type Tag, type TagKind } from '../services/api'

export const TAGS_QUERY_KEY = ['tags'] as const

export function useTagsQuery(kind?: TagKind) {
  return useQuery<Tag[]>({
    queryKey: kind ? ['tags', kind] : TAGS_QUERY_KEY,
    queryFn: () => tagsApi.list(kind),
    staleTime: 30_000,
  })
}
