import React, { useState, useEffect, useRef } from 'react'; import { useOrg } from '../../contexts/OrgContext'; import { Employee } from '../../types'; import ChatSidebar from './ChatSidebar'; import MessageThread from './MessageThread'; import FileUploadInput from './FileUploadInput'; interface Message { id: string; text: string; isUser: boolean; timestamp: number; files?: string[]; } interface ChatLayoutProps { children?: React.ReactNode; } const ChatLayout: React.FC = ({ children }) => { const { employees } = useOrg(); const [selectedEmployees, setSelectedEmployees] = useState([]); const [messages, setMessages] = useState([]); const [inputValue, setInputValue] = useState(''); const [isLoading, setIsLoading] = useState(false); const [uploadedFiles, setUploadedFiles] = useState([]); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleNavigation = (page: string) => { // Handle navigation to different pages console.log('Navigate to:', page); }; const handleSendMessage = async () => { if (!inputValue.trim() && uploadedFiles.length === 0) return; const userMessage: Message = { id: Date.now().toString(), text: inputValue, isUser: true, timestamp: Date.now(), files: uploadedFiles.length > 0 ? [...uploadedFiles] : undefined }; setMessages(prev => [...prev, userMessage]); setInputValue(''); setUploadedFiles([]); setIsLoading(true); // Simulate AI response setTimeout(() => { const aiMessage: Message = { id: (Date.now() + 1).toString(), text: "I understand you're asking about the employee data. Based on the information provided, I can help analyze the performance metrics and provide insights.\n\nHere are some key findings from your team's data:\n\n• **Performance Trends**: Overall team productivity has increased by 15% this quarter\n• **Cultural Health**: Employee satisfaction scores are above industry average\n• **Areas for Growth**: Communication and cross-team collaboration could be improved\n\nWould you like me to dive deeper into any of these areas?", isUser: false, timestamp: Date.now() }; setMessages(prev => [...prev, aiMessage]); setIsLoading(false); }, 2000); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSendMessage(); } }; const handleRemoveFile = (index: number) => { setUploadedFiles(prev => prev.filter((_, i) => i !== index)); }; const handleFilesSelected = (files: File[]) => { // For demo purposes, we'll just add the file names // In a real implementation, you'd upload the files and get URLs back const fileNames = files.map(file => file.name); setUploadedFiles(prev => [...prev, ...fileNames]); }; const hasMessages = messages.length > 0; return (
{/* Sidebar */} {/* Main Content Area */}
{/* Header with Employee Selection */}

Chat

{selectedEmployees.length > 0 && (
Analyzing:
{selectedEmployees.slice(0, 3).map((emp, index) => (
{emp.name}
))} {selectedEmployees.length > 3 && (
+{selectedEmployees.length - 3} more
)}
)}
{/* Messages Area */}
{hasMessages ? (
) : ( children )}
{/* Input Area */}
{/* Send Button */}
); }; export default ChatLayout;