/**
 * Centralized Color Palette Configuration
 * Single source of truth for all application colors
 */

// Base Color Palette - Professional Bakery Theme
export const baseColors = {
  // Primary Colors - Warm Orange (Bakery Brand)
  primary: {
    50: '#fffbeb',
    100: '#fef3c7',
    200: '#fde68a',
    300: '#fcd34d',
    400: '#fbbf24',
    500: '#f59e0b',
    600: '#d97706', // Main brand color
    700: '#b45309',
    800: '#92400e',
    900: '#78350f',
  },

  // Secondary Colors - Professional Sage Green
  secondary: {
    50: '#f0fdf4',
    100: '#dcfce7',
    200: '#bbf7d0',
    300: '#86efac',
    400: '#4ade80',
    500: '#22c55e',
    600: '#16a34a', // Main secondary color
    700: '#15803d',
    800: '#166534',
    900: '#14532d',
  },

  // Semantic Colors
  success: {
    50: '#ecfdf5',
    100: '#d1fae5',
    200: '#a7f3d0',
    300: '#6ee7b7',
    400: '#34d399',
    500: '#10b981',
    600: '#059669',
    700: '#047857',
    800: '#065f46',
    900: '#064e3b',
  },

  warning: {
    50: '#fffbeb',
    100: '#fef3c7',
    200: '#fde68a',
    300: '#fcd34d',
    400: '#fbbf24',
    500: '#f59e0b',
    600: '#ea580c', // Distinct from primary
    700: '#c2410c',
    800: '#9a3412',
    900: '#7c2d12',
  },

  error: {
    50: '#fef2f2',
    100: '#fee2e2',
    200: '#fecaca',
    300: '#fca5a5',
    400: '#f87171',
    500: '#ef4444',
    600: '#dc2626',
    700: '#b91c1c',
    800: '#991b1b',
    900: '#7f1d1d',
  },

  info: {
    50: '#eff6ff',
    100: '#dbeafe',
    200: '#bfdbfe',
    300: '#93c5fd',
    400: '#60a5fa',
    500: '#3b82f6',
    600: '#0284c7',
    700: '#0369a1',
    800: '#075985',
    900: '#0c4a6e',
  },

  // Neutral Colors (Grayscale)
  neutral: {
    50: '#f8fafc',
    100: '#f1f5f9',
    200: '#e2e8f0',
    300: '#cbd5e1',
    400: '#94a3b8',
    500: '#64748b',
    600: '#475569',
    700: '#334155',
    800: '#1e293b',
    900: '#0f172a',
  },
};

// Professional Bakery Accent Colors
export const bakeryColors = {
  sourdough: '#d4a574',
  wholeWheat: '#a67c52',
  brioche: '#f4e4bc',
  rye: '#8b6f47',
  croissant: '#f5d76e',
  danish: '#e8b4cb',
  espresso: '#3c2415',
  latte: '#c8a882',
  bread: '#deb887',
  wheat: '#f5deb3',
  flour: '#faf0e6',
  butter: '#fff8dc',
  chocolate: '#8b4513',
  vanilla: '#f5f5dc',
  strawberry: '#ff69b4',
  mint: '#98fb98',
  caramel: '#d2691e',
  cream: '#fffdd0',
};

// Status Colors for Cards and Components
export const statusColors = {
  // Order/Production Statuses
  pending: {
    primary: '#f59e0b',
    light: '#fef3c7',
    dark: '#d97706',
  },
  inProgress: {
    primary: '#3b82f6',
    light: '#dbeafe',
    dark: '#2563eb',
  },
  completed: {
    primary: '#10b981',
    light: '#d1fae5',
    dark: '#059669',
  },
  cancelled: {
    primary: '#ef4444',
    light: '#fee2e2',
    dark: '#dc2626',
  },
  // Inventory Statuses
  normal: {
    primary: '#10b981',
    light: '#d1fae5',
    dark: '#059669',
  },
  low: {
    primary: '#f59e0b',
    light: '#fef3c7',
    dark: '#d97706',
  },
  out: {
    primary: '#ef4444',
    light: '#fee2e2',
    dark: '#dc2626',
  },
  expired: {
    primary: '#ef4444',
    light: '#fee2e2',
    dark: '#dc2626',
  },
  // Purchase Order Statuses
  approved: {
    primary: '#3b82f6',
    light: '#dbeafe',
    dark: '#2563eb',
  },
  inTransit: {
    primary: '#8b5cf6',
    light: '#ede9fe',
    dark: '#7c3aed',
  },
  delivered: {
    primary: '#10b981',
    light: '#d1fae5',
    dark: '#059669',
  },
  // Recipe Categories
  bread: {
    primary: '#8b5cf6',
    light: '#ede9fe',
    dark: '#7c3aed',
  },
  pastry: {
    primary: '#f59e0b',
    light: '#fef3c7',
    dark: '#d97706',
  },
  cake: {
    primary: '#ef4444',
    light: '#fee2e2',
    dark: '#dc2626',
  },
  cookie: {
    primary: '#3b82f6',
    light: '#dbeafe',
    dark: '#2563eb',
  },
  other: {
    primary: '#6b7280',
    light: '#f3f4f6',
    dark: '#4b5563',
  },
};

// Chart Colors (Colorblind-Safe Data Visualization)
export const chartColors = {
  primary: '#d97706',    // Orange
  secondary: '#0369a1',  // Blue  
  tertiary: '#16a34a',   // Green
  quaternary: '#dc2626', // Red
  quinary: '#7c3aed',    // Purple
  senary: '#0891b2',     // Cyan
  septenary: '#ea580c',  // Orange variant
  octonary: '#059669',   // Emerald
};

// Light Theme Color Mapping
export const lightTheme = {
  // Backgrounds
  bg: {
    primary: '#ffffff',
    secondary: '#f8fafc',
    tertiary: '#f1f5f9', 
    quaternary: '#e2e8f0',
    overlay: 'rgba(255, 255, 255, 0.8)',
    modalBackdrop: 'rgba(0, 0, 0, 0.5)',
  },

  // Text Colors
  text: {
    primary: '#0f172a',
    secondary: '#475569',
    tertiary: '#64748b',
    quaternary: '#94a3b8',
    inverse: '#ffffff',
    muted: '#64748b',
    disabled: '#cbd5e1',
  },

  // Borders
  border: {
    primary: '#e2e8f0',
    secondary: '#cbd5e1',
    tertiary: '#94a3b8',
    focus: '#d97706',
    error: '#dc2626',
    success: '#059669',
  },

  // Surfaces
  surface: {
    primary: '#ffffff',
    secondary: '#f8fafc',
    tertiary: '#f1f5f9',
    raised: '#ffffff',
    overlay: 'rgba(255, 255, 255, 0.95)',
  },

  // Component-specific
  input: {
    bg: '#ffffff',
    border: '#d1d5db',
    borderFocus: '#d97706',
    borderError: '#dc2626',
    placeholder: '#9ca3af',
  },

  nav: {
    bg: '#ffffff',
    border: '#e5e7eb',
    itemHover: '#f9fafb',
    itemActive: '#fef3c7',
  },

  card: {
    bg: '#ffffff',
    border: '#e5e7eb',
    shadow: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
  },
};

// Dark Theme Color Mapping
export const darkTheme = {
  // Backgrounds
  bg: {
    primary: '#0f172a',
    secondary: '#1e293b',
    tertiary: '#334155',
    quaternary: '#475569',
    overlay: 'rgba(0, 0, 0, 0.8)',
    modalBackdrop: 'rgba(0, 0, 0, 0.75)',
  },

  // Text Colors
  text: {
    primary: '#f8fafc',
    secondary: '#cbd5e1',
    tertiary: '#94a3b8',
    quaternary: '#64748b',
    inverse: '#0f172a',
    muted: '#64748b',
    disabled: '#475569',
  },

  // Borders
  border: {
    primary: '#334155',
    secondary: '#475569',
    tertiary: '#64748b',
    focus: '#f59e0b',
    error: '#ef4444',
    success: '#22c55e',
  },

  // Surfaces
  surface: {
    primary: '#1e293b',
    secondary: '#334155',
    tertiary: '#475569',
    raised: '#1e293b',
    overlay: 'rgba(15, 23, 42, 0.95)',
  },

  // Component-specific
  input: {
    bg: '#1e293b',
    border: '#475569',
    borderFocus: '#f59e0b',
    borderError: '#ef4444',
    placeholder: '#64748b',
  },

  nav: {
    bg: '#1e293b',
    border: '#334155',
    itemHover: '#334155',
    itemActive: 'rgba(245, 158, 11, 0.2)',
  },

  card: {
    bg: '#1e293b',
    border: '#334155',
    shadow: '0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4)',
  },
};

// Export for Tailwind Config
export const tailwindColorConfig = {
  ...baseColors,
  bakery: bakeryColors,
  chart: chartColors,
};

// CSS Custom Properties Generator
export const generateCSSVariables = (theme = 'light') => {
  const themeColors = theme === 'light' ? lightTheme : darkTheme;
  const semanticColors = baseColors;
  
  const cssVars = {};
  
  // Generate semantic color variables
  Object.entries(semanticColors).forEach(([colorName, colorScale]) => {
    if (typeof colorScale === 'object') {
      Object.entries(colorScale).forEach(([scale, value]) => {
        cssVars[`--color-${colorName}-${scale}`] = value;
      });
      // Main color (600 scale as default)
      cssVars[`--color-${colorName}`] = colorScale[600];
    }
  });
  
  // Generate theme-specific variables
  Object.entries(themeColors).forEach(([categoryName, category]) => {
    Object.entries(category).forEach(([propertyName, value]) => {
      cssVars[`--${categoryName}-${propertyName}`] = value;
    });
  });
  
  // Generate bakery colors
  Object.entries(bakeryColors).forEach(([colorName, value]) => {
    cssVars[`--color-${colorName}`] = value;
  });
  
  // Generate chart colors
  Object.entries(chartColors).forEach(([colorName, value]) => {
    cssVars[`--chart-${colorName}`] = value;
  });
  
  return cssVars;
};

export default {
  baseColors,
  bakeryColors,
  statusColors,
  chartColors,
  lightTheme,
  darkTheme,
  tailwindColorConfig,
  generateCSSVariables,
};