import { MessageSquare, Search, SendHorizonal } from "lucide-react" import { useLayoutEffect, useRef, useState } from "react" import { Page } from "@/components/shared/Page" import { Badge } from "@/components/ui/badge" import { Input } from "@/components/ui/input" import { CONVERSATIONS } from "@/data/mockData" import { cn } from "@/lib/utils" import type { Conversation } from "@/data/types" /* =========================================================================== Messages — a real two-pane inbox. Sending is local state only. =========================================================================== */ export function MessagesPage() { const [threads, setThreads] = useState(() => CONVERSATIONS.map((c) => ({ ...c, messages: [...c.messages] })) ) const [activeId, setActiveId] = useState(threads[0].id) const [query, setQuery] = useState("") const [draft, setDraft] = useState("") const endRef = useRef(null) const active = threads.find((t) => t.id === activeId) ?? threads[0] const visible = threads.filter((t) => `${t.name} ${t.role}`.toLowerCase().includes(query.toLowerCase()) ) useLayoutEffect(() => { endRef.current?.scrollIntoView({ block: "end" }) }, [active.messages.length, activeId]) /** Opening a thread marks it read. */ function openThread(id: string) { setActiveId(id) setThreads((prev) => prev.map((t) => (t.id === id && t.unread > 0 ? { ...t, unread: 0 } : t)) ) } function send() { const text = draft.trim() if (!text) return setThreads((prev) => prev.map((t) => t.id === activeId ? { ...t, lastAt: "Now", messages: [ ...t.messages, { id: `local-${t.messages.length}`, from: "me" as const, text, at: "Now" }, ], } : t ) ) setDraft("") } return (
{/* ------------------------------------------------- conversations */} {/* ------------------------------------------------- active thread */}
{active.initials}
{active.name}
{active.role}
Active
{active.messages.map((m) => (

{m.text}

{m.at}

))}
setDraft(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault() send() } }} placeholder={`Message ${active.name.split(" ")[0]}…`} aria-label="Message" className="min-w-0 flex-1 bg-transparent text-[13px] text-ink placeholder:text-ink-3 focus:outline-none" />
) }