"use client"; import { useEffect, useState } from "react"; import { LogoutButton } from "@/components/logout-button"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { avatarVibeOptions, defaultProfilePreferences, focusTopicOptions, getProfilePreferences, saveProfilePreferences, type ProfilePreferences, } from "@/lib/profile-preferences-storage"; type ProfilePreferencesFormProps = { email?: string | null; }; export function ProfilePreferencesForm({ email }: ProfilePreferencesFormProps) { const [preferences, setPreferences] = useState( defaultProfilePreferences, ); const [isReady, setIsReady] = useState(false); const [error, setError] = useState(null); const [isSaving, setIsSaving] = useState(false); useEffect(() => { async function loadPreferences() { try { setPreferences(await getProfilePreferences()); } catch (loadError) { setError( loadError instanceof Error ? loadError.message : "Could not load profile preferences.", ); } finally { setIsReady(true); } } void loadPreferences(); }, []); const updatePreferences = async (updates: Partial) => { const nextPreferences = { ...preferences, ...updates }; setPreferences(nextPreferences); setIsSaving(true); setError(null); try { const savedPreferences = await saveProfilePreferences(nextPreferences); setPreferences(savedPreferences); } catch (saveError) { setPreferences(preferences); setError( saveError instanceof Error ? saveError.message : "Could not save profile preferences.", ); } finally { setIsSaving(false); } }; if (!isReady) { return (

Loading profile...

); } return (
{error ?

{error}

: null} Profile information Your account details.
Focus topic preference Choose the one area you want your pet and daily tasks to focus on. {focusTopicOptions.map((topic) => ( ))} Avatar preferences Personalize your pet's vibe. {avatarVibeOptions.map((vibe) => ( ))} Notification preferences Control reminders for your daily quiz and habits.
void updatePreferences({ dailyReminderEnabled: checked === true }) } />
void updatePreferences({ dailyReminderTime: event.target.value }) } />
Account settings Session and onboarding status.
Onboarding Complete
); }