export function formatDate(date: string | Date): string {
  return new Intl.DateTimeFormat('de-DE', { dateStyle: 'medium' }).format(new Date(date))
}

export function formatDateShort(date: string | Date): string {
  return new Intl.DateTimeFormat('de-DE', { day: '2-digit', month: '2-digit' }).format(new Date(date))
}

export function getDaysInRange(start: string, end: string): string[] {
  const days: string[] = []
  const current = new Date(start)
  const endDate = new Date(end)
  while (current <= endDate) {
    days.push(current.toISOString().split('T')[0])
    current.setDate(current.getDate() + 1)
  }
  return days
}

export function getWeekday(date: string): number {
  const d = new Date(date)
  return (d.getDay() + 6) % 7 // 0=Mon, 6=Sun
}

export function isWeekend(date: string): boolean {
  const day = getWeekday(date)
  return day === 5 || day === 6
}

export function addDays(date: string, days: number): string {
  const d = new Date(date)
  d.setDate(d.getDate() + days)
  return d.toISOString().split('T')[0]
}

export function getWeekdayName(date: string): string {
  return new Intl.DateTimeFormat('de-DE', { weekday: 'short' }).format(new Date(date))
}

export function getMonthName(date: string): string {
  return new Intl.DateTimeFormat('de-DE', { month: 'long', year: 'numeric' }).format(new Date(date))
}
