import { useState, useEffect } from 'react'; import { toast } from 'sonner'; import { useQueryClient } from '@tanstack/react-query'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent } from '@/components/ui/card'; import { cn } from '@/lib/utils'; import type { Settings } from '@/types'; const accentColors = [ { name: 'cyan', color: '#06b6d4' }, { name: 'blue', color: '#3b82f6' }, { name: 'purple', color: '#8b5cf6' }, { name: 'orange', color: '#f97316' }, { name: 'green', color: '#22c55e' }, { name: 'red', color: '#ef4444' }, { name: 'pink', color: '#ec4899' }, { name: 'yellow', color: '#eab308' }, ]; interface AppearanceTabProps { settings: Settings | undefined; updateSettings: (updates: Partial) => Promise; isUpdating: boolean; } export default function AppearanceTab({ settings, updateSettings, isUpdating }: AppearanceTabProps) { const queryClient = useQueryClient(); const [selectedColor, setSelectedColor] = useState(settings?.accent_color || 'cyan'); const [firstDayOfWeek, setFirstDayOfWeek] = useState(settings?.first_day_of_week ?? 0); const [upcomingDays, setUpcomingDays] = useState(settings?.upcoming_days || 7); useEffect(() => { if (settings) { setSelectedColor(settings.accent_color); setFirstDayOfWeek(settings.first_day_of_week); setUpcomingDays(settings.upcoming_days); } }, [settings?.id]); const handleColorChange = async (color: string) => { setSelectedColor(color); try { await updateSettings({ accent_color: color }); toast.success('Accent color updated'); } catch { toast.error('Failed to update accent color'); } }; const handleFirstDayChange = async (value: number) => { const previous = firstDayOfWeek; setFirstDayOfWeek(value); try { await updateSettings({ first_day_of_week: value }); queryClient.invalidateQueries({ queryKey: ['calendar-events'] }); toast.success(value === 0 ? 'Week starts on Sunday' : 'Week starts on Monday'); } catch { setFirstDayOfWeek(previous); toast.error('Failed to update first day of week'); } }; const handleUpcomingDaysSave = async () => { if (isNaN(upcomingDays) || upcomingDays < 1 || upcomingDays > 30) return; if (upcomingDays === settings?.upcoming_days) return; try { await updateSettings({ upcoming_days: upcomingDays }); toast.success('Settings updated'); } catch { toast.error('Failed to update settings'); } }; return (
{/* Accent Color */}
{accentColors.map((c) => ( ))}
{/* Calendar & Dashboard */}

Sets which day the calendar week starts on

setUpcomingDays(parseInt(e.target.value))} onBlur={handleUpcomingDaysSave} onKeyDown={(e) => { if (e.key === 'Enter') handleUpcomingDaysSave(); }} className="w-24" disabled={isUpdating} /> days

How many days ahead to show in the upcoming items widget

); }