import { createContext, useContext, useState, useEffect, ReactNode } from 'react'; interface AppSettings { scrollToTopThreshold: number; // 0.5 = 50%, 0.7 = 70%, etc. } interface AppSettingsContextType { settings: AppSettings; updateSettings: (newSettings: Partial) => void; } const defaultSettings: AppSettings = { scrollToTopThreshold: 0.7, }; const AppSettingsContext = createContext(undefined); const STORAGE_KEY = 'opencrm_app_settings'; export function AppSettingsProvider({ children }: { children: ReactNode }) { const [settings, setSettings] = useState(() => { const stored = localStorage.getItem(STORAGE_KEY); if (stored) { try { return { ...defaultSettings, ...JSON.parse(stored) }; } catch { return defaultSettings; } } return defaultSettings; }); useEffect(() => { localStorage.setItem(STORAGE_KEY, JSON.stringify(settings)); }, [settings]); const updateSettings = (newSettings: Partial) => { setSettings(prev => ({ ...prev, ...newSettings })); }; return ( {children} ); } export function useAppSettings() { const context = useContext(AppSettingsContext); if (!context) { throw new Error('useAppSettings must be used within AppSettingsProvider'); } return context; }