export const JOBS_TIME_FILTER_VALUES = ['1h', '24h', 'all'] as const;

export type JobsTimeFilter = (typeof JOBS_TIME_FILTER_VALUES)[number];

export const DEFAULT_JOBS_TIME_FILTER: JobsTimeFilter = 'all';

const WINDOW_MS: Record<'1h' | '24h', number> = {
  '1h': 60 * 60 * 1000,
  '24h': 24 * 60 * 60 * 1000,
};

export function isWithinTimeWindow(
  createdAt: Date | string,
  filter: JobsTimeFilter,
  now: number = Date.now(),
): boolean {
  if (filter === 'all') return true;
  const ts = new Date(createdAt).getTime();
  if (Number.isNaN(ts)) return true;
  return ts >= now - WINDOW_MS[filter];
}
