"use client";
import React, { useState, useRef, useEffect } from 'react';
import {
Send, Plus, Menu, Search, Archive, Trash2, Edit3,
MessageSquare, User, Bot, Copy, ThumbsUp, ThumbsDown,
RotateCcw, Share, MoreHorizontal, Image, Video, FileText,
Code, Table, Music, Mic, Settings, Zap, Brain, Sparkles,
BarChart2, Clock, Globe, Lock, Unlock, Book, Feather,
Camera, Film, Headphones, Download, Upload, Link, Mail,
AlertCircle, CheckCircle, HelpCircle, Info, Star, Heart,
Award, Gift, Coffee, ShoppingCart, CreditCard, Key,
Map, Navigation, Phone, Tag, Watch, Wifi,
Cloud, Sun, Moon, Umbrella, Droplet, Wind
} from 'lucide-react';
const ChatPage = () => {
const [messages, setMessages] = useState([
{
id: 1,
type: 'assistant',
content: "Hello! I'm General Bots, a large language model by Pragmatismo. How can I help you today?",
timestamp: new Date().toISOString()
}
]);
const [input, setInput] = useState('');
const [isTyping, setIsTyping] = useState(false);
const [sidebarOpen, setSidebarOpen] = useState(true);
const [conversations, setConversations] = useState([
{ id: 1, title: 'Current Chat', timestamp: new Date(), active: true },
{ id: 2, title: 'Previous Conversation', timestamp: new Date(Date.now() - 86400000), active: false },
{ id: 3, title: 'Code Review Discussion', timestamp: new Date(Date.now() - 172800000), active: false },
{ id: 4, title: 'Project Planning', timestamp: new Date(Date.now() - 259200000), active: false },
]);
const [activeMode, setActiveMode] = useState('assistant');
const messagesEndRef = useRef(null);
const textareaRef = useRef(null);
// Mode buttons
const modeButtons = [
{ id: 'deep-think', icon: , label: 'Deep Think' },
{ id: 'web', icon: , label: 'Web' },
{ id: 'creative', icon: , label: 'Creative' },
{ id: 'image', icon: , label: 'Image' },
{ id: 'video', icon: , label: 'Video' },
{ id: 'document', icon: , label: 'Document' },
{ id: 'code', icon:
, label: 'Code' },
{ id: 'data', icon:
, label: 'Data' },
{ id: 'audio', icon: , label: 'Audio' },
{ id: 'analysis', icon: , label: 'Analysis' },
{ id: 'research', icon: , label: 'Research' },
{ id: 'writing', icon: , label: 'Writing' },
];
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};
useEffect(() => {
scrollToBottom();
}, [messages]);
const handleSubmit = async () => {
if (!input.trim()) return;
const userMessage = {
id: Date.now(),
type: 'user',
content: input.trim(),
timestamp: new Date().toISOString()
};
setMessages(prev => [...prev, userMessage]);
setInput('');
setIsTyping(true);
// Simulate assistant response
setTimeout(() => {
const assistantMessage = {
id: Date.now() + 1,
type: 'assistant',
content: `I understand you're asking about "${input.trim()}". This is a simulated response to demonstrate the chat interface. The actual implementation would connect to your chat provider and send real responses.`,
timestamp: new Date().toISOString()
};
setMessages(prev => [...prev, assistantMessage]);
setIsTyping(false);
}, 1500);
};
const handleKeyDown = (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSubmit();
}
};
const formatTimestamp = (timestamp) => {
const date = new Date(timestamp);
const now = new Date();
const diffInHours = (now - date) / (1000 * 60 * 60);
if (diffInHours < 24) {
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
} else if (diffInHours < 48) {
return 'Yesterday';
} else {
return date.toLocaleDateString();
}
};
const newChat = () => {
const newConv = {
id: Date.now(),
title: 'New Chat',
timestamp: new Date(),
active: true
};
setConversations(prev => [newConv, ...prev.map(c => ({ ...c, active: false }))]);
setMessages([{
id: Date.now(),
type: 'assistant',
content: "Hello! I'm General Bots, a large language model by Pragmatismo. How can I help you today?",
timestamp: new Date().toISOString()
}]);
};
const MessageActions = ({ message }) => (
);
// Auto-resize textarea
useEffect(() => {
const textarea = textareaRef.current;
if (textarea) {
textarea.style.height = 'auto';
textarea.style.height = `${Math.min(textarea.scrollHeight, 120)}px`;
}
}, [input]);
return (
{/* Sidebar */}
{sidebarOpen && (
<>
{/* Sidebar Header */}
{/* Conversations List */}
{conversations.map(conv => (
{
setConversations(prev => prev.map(c => ({ ...c, active: c.id === conv.id })));
}}
>
{conv.title}
{formatTimestamp(conv.timestamp)}
{conv.active && (
)}
))}
{/* Sidebar Footer */}
>
)}
{/* Main Chat Area */}
{/* Header */}
{conversations.find(c => c.active)?.title || 'New Chat'}
{/* Messages Container - This is the key fix */}
{messages.map(message => (
{message.type === 'user' ? (
) : (
)}
{message.content}
{formatTimestamp(message.timestamp)}
{message.type === 'assistant' && }
))}
{isTyping && (
)}
{/* Mode Carousel */}
{modeButtons.map(button => (
))}
{/* Input Area */}
);
};
export default ChatPage;