"use client";
import { useState } from "react";
import { Pill, Send } from "lucide-react";
import type { ChatMessage, Citation } from "@duoc-thu/shared-types";
import { ChatBubble, CitationCard, Card, Input, Button, cn } from "@duoc-thu/ui";
import { sendChatMessage } from "@duoc-thu/api-client";
function TypingIndicator() {
return (
);
}
export interface ChatPanelProps {
onCitationClick?: (citation: Citation) => void;
className?: string;
}
export function ChatPanel({ onCitationClick, className }: ChatPanelProps) {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState("");
const [isSending, setIsSending] = useState(false);
async function handleSubmit(event: React.FormEvent) {
event.preventDefault();
const content = input.trim();
if (!content || isSending) return;
const userMessage: ChatMessage = {
id: `local-${messages.length}`,
role: "user",
content,
createdAt: new Date().toISOString(),
};
setMessages((prev) => [...prev, userMessage]);
setInput("");
setIsSending(true);
try {
const response = await sendChatMessage(content);
setMessages((prev) => [...prev, response.message]);
} finally {
setIsSending(false);
}
}
return (
{messages.length === 0 && (
Hỏi về bất kỳ loại thuốc nào
Ví dụ: “Liều dùng paracetamol cho người lớn?” hoặc “Chống chỉ
định của amoxicillin là gì?”
)}
{messages.map((message) => (
{message.citations && message.citations.length > 0 && (
{message.citations.map((citation) => (
onCitationClick(citation) : undefined}
/>
))}
)}
))}
{isSending &&
}
);
}