'use client' import { useEffect, useState } from 'react' import { fetchConfig, saveConfig } from '@/lib/api/config' import { testTelegram, downloadBackup, restoreBackup } from '@/lib/api/system' import { useSettingsStore } from '@/store/settingsStore' const Field = ({ label, k, cfg, onChange, type = 'text', mono = false, }: { label: string; k: string; cfg: Record; onChange: (k: string, v: string) => void; type?: string; mono?: boolean }) => (
onChange(k, e.target.value)} className={`g-input h-8 text-sm flex-1 ${mono ? 'font-mono' : ''}`} />
) const Section = ({ title, children }: { title: string; children: React.ReactNode }) => (

{title}

{children}
) export default function SettingsPage() { const { config, loaded, setConfig, updateKey } = useSettingsStore() const [saving, setSaving] = useState(false) const [msg, setMsg] = useState('') useEffect(() => { if (!loaded) fetchConfig().then(setConfig).catch(() => setConfig({})) }, [loaded, setConfig]) const save = async () => { setSaving(true) try { await saveConfig(config); setMsg('Saved.') } catch { setMsg('Save failed.') } setSaving(false) setTimeout(() => setMsg(''), 3000) } const handleRestore = async (e: React.ChangeEvent) => { const file = e.target.files?.[0] if (!file) return if (!confirm('Restore this backup? Current data will be replaced.')) return try { await restoreBackup(file); setMsg('Restored. Restart engine.') } catch { setMsg('Restore failed.') } } if (!loaded) return (
Loading settings…
) return (

Settings

Engine and alert configuration