import { useQuery } from '@tanstack/react-query'
import { library, type LibraryStats } from '../services/api'

export const LIBRARY_STATS_QUERY_KEY = ['library', 'stats'] as const

/**
 * Per-section counts for the LeftSidebar badges (All Photos, Rated,
 * Duplicates, Discarded). Cached briefly so navigating around doesn't
 * re-fetch on every click. Mutations that change a photo's rating,
 * discard flag, tags, etc. must invalidate LIBRARY_STATS_QUERY_KEY in
 * their onSuccess so the badges stay live.
 */
export function useLibraryStatsQuery() {
  return useQuery<LibraryStats>({
    queryKey: LIBRARY_STATS_QUERY_KEY,
    queryFn: () => library.stats(),
    staleTime: 30_000,
  })
}
