import { GetStaticProps } from "next";

import Term, {
  getStaticProps as termGetStaticProps,
  Props,
} from "./[year]/[term]/index";

export default Term;

export const getStaticProps: GetStaticProps<Props> = async () => {
  const date = new Date();
  let term = "";
  const year = date.getUTCFullYear();
  if (
    new Date(`${year}-01-01`).getTime() <= date.getTime() &&
    date.getTime() <= new Date(`${year}-04-30`).getTime()
  ) {
    term = "winter";
  } else if (
    new Date(`${year}-05-01`).getTime() <= date.getTime() &&
    date.getTime() <= new Date(`${year}-08-31`).getTime()
  ) {
    term = "spring";
  } else if (
    new Date(`${year}-09-01`).getTime() <= date.getTime() &&
    date.getTime() <= new Date(`${year}-12-31`).getTime()
  ) {
    term = "fall";
  }

  const context = {
    params: {
      year: `${year}`,
      term: term,
    },
  };
  return await termGetStaticProps(context);
};
