"use client"; import { Mail, SendHorizonal } from "lucide-react"; import { type FormEvent, useMemo, useState } from "react"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from "@/components/ui/empty"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; // All conversations here are mock/placeholder data — there is no messaging // backend. They illustrate the inbox + chat-thread timeline layout. type ChatMessage = { id: string; direction: "in" | "out"; text: string; time: string; }; type Conversation = { id: string; name: string; initials: string; role: string; unread: boolean; messages: ChatMessage[]; }; const seed: Conversation[] = [ { id: "1", name: "Dr. Stein", initials: "DS", role: "Endocrinology", unread: true, messages: [ { id: "1a", direction: "in", text: "The lab results for Amina Yusuf are back — lipid panel and HbA1c are both in range.", time: "10:24", }, { id: "1b", direction: "in", text: "Want me to adjust her plan before the follow-up?", time: "10:25", }, ], }, { id: "2", name: "Dr. Okafor", initials: "DO", role: "Family medicine", unread: true, messages: [ { id: "2a", direction: "out", text: "Sent over Daniel Mensah's intake notes — can you take a look?", time: "08:50", }, { id: "2b", direction: "in", text: "Thanks! Added him to tomorrow at 10:00. Were his prior records imported?", time: "09:12", }, ], }, { id: "3", name: "Care team", initials: "CT", role: "Clinic-wide", unread: false, messages: [ { id: "3a", direction: "in", text: "Seasonal vaccine stock has been replenished — slots are open all week.", time: "Yesterday", }, { id: "3b", direction: "out", text: "Great, I'll direct eligible patients to the front desk.", time: "Yesterday", }, ], }, { id: "4", name: "Reception", initials: "RC", role: "Front desk", unread: false, messages: [ { id: "4a", direction: "in", text: "Two Friday afternoon appointments were moved to next Monday at the patients' request.", time: "Mon", }, ], }, ]; const now = () => new Date().toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: false, }); export function MessagesView() { const [conversations, setConversations] = useState(seed); const [selectedId, setSelectedId] = useState(null); const [showUnreadOnly, setShowUnreadOnly] = useState(false); const [draft, setDraft] = useState(""); const unreadCount = conversations.filter((c) => c.unread).length; const selected = conversations.find((c) => c.id === selectedId) ?? null; const visible = useMemo( () => (showUnreadOnly ? conversations.filter((c) => c.unread) : conversations), [conversations, showUnreadOnly], ); const open = (id: string) => { setSelectedId(id); setDraft(""); setConversations((prev) => prev.map((c) => (c.id === id ? { ...c, unread: false } : c)), ); }; const send = (event: FormEvent) => { event.preventDefault(); const text = draft.trim(); if (!(text && selected)) return; const message: ChatMessage = { id: `${selected.id}-${Date.now()}`, direction: "out", text, time: now(), }; setConversations((prev) => prev.map((c) => c.id === selected.id ? { ...c, messages: [...c.messages, message] } : c, ), ); setDraft(""); }; return (
{/* Left: conversation list */} {/* Right: conversation timeline or empty state */}
{selected ? (
{selected.initials}
{selected.name} {selected.role}
{selected.messages.map((m) => (
{m.text}
{m.time}
))}
setDraft(e.target.value)} placeholder={`Message ${selected.name}…`} value={draft} />
) : (
No conversation selected Choose a conversation from the inbox to read and reply.
)}
); }