import React, { useState, useRef, useEffect } from 'react'; import { MessageCircle, X, Send, User, Bot, Minimize2 } from 'lucide-react'; import { Button } from './ui/button'; import exampleImage from 'figma:asset/a28d79dd35b730f689b77dbb30452ca27bd25759.png'; interface Message { id: string; text: string; sender: 'user' | 'bot'; timestamp: Date; } export function Chatbot() { const [isOpen, setIsOpen] = useState(false); const [messages, setMessages] = useState([ { id: '1', text: 'Hello! I\'m here to help you learn more about Kautilya Leadership Centre. How can I assist you today?', sender: 'bot', timestamp: new Date() } ]); const [inputValue, setInputValue] = useState(''); const [isTyping, setIsTyping] = useState(false); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const predefinedResponses: { [key: string]: string } = { 'hello': 'Hello! Welcome to Kautilya Leadership Centre. I\'m here to help you with information about our programs, services, and how we can support your leadership development journey.', 'programs': 'We offer comprehensive leadership development programs including executive coaching, team development, strategic leadership training, and virtual learning experiences. Would you like to know more about any specific program?', 'services': 'Our services include Leadership Development, Executive Coaching, Team Building, Strategic Planning, Organizational Development, and Virtual Learning Platforms. Each is designed to enhance leadership capabilities.', 'contact': 'You can reach us through our contact form on the website, or feel free to schedule a consultation. We\'d be happy to discuss how we can support your leadership development goals.', 'virtual': 'Our virtual learning platform offers flexible, interactive leadership development experiences. You can access courses, participate in live sessions, and connect with other leaders from anywhere.', 'coaching': 'Our executive coaching program provides personalized one-on-one guidance to help leaders develop their skills, overcome challenges, and achieve their professional goals.', 'team': 'Our team development services focus on building high-performing teams through collaborative workshops, communication training, and strategic alignment exercises.', 'webinar': 'Join our upcoming leadership webinars! We regularly host sessions covering various leadership topics. Check our webinars section for schedules and registration.', 'default': 'That\'s a great question! For detailed information about our specific programs and services, I\'d recommend exploring our website or contacting our team directly. Is there anything specific about leadership development I can help you with?' }; const getBotResponse = (userMessage: string): string => { const lowerMessage = userMessage.toLowerCase(); for (const [key, response] of Object.entries(predefinedResponses)) { if (key !== 'default' && lowerMessage.includes(key)) { return response; } } return predefinedResponses.default; }; const handleSendMessage = async () => { if (!inputValue.trim()) return; const userMessage: Message = { id: Date.now().toString(), text: inputValue, sender: 'user', timestamp: new Date() }; setMessages(prev => [...prev, userMessage]); setInputValue(''); setIsTyping(true); // Simulate typing delay setTimeout(() => { const botMessage: Message = { id: (Date.now() + 1).toString(), text: getBotResponse(inputValue), sender: 'bot', timestamp: new Date() }; setMessages(prev => [...prev, botMessage]); setIsTyping(false); }, 1500); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSendMessage(); } }; const formatTime = (date: Date) => { return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: true }); }; return ( <> {/* Chatbot Toggle Button */}
{/* Chatbot Window */} {isOpen && (
{/* Header with gradient background */}

Welcome to KLC

How can I help you today?

{/* Messages Container */}
{messages.map((message) => (
{message.sender === 'user' ? ( ) : ( )}

{message.text}

{formatTime(message.timestamp)}

))} {/* Typing Indicator */} {isTyping && (
)}
{/* Input Area */}
setInputValue(e.target.value)} onKeyPress={handleKeyPress} placeholder="Type your message..." className="flex-1 px-4 py-3 border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent text-sm bg-gray-50" style={{ fontFamily: 'var(--font-family-brand)' }} />
)} ); }