import { format } from 'date-fns';
import type { DateRange } from '@/services/dashboard.service';

/**
 * Format date range for display in dashboard components
 * Returns a human-readable string describing the active date filter
 */
export function formatDateRangeText(
  dateRange: DateRange,
  customStartDate?: Date,
  customEndDate?: Date,
  prefix: string = 'for'
): string {
  if (dateRange === 'custom' && customStartDate && customEndDate) {
    return `${prefix} ${format(customStartDate, 'MMM d, yyyy')} - ${format(customEndDate, 'MMM d, yyyy')}`;
  }
  
  const rangeMap: Record<DateRange, string> = {
    'all': '(All Time)',
    'today': `${prefix} Today`,
    'week': `${prefix} This Week`,
    'month': `${prefix} This Month`,
    'quarter': `${prefix} This Quarter`,
    'year': `${prefix} This Year`,
    'last30days': `${prefix} Last 30 Days`,
    'custom': `${prefix} Custom Range`
  };
  
  return rangeMap[dateRange] || `${prefix} Selected Period`;
}

/**
 * Format date range for card descriptions
 */
export function formatDateRangeDescription(
  dateRange: DateRange,
  customStartDate?: Date,
  customEndDate?: Date
): string {
  if (dateRange === 'all') {
    return 'All historical data';
  }
  
  if (dateRange === 'custom' && customStartDate && customEndDate) {
    return `Data from ${format(customStartDate, 'MMM d, yyyy')} to ${format(customEndDate, 'MMM d, yyyy')}`;
  }
  
  const rangeMap: Record<DateRange, string> = {
    'all': 'All historical data',
    'today': "Today's data",
    'week': 'This week data',
    'month': 'This month data',
    'quarter': 'This quarter data',
    'year': 'This year data',
    'last30days': 'Last 30 days data',
    'custom': 'Custom date range'
  };
  
  return rangeMap[dateRange] || 'Filtered data';
}

