import dayjs from "./day.js";

export const DateFormat = "MM/DD/YYYY";
const RuleSets = [
  {
    title: "V1",
    range: [dayjs("2010-01-01"), dayjs("2023-04-01")]
  },
  {
    title: "V2",
    range: [dayjs("2023-04-01"), dayjs("2024-09-01")]
  },
  {
    title: "V3",
    range: [dayjs("2024-09-01"), dayjs("2040-01-01")]
  }
];
//TODO: Verify that this doesnt need to be reversed.
export function ChangeOfRuleSet({ prevDateMoment = dayjs(), newDateMoment = dayjs() }) {
  const prevRuleSet = RuleSets.find(
    (r) => prevDateMoment.isSameOrAfter(r.range[0]) && prevDateMoment.isBefore(r.range[1])
  );

  const newRuleSet = RuleSets.find(
    (r) => newDateMoment.isSameOrAfter(r.range[0]) && newDateMoment.isBefore(r.range[1])
  );

  return prevRuleSet?.title !== newRuleSet?.title;
}

export function WhichMPIRulesetToApply(close_date) {
  const DateMoment = close_date ? dayjs(close_date) : dayjs();
  const newRuleSet = RuleSets.find((r) => DateMoment.isSameOrAfter(r.range[0]) && DateMoment.isBefore(r.range[1]));
  //console.log("Using ruleset:", newRuleSet);

  return newRuleSet?.title;
}