export interface DateRange {
  start: Date
  end: Date
}

export interface Preset {
  label: string
  value: string
}

export const DEFAULT_PRESETS: Preset[] = [
  { label: 'Last 1h', value: 'last-1h' },
  { label: 'Last 6h', value: 'last-6h' },
  { label: 'Today', value: 'today' },
  { label: 'Last 24h', value: 'last-24h' },
  { label: 'Last 7d', value: 'last-7d' },
  { label: 'Custom', value: 'custom' },
]

export const PRESET_SHORT_LABELS: Record<string, string> = {
  'last-1h': '1h',
  'last-3h': '3h',
  'last-6h': '6h',
  'today': 'Today',
  'last-24h': '24h',
  'last-7d': '7d',
  'custom': 'Custom',
}

export function computePresetRange(preset: string): DateRange {
  const now = new Date()
  const end = now

  switch (preset) {
    case 'last-1h':
      return { start: new Date(now.getTime() - 60 * 60 * 1000), end }
    case 'last-3h':
      return { start: new Date(now.getTime() - 3 * 60 * 60 * 1000), end }
    case 'last-6h':
      return { start: new Date(now.getTime() - 6 * 60 * 60 * 1000), end }
    case 'today': {
      const start = new Date(now)
      start.setHours(0, 0, 0, 0)
      return { start, end }
    }
    case 'last-24h':
      return { start: new Date(now.getTime() - 24 * 60 * 60 * 1000), end }
    case 'last-7d':
      return { start: new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000), end }
    default:
      return { start: new Date(now.getTime() - 60 * 60 * 1000), end }
  }
}
