import moment from "moment";
import { Assignment } from "@/interfaces/results";

export const futureAssignmentFilter = (a: Assignment) => {
	const currentDate = moment();

	if (a.archived) return false;
	if (moment(a.endDate).isBefore(currentDate)) return false;
	if (a.autoStart && moment(a.startDate).isBefore(currentDate)) return false;

	return !a.start;
}

export const pastAssignmentFilter = (a: Assignment) => {
	const currentDate = moment();

	if (a.archived) return false;

	return moment(a.endDate).isBefore(currentDate);
}

export const archivedAssignmentFilter = (a: Assignment) => a.archived;

export const activeAssignmentFilter = (a: Assignment) => {
	const currentDate = moment();
	if (moment(a.endDate).isBefore(currentDate) || a.archived) return false;

	if (a.start) return true;
	if (a.autoStart) return currentDate.isAfter(moment(a.startDate));

	return false
};

export const startHasExpiredAssignmentFilter = (a: Assignment) => {
	const currentDate = moment();
	if (a.archived) return false;
	if (a.start) return false;
	if (currentDate.isAfter(moment(a.startDate)) && currentDate.isBefore(moment(a.endDate))) return true;
	return false;
}
