import React, { useState, useEffect, useRef } from 'react';
import styled, { keyframes } from 'styled-components';
const fadeIn = keyframes`
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
`;
const Container = styled.div`
font-family: 'Arial', sans-serif;
max-width: 500px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
`;
const Header = styled.h1`
text-align: center;
color: #333;
`;
const ChatWindow = styled.div`
height: 400px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 5px;
padding: 10px;
background-color: white;
`;
const Message = styled.div`
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
max-width: 80%;
animation: ${fadeIn} 0.3s ease-out;
${props => props.isUser ? `
background-color: #007bff;
color: white;
align-self: flex-end;
margin-left: auto;
` : `
background-color: #f1f0f0;
color: #333;
`}
`;
const Input = styled.input`
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin-top: 10px;
`;
const Button = styled.button`
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
margin-top: 10px;
cursor: pointer;
transition: background-color 0.3s;
&:hover {
background-color: #0056b3;
}
`;
const legalResponses = {
"contract": "A contract is a legally binding agreement between two or more parties. It typically involves an offer, acceptance, and consideration.",
"lawsuit": "A lawsuit is a legal proceeding initiated by one party against another in a court of law.",
"copyright": "Copyright is a form of intellectual property protection granted to original works of authorship, including literary, dramatic, musical, and artistic works.",
"patent": "A patent is a government-granted right that gives an inventor the exclusive right to manufacture, use, and sell their invention for a specific period.",
"trademark": "A trademark is a symbol, word, or phrase used to identify and distinguish the source of goods or services of one party from those of others.",
"default": "I'm sorry, but I don't have specific information about that legal topic. Please consult with a qualified attorney for professional legal advice."
};
const LegalAIChatbot = () => {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const chatWindowRef = useRef(null);
useEffect(() => {
setMessages([{ text: "Hello! I'm a legal AI chatbot. How can I assist you with legal information today?", isUser: false }]);
}, []);
useEffect(() => {
if (chatWindowRef.current) {
chatWindowRef.current.scrollTop = chatWindowRef.current.scrollHeight;
}
}, [messages]);
const handleInputChange = (e) => {
setInput(e.target.value);
};
const handleSend = () => {
if (input.trim() === '') return;
setMessages(prev => [...prev, { text: input, isUser: true }]);
setTimeout(() => {
const botResponse = getBotResponse(input);
setMessages(prev => [...prev, { text: botResponse, isUser: false }]);
}, 500);
setInput('');
};
const getBotResponse = (userMessage) => {
const lowercaseMessage = userMessage.toLowerCase();
for (const [keyword, response] of Object.entries(legalResponses)) {
if (lowercaseMessage.includes(keyword)) {
return response;
}
}
return legalResponses.default;
};
const handleKeyPress = (e) => {
if (e.key === 'Enter') {
handleSend();
}
};
return (