interface Settings {
  theme: 'light' | 'dark';
  fontFamily: 'serif' | 'sans' | 'mono';
  fontSize: 'small' | 'medium' | 'large' | 'extra-large';
  readingWidth: 'narrow' | 'medium' | 'wide';
  readingSpeed: number; // words per minute
}

const defaultSettings: Settings = {
  theme: 'light',
  fontFamily: 'serif',
  fontSize: 'medium',
  readingWidth: 'medium',
  readingSpeed: 200,
};

export const getReadingSpeed = (): number => {
  try {
    const savedSettings = localStorage.getItem('storycove-settings');
    if (savedSettings) {
      const parsed = JSON.parse(savedSettings);
      return parsed.readingSpeed || defaultSettings.readingSpeed;
    }
  } catch (error) {
    console.error('Failed to parse saved settings:', error);
  }
  return defaultSettings.readingSpeed;
};

export const calculateReadingTime = (wordCount: number): number => {
  const wordsPerMinute = getReadingSpeed();
  return Math.max(1, Math.round(wordCount / wordsPerMinute));
};