import { useState, useEffect } from "react"; import { Plus } from "lucide-react"; import { cn } from "../lib/utils"; import { conversationService } from "../api/conversationService"; type Conversation = { title: string; id: string; }; type ConversationProps = { conversations: Conversation[]; onSelectConversation: (conversation: Conversation) => void; onCreateNewConversation: () => void; selectedId?: string; variant?: "dark" | "light"; }; export const ConversationList = ({ conversations, onSelectConversation, onCreateNewConversation, selectedId, variant = "dark", }: ConversationProps) => { const [items, setItems] = useState(conversations); useEffect(() => { const load = async () => { try { let fetched = await conversationService.getAllConversations(); if (fetched.length === 0) { await conversationService.createConversation(); fetched = await conversationService.getAllConversations(); } setItems(fetched.map((c) => ({ id: c.id, title: c.name }))); } catch (err) { console.error("Failed to load conversations:", err); } }; load(); }, []); // Keep in sync when parent updates conversations useEffect(() => { setItems(conversations); }, [conversations]); return (