import { useMemo } from 'react'
import { useSchoolYear } from '../context/SchoolYearContext'

export function useSelectedSchoolYearParams() {
  const { selectedSchoolYear, selectedSchoolYearName, isReadOnlyYear } = useSchoolYear()

  return useMemo(() => {
    const schoolYear = selectedSchoolYearName
    const query = new URLSearchParams()
    const headers: Record<string, string> = {}

    if (schoolYear) {
      query.set('school_year', schoolYear)
      headers['X-School-Year'] = schoolYear
    }

    const queryString = query.toString()

    return {
      schoolYear,
      query,
      queryString,
      headers,
      isReadOnly: selectedSchoolYear ? isReadOnlyYear : false,
    }
  }, [isReadOnlyYear, selectedSchoolYear, selectedSchoolYearName])
}
