import type { Period } from "./types";

const termNames: Record<string, string> = {
    year: "Full School Year",
    semester_1: "First Semester",
    semester_2: "Second Semester",
};
export const periodName = (period: Period) =>
    termNames[period.term_key ?? ""] || period.name;
export const schoolYears = (periods: Period[] = []) =>
    [...new Set(periods.map((p) => p.school_year))].sort().reverse();
export function currentSchoolYear(periods: Period[] = []) {
    const today = new Date().toISOString().slice(0, 10);
    return (
        periods.find(
            (p) =>
                p.starts_on.slice(0, 10) <= today &&
                p.ends_on.slice(0, 10) >= today,
        )?.school_year ||
        schoolYears(periods)[0] ||
        ""
    );
}
export function yearOrGrade(level: string, year: number) {
    if (level !== "college") return `Grade ${year}`;
    return `${year}${year === 1 ? "st" : year === 2 ? "nd" : year === 3 ? "rd" : "th"} Year`;
}
