"use client"; import { useState } from "react"; import { useAuth } from "@/hooks/use-auth"; import { updateProfile, type ProfileField } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { toast } from "sonner"; import { Plus, Trash2 } from "lucide-react"; const MAX_MOODS = 8; export function CustomMoodsEditor({ initial, }: { initial: ProfileField[]; }) { const { token } = useAuth(); const [moods, setMoods] = useState(initial); const [saving, setSaving] = useState(false); const update = (i: number, key: "name" | "value", val: string) => { setMoods((prev) => prev.map((f, j) => (j === i ? { ...f, [key]: val } : f))); }; const add = () => { if (moods.length >= MAX_MOODS) return; setMoods((prev) => [...prev, { name: "", value: "" }]); }; const remove = (i: number) => { setMoods((prev) => prev.filter((_, j) => j !== i)); }; const save = async () => { if (!token) return; const clean = moods.filter((f) => f.name.trim() || f.value.trim()); setSaving(true); try { await updateProfile({ customMoods: clean }, token); setMoods(clean); toast.success("Custom moods saved."); } catch { toast.error("Failed to save custom moods."); } finally { setSaving(false); } }; return (

Custom moods

Add up to {MAX_MOODS} custom moods. These appear alongside the predefined moods when composing a thought.

{moods.map((f, i) => (
update(i, "name", e.target.value)} placeholder="Mood name" className="max-w-[10rem] text-sm" /> update(i, "value", e.target.value)} placeholder="Emoji" className="max-w-[5rem] text-sm" />
))}
{moods.length < MAX_MOODS && ( )}
); }