'use client'; import { Fragment, useState, useEffect } from 'react'; import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild, Listbox, ListboxButton, ListboxOptions, ListboxOption } from '@headlessui/react'; import { useTheme } from '@/contexts/ThemeContext'; import { useConfig } from '@/contexts/ConfigContext'; interface SettingsModalProps { isOpen: boolean; setIsOpen: (isOpen: boolean) => void; } const themes = [ { id: 'light' as const, name: 'Light' }, { id: 'dark' as const, name: 'Dark' }, { id: 'system' as const, name: 'System' }, ]; export function SettingsModal({ isOpen, setIsOpen }: SettingsModalProps) { const { theme, setTheme } = useTheme(); const { apiKey, baseUrl, updateConfig } = useConfig(); const [localApiKey, setLocalApiKey] = useState(apiKey); const [localBaseUrl, setLocalBaseUrl] = useState(baseUrl); const selectedTheme = themes.find(t => t.id === theme) || themes[0]; useEffect(() => { setLocalApiKey(apiKey); setLocalBaseUrl(baseUrl); }, [apiKey, baseUrl]); return ( setIsOpen(false)}>
Settings
setTheme(newTheme.id)}>
{selectedTheme.name} {themes.map((theme) => ( `relative cursor-pointer select-none py-2 pl-10 pr-4 ${ active ? 'bg-accent/10 text-accent' : 'text-foreground' }` } value={theme} > {({ selected }) => ( <> {theme.name} {selected ? ( ) : null} )} ))}
setLocalApiKey(e.target.value)} className="w-full rounded-lg bg-background py-2 px-3 text-foreground shadow-sm focus:outline-none focus:ring-2 focus:ring-accent" />
setLocalBaseUrl(e.target.value)} className="w-full rounded-lg bg-background py-2 px-3 text-foreground shadow-sm focus:outline-none focus:ring-2 focus:ring-accent" />
); }