import { useQuery } from "@tanstack/react-query"
import { useAuthStore } from "@/store/auth-store"
import { fetchWritingHistory } from "@/lib/progress-service"
import type { WritingSubmission } from "@/types"

export function useWritingHistory() {
  const user = useAuthStore((s) => s.user)
  return useQuery<WritingSubmission[]>({
    queryKey: ["writing-history", user?.id],
    queryFn: () => fetchWritingHistory(user!.id) as Promise<WritingSubmission[]>,
    enabled: !!user,
    staleTime: 30_000,
  })
}
