/**
 * Convert a time value and unit to milliseconds
 */
export function convertToMilliseconds(value: number, unit: string): number {
  const conversions: Record<string, number> = {
    seconds: 1000,
    minutes: 60 * 1000,
    hours: 60 * 60 * 1000,
    days: 24 * 60 * 60 * 1000,
  };

  return value * (conversions[unit] || 1000);
}

/**
 * Get refresh interval in milliseconds from widget settings
 */
export function getRefreshInterval(
  settings: WidgetSettings,
  defaultValue: number = 60,
  defaultUnit: string = "minutes"
): number {
  const value = (settings.refreshIntervalValue as number) || defaultValue;
  const unit = (settings.refreshIntervalUnit as string) || defaultUnit;
  return convertToMilliseconds(value, unit);
}
