'use client'

import { useEffect } from 'react'
import { hexToOklch, calculateBrightness } from '@/lib/helpers/colorUtils'

export function ThemeColorSetter() {
  useEffect(() => {
    try {
      const savedColor = localStorage.getItem('theme-primary-color')
      if (savedColor) {
        const oklchColor = hexToOklch(savedColor)
        
        if (oklchColor) {
          document.documentElement.style.setProperty('--primary', oklchColor)
          
          const brightness = calculateBrightness(savedColor)
          const foregroundOklch = brightness > 0.5 ? 'oklch(0 0 0)' : 'oklch(1 0 0)'
          document.documentElement.style.setProperty('--primary-foreground', foregroundOklch)
        }
      }
    } catch (e) {
      // Silent fail
    }
  }, [])

  return null
}

