'use client'; import { useState, useEffect, useCallback } from 'react'; import { settingsStore } from '@/lib/store/settings-store'; /** * Hook to access and update player settings from the settings store * Provides reactive updates when settings change */ export function usePlayerSettings() { const [settings, setSettings] = useState(() => { const stored = settingsStore.getSettings(); return { autoNextEpisode: stored.autoNextEpisode, autoSkipIntro: stored.autoSkipIntro, skipIntroSeconds: stored.skipIntroSeconds, autoSkipOutro: stored.autoSkipOutro, skipOutroSeconds: stored.skipOutroSeconds, showModeIndicator: stored.showModeIndicator, }; }); // Subscribe to settings changes useEffect(() => { const unsubscribe = settingsStore.subscribe(() => { const stored = settingsStore.getSettings(); setSettings({ autoNextEpisode: stored.autoNextEpisode, autoSkipIntro: stored.autoSkipIntro, skipIntroSeconds: stored.skipIntroSeconds, autoSkipOutro: stored.autoSkipOutro, skipOutroSeconds: stored.skipOutroSeconds, showModeIndicator: stored.showModeIndicator, }); }); return unsubscribe; }, []); const updateSetting = useCallback(( key: K, value: typeof settings[K] ) => { const currentSettings = settingsStore.getSettings(); settingsStore.saveSettings({ ...currentSettings, [key]: value, }); }, []); const setAutoNextEpisode = useCallback((value: boolean) => { updateSetting('autoNextEpisode', value); }, [updateSetting]); const setAutoSkipIntro = useCallback((value: boolean) => { updateSetting('autoSkipIntro', value); }, [updateSetting]); const setSkipIntroSeconds = useCallback((value: number) => { updateSetting('skipIntroSeconds', Math.max(0, value)); }, [updateSetting]); const setAutoSkipOutro = useCallback((value: boolean) => { updateSetting('autoSkipOutro', value); }, [updateSetting]); const setSkipOutroSeconds = useCallback((value: number) => { updateSetting('skipOutroSeconds', Math.max(0, value)); }, [updateSetting]); const setShowModeIndicator = useCallback((value: boolean) => { updateSetting('showModeIndicator', value); }, [updateSetting]); return { ...settings, setAutoNextEpisode, setAutoSkipIntro, setSkipIntroSeconds, setAutoSkipOutro, setSkipOutroSeconds, setShowModeIndicator, }; }