// useAcademicYears：获取学年列表
// 依据：02-architecture-design.md §4.2 GraphQL 接入

"use client";

import { useQuery, type CombinedError } from "urql";
import { ACADEMIC_YEARS } from "@/lib/graphql/operations";
import type { AcademicYear } from "@/types";

interface AcademicYearsResponse {
  academicYears: AcademicYear[];
}

export function useAcademicYears(): {
  academicYears: AcademicYear[];
  loading: boolean;
  error: CombinedError | undefined;
} {
  const [result] = useQuery<AcademicYearsResponse>({
    query: ACADEMIC_YEARS,
  });

  return {
    academicYears: result.data?.academicYears ?? [],
    loading: result.fetching,
    error: result.error,
  };
}
