"use client"

import { useMemo } from "react"

import type { ClassFormGrade } from "../components/class-form-utils"

export interface UseClassFiltersReturn {
  createGrades: ClassFormGrade[]
  editGrades: ClassFormGrade[]
}

/**
 * 按学校筛选年级（admin 模式使用）。
 * createGrades 按 createSchoolId 筛选，editGrades 按 editSchoolId 筛选。
 * grade 模式不使用此 hook（managedGrades 直接展示，无需按学校过滤）。
 */
export function useClassFilters(
  grades: ClassFormGrade[],
  createSchoolId: string,
  editSchoolId: string,
): UseClassFiltersReturn {
  const createGrades = useMemo(
    () => grades.filter((g) => g.schoolId === createSchoolId),
    [grades, createSchoolId],
  )
  const editGrades = useMemo(
    () => grades.filter((g) => g.schoolId === editSchoolId),
    [grades, editSchoolId],
  )
  return { createGrades, editGrades }
}
