import { useState } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; export default function PrintChatBot() { const [messages, setMessages] = useState([ { role: "bot", text: "Hi there! What print product do you need today?" }, ]); const [input, setInput] = useState(""); const handleSend = async () => { if (!input.trim()) return; const userMessage = { role: "user", text: input }; setMessages((prev) => [...prev, userMessage]); setInput(""); const botReply = await getBotReply([...messages, userMessage]); setMessages((prev) => [...prev, { role: "bot", text: botReply }]); }; const getBotReply = async (conversation) => { const lastMessage = conversation[conversation.length - 1].text.toLowerCase(); if (lastMessage.includes("flyer") || lastMessage.includes("brochure")) { return "Got it. How many do you need, and would you like glossy or matte paper?"; } if (lastMessage.includes("glossy")) { return "Great. Standard A5 glossy flyers, double-sided, 150gsm. Quantity?"; } if (lastMessage.includes("500") || lastMessage.includes("1000")) { return "Perfect. I’ll summarize your order and give you a quote next."; } return "Thanks! Can you tell me more about the size, paper type, or quantity you had in mind?"; }; return (
{messages.map((msg, idx) => (
{msg.text}
))}
setInput(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleSend()} />
); }