import React, { useState } from "react";
function Chatbot() {
const [isOpen, setIsOpen] = useState(false);
const [messages, setMessages] = useState([
{ id: 1, text: "Hello! How can I help you with your financials today?", sender: "bot" }
]);
const [input, setInput] = useState("");
const handleSend = () => {
if (!input.trim()) return;
setMessages([...messages, { id: Date.now(), text: input, sender: "user" }]);
setInput("");
setTimeout(() => {
setMessages(prev => [...prev, { id: Date.now(), text: "I'm a demo bot. I cannot answer queries right now.", sender: "bot" }]);
}, 1000);
};
return (
<>
{/* Floating Icon */}
setIsOpen(!isOpen)}
style={{
position: "fixed",
bottom: "20px",
right: "20px",
width: "50px",
height: "50px",
borderRadius: "25px",
backgroundColor: "#3b82f6",
color: "white",
display: "flex",
justifyContent: "center",
alignItems: "center",
boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
cursor: "pointer",
zIndex: 9999,
fontSize: "24px"
}}
>
💬
{/* Chat Window */}
{isOpen && (
{/* Header */}
AI Assistant
{/* Messages */}
{messages.map(msg => (
{msg.text}
))}
{/* Input Area */}
setInput(e.target.value)}
onKeyPress={e => e.key === "Enter" && handleSend()}
placeholder="Type a message..."
style={{
flex: 1,
padding: "8px 12px",
borderRadius: "20px",
border: "1px solid #cbd5e1",
outline: "none",
fontSize: "13px"
}}
/>
)}
>
);
}
export default Chatbot;