const maxInviteExpirationDays = 365;

export function inviteExpiresAt(input: FormDataEntryValue | null, now = Date.now()) {
  const days = Math.trunc(Number(input || 0));
  if (!Number.isFinite(days) || days <= 0) return null;
  return new Date(now + Math.min(days, maxInviteExpirationDays) * 24 * 60 * 60 * 1000);
}

export function isInviteExpired(expiresAt: Date | string | null, now = Date.now()) {
  if (!expiresAt) return false;
  return new Date(expiresAt).getTime() < now;
}
