import { useState, useRef, useEffect } from "react"; import { Card } from "./ui/card"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; import { Badge } from "./ui/badge"; import { Send, Bot, User, Sparkles, FileText } from "lucide-react"; interface Message { id: string; role: "user" | "assistant"; content: string; timestamp: Date; } export function AIChat() { const [messages, setMessages] = useState([ { id: "1", role: "assistant", content: "Hello! I'm your Labwise AI assistant. I can help you with:\n\n• Chemical safety information\n• Protocol guidance\n• SDS lookups\n• EHS documentation questions\n• Emergency procedures\n\nWhat would you like to know?", 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, isTyping]); const mockResponses: { [key: string]: string } = { "acetone": "Acetone (CAS 67-64-1) is a flammable liquid. Key safety considerations:\n\n• Store in flammables cabinet away from ignition sources\n• Use in well-ventilated areas or fume hood\n• Wear nitrile gloves and safety goggles\n• Keep away from oxidizing agents\n• Flash point: -20°C\n\nWould you like me to pull up the full SDS?", "disposal": "For chemical waste disposal:\n\n1. Segregate waste by compatibility class\n2. Label all waste containers with contents and hazards\n3. Use proper waste containers (no food/beverage containers)\n4. Contact EHS for pickup when containers are 80% full\n5. Never pour chemicals down the drain unless specifically approved\n\nWhat type of waste are you disposing of?", "ppe": "Personal Protective Equipment (PPE) requirements depend on the chemicals and procedures:\n\n**Minimum PPE:**\n• Safety glasses or goggles\n• Lab coat\n• Closed-toe shoes\n• Long pants\n\n**Additional PPE may include:**\n• Chemical-resistant gloves (nitrile, neoprene, etc.)\n• Face shield for splash hazards\n• Respirator for specific vapors\n\nWhat chemicals are you working with?", "default": "I can help you with that! Based on your question, here are some key points:\n\n• Always refer to the Safety Data Sheet (SDS) for specific chemical hazards\n• Ensure proper PPE is worn at all times\n• Work in well-ventilated areas or fume hoods when handling volatile chemicals\n• Follow your lab's standard operating procedures\n\nWould you like more specific information about a particular chemical or procedure?" }; const handleSend = () => { if (!inputValue.trim()) return; const userMessage: Message = { id: Date.now().toString(), role: "user", content: inputValue, timestamp: new Date() }; setMessages(prev => [...prev, userMessage]); setInputValue(""); setIsTyping(true); setTimeout(() => { const lowercaseInput = inputValue.toLowerCase(); let response = mockResponses.default; if (lowercaseInput.includes("acetone")) { response = mockResponses.acetone; } else if (lowercaseInput.includes("disposal") || lowercaseInput.includes("waste")) { response = mockResponses.disposal; } else if (lowercaseInput.includes("ppe") || lowercaseInput.includes("protective equipment")) { response = mockResponses.ppe; } const assistantMessage: Message = { id: (Date.now() + 1).toString(), role: "assistant", content: response, timestamp: new Date() }; setMessages(prev => [...prev, assistantMessage]); setIsTyping(false); }, 1500); }; const quickQuestions = [ "What PPE do I need for handling acids?", "How do I dispose of organic solvents?", "What are the hazards of acetone?", "Where can I find the SDS for benzene?" ]; return (

AI Safety Assistant

Ask questions about chemical safety, protocols, and lab procedures

{/* Messages */}
{messages.map((message) => (
{message.role === "user" ? ( ) : ( )}

{message.content}

{message.timestamp.toLocaleTimeString()}

))} {isTyping && (
)}
{/* Quick Questions */} {messages.length === 1 && (

Quick questions:

{quickQuestions.map((question, idx) => ( ))}
)} {/* Input */}
setInputValue(e.target.value)} onKeyPress={(e) => e.key === "Enter" && handleSend()} className="flex-1" />
); }