export const LEFTOVER_EXPIRING_WITHIN_DAYS = 2;

export function daysUntil(expiresAt: Date): number {
  const ms = expiresAt.getTime() - Date.now();
  return Math.ceil(ms / (1000 * 60 * 60 * 24));
}

export function dishExpiresAt(cookedAt: Date, fridgeDays: number): Date {
  const d = new Date(cookedAt);
  d.setDate(d.getDate() + fridgeDays);
  return d;
}

export function isLeftoverExpiringSoon(cookedAt: Date, fridgeDays: number): boolean {
  const days = daysUntil(dishExpiresAt(cookedAt, fridgeDays));
  return days >= 0 && days <= LEFTOVER_EXPIRING_WITHIN_DAYS;
}
