import React, { useState, useEffect } from 'react'; import { Save } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; import { supabase } from '../lib/supabase'; const THEME_COLORS = ['red', 'green', 'blue', 'yellow', 'grey', 'purple']; export default function Profile() { const { user } = useAuth(); const [username, setUsername] = useState(''); const [themeColor, setThemeColor] = useState('blue'); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); useEffect(() => { const loadProfile = async () => { if (user) { const { data, error } = await supabase .from('profiles') .select('username, theme_color') .eq('id', user.id) .single(); if (data) { setUsername(data.username || ''); setThemeColor(data.theme_color || 'blue'); } setLoading(false); } }; loadProfile(); }, [user]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!user) return; setSaving(true); try { const { error } = await supabase .from('profiles') .upsert({ id: user.id, username, theme_color: themeColor, updated_at: new Date() }); if (error) throw error; alert('Profile updated successfully!'); } catch (error) { console.error('Error updating profile:', error); alert('Failed to update profile'); } finally { setSaving(false); } }; if (loading) { return (