{"version":3,"sources":["../src/themes/ThemeProvider.tsx","../src/themes/theme-loader.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useEffect, useState } from 'react';\n\ntype Theme = 'light' | 'dark' | 'system';\n\ninterface ThemeProviderProps {\n  children: React.ReactNode;\n  defaultTheme?: Theme;\n  storageKey?: string;\n}\n\ninterface ThemeProviderState {\n  theme: Theme;\n  setTheme: (theme: Theme) => void;\n}\n\nconst initialState: ThemeProviderState = {\n  theme: 'system',\n  setTheme: () => null,\n};\n\nconst ThemeProviderContext = createContext<ThemeProviderState>(initialState);\n\nexport function ThemeProvider({\n  children,\n  defaultTheme = 'system',\n  storageKey = 'sf-ui-theme',\n  ...props\n}: ThemeProviderProps) {\n  const [theme, setTheme] = useState<Theme>(\n    () => (typeof window !== 'undefined' ? (localStorage.getItem(storageKey) as Theme) : null) || defaultTheme\n  );\n\n  useEffect(() => {\n    const root = window.document.documentElement;\n\n    root.classList.remove('light', 'dark');\n    root.removeAttribute('data-theme');\n\n    if (theme === 'system') {\n      const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n      root.classList.add(systemTheme);\n      root.setAttribute('data-theme', systemTheme);\n      return;\n    }\n\n    root.classList.add(theme);\n    root.setAttribute('data-theme', theme);\n  }, [theme]);\n\n  const value = {\n    theme,\n    setTheme: (theme: Theme) => {\n      localStorage.setItem(storageKey, theme);\n      setTheme(theme);\n    },\n  };\n\n  return (\n    <ThemeProviderContext.Provider {...props} value={value}>\n      {children}\n    </ThemeProviderContext.Provider>\n  );\n}\n\nexport const useTheme = () => {\n  const context = useContext(ThemeProviderContext);\n\n  if (context === undefined) throw new Error('useTheme must be used within a ThemeProvider');\n\n  return context;\n};\n","/**\n * Theme utilities for managing theme state\n */\n\nexport type ThemeMode = 'light' | 'dark' | 'system';\n\n/**\n * Apply a theme to the document\n */\nexport function applyTheme(theme: ThemeMode): void {\n  if (typeof window === 'undefined') return;\n\n  const root = window.document.documentElement;\n  root.classList.remove('light', 'dark');\n  root.removeAttribute('data-theme');\n\n  if (theme === 'system') {\n    const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n    root.classList.add(systemTheme);\n    root.setAttribute('data-theme', systemTheme);\n    return;\n  }\n\n  root.classList.add(theme);\n  root.setAttribute('data-theme', theme);\n}\n\n/**\n * Toggle between light and dark themes\n */\nexport function toggleTheme(): ThemeMode {\n  if (typeof window === 'undefined') return 'light';\n\n  const root = window.document.documentElement;\n  const currentTheme = root.classList.contains('dark') ? 'dark' : 'light';\n  const newTheme: ThemeMode = currentTheme === 'dark' ? 'light' : 'dark';\n\n  applyTheme(newTheme);\n  return newTheme;\n}\n\n/**\n * Initialize theme from localStorage or system preference\n */\nexport function initializeTheme(storageKey = 'sf-ui-theme'): ThemeMode {\n  if (typeof window === 'undefined') return 'light';\n\n  const stored = localStorage.getItem(storageKey) as ThemeMode | null;\n  const theme = stored || 'system';\n\n  applyTheme(theme);\n  return theme;\n}\n\n/**\n * Get the current resolved theme (not 'system')\n */\nexport function getResolvedTheme(): 'light' | 'dark' {\n  if (typeof window === 'undefined') return 'light';\n\n  const root = window.document.documentElement;\n  return root.classList.contains('dark') ? 'dark' : 'light';\n}\n"],"mappings":";AAGA,SAAS,eAAe,YAAY,WAAW,gBAAgB;AA0D3D;AA3CJ,IAAM,eAAmC;AAAA,EACvC,OAAO;AAAA,EACP,UAAU,MAAM;AAClB;AAEA,IAAM,uBAAuB,cAAkC,YAAY;AAEpE,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA,eAAe;AAAA,EACf,aAAa;AAAA,EACb,GAAG;AACL,GAAuB;AACrB,QAAM,CAAC,OAAO,QAAQ,IAAI;AAAA,IACxB,OAAO,OAAO,WAAW,cAAe,aAAa,QAAQ,UAAU,IAAc,SAAS;AAAA,EAChG;AAEA,YAAU,MAAM;AACd,UAAM,OAAO,OAAO,SAAS;AAE7B,SAAK,UAAU,OAAO,SAAS,MAAM;AACrC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