'use client'; import {useState} from 'react'; import {VStack, HStack} from '@astryxdesign/core/Layout'; import {FormLayout} from '@astryxdesign/core/FormLayout'; import {Selector} from '@astryxdesign/core/Selector'; import {Button} from '@astryxdesign/core/Button'; import {Text} from '@astryxdesign/core/Text'; import {useToast} from '@astryxdesign/core/Toast'; import {StaticPanel} from '@/shared/components/patterns/PanelCard'; import {useThemeMode} from '@/shared/providers/ThemeModeProvider'; import type {ThemeMode} from '@/shared/theme/themeMode'; /** Theme mode is deliberately absent — it lives in ThemeModeProvider. */ export interface SystemPreferences { currency: 'INR' | 'USD' | 'EUR' | 'GBP'; language: 'en' | 'hi' | 'kn' | 'ta'; dateFormat: 'DD/MM/YYYY' | 'MM/DD/YYYY' | 'YYYY-MM-DD'; defaultLanding: '/dashboard' | '/stores' | '/lyts' | '/staff'; } const DEFAULT_PREFS: SystemPreferences = { currency: 'INR', language: 'en', dateFormat: 'DD/MM/YYYY', defaultLanding: '/dashboard', }; export function PreferencesForm() { const toast = useToast(); /** * Theme is the one preference that does NOT go through the save cycle. * It repaints the workspace the instant it changes and persists itself to * the theme-mode cookie, so there is nothing left for Save to commit — and * a mode you can see but have not "saved" would be the confusing state. * The rest of the form is still mock local state. */ const {mode: themeMode, setMode: setThemeMode} = useThemeMode(); const [prefs, setPrefs] = useState(DEFAULT_PREFS); const [savedPrefs, setSavedPrefs] = useState(DEFAULT_PREFS); const [isSaving, setIsSaving] = useState(false); const set = ( key: K, val: SystemPreferences[K], ) => setPrefs((p) => ({...p, [key]: val})); const isDirty = JSON.stringify(prefs) !== JSON.stringify(savedPrefs); const handleSave = () => { setIsSaving(true); setTimeout(() => { setSavedPrefs(prefs); setIsSaving(false); toast({body: 'Workspace preferences updated'}); }, 400); }; return ( {isDirty ? ( Unsaved changes ) : null}