import { format, parseISO } from 'date-fns';
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

export function formatDate(dateString: string, formatString: string = 'MMM dd, yyyy'): string {
  return format(new Date(dateString), formatString);
}

export function formatDateTime(dateString: string, timeString: string): string {
  return `${format(new Date(dateString), 'MMM dd, yyyy')} at ${timeString}`;
}

export function formatDateRange(startDateStr: string, endDateStr: string): string {
  const startDate = parseISO(startDateStr);
  const endDate = parseISO(endDateStr);
  const startYear = startDate.getFullYear();
  const endYear = endDate.getFullYear();

  return startYear === endYear
    ? `${format(startDate, "MMM d")} - ${format(endDate, "MMM d, yyyy")}`
    : `${format(startDate, "MMM d, yyyy")} - ${format(endDate, "MMM d, yyyy")}`;
}

export function getStatusColor(status: 'normal' | 'warning' | 'critical'): string {
  switch (status) {
    case 'normal':
      return 'text-green-600';
    case 'warning':
      return 'text-yellow-600';
    case 'critical':
      return 'text-red-600';
    default:
      return 'text-gray-600';
  }
}

export function getSeverityColor(severity: 'mild' | 'moderate' | 'severe'): string {
  switch (severity) {
    case 'mild':
      return 'text-green-600 bg-green-50';
    case 'moderate':
      return 'text-yellow-600 bg-yellow-50';
    case 'severe':
      return 'text-red-600 bg-red-50';
    default:
      return 'text-gray-600 bg-gray-50';
  }
}

