Spaces:
Sleeping
Sleeping
File size: 37,558 Bytes
13a0af9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
import { useState, useRef, useEffect, type ReactNode } from 'react';
import { Send, MessageCircle, Settings, Search, BarChart3, User, Bot, Sparkles, HelpCircle, Moon, Sun, Globe, Database, BookOpen, Crown, Zap, Menu, ChevronLeft, ChevronRight, ThumbsUp, ThumbsDown, MessageSquare } from 'lucide-react';
import { Button } from './ui/button';
import { Input } from './ui/input';
import { Message } from './Message';
import { TypingIndicator } from './TypingIndicator';
import { Sheet, SheetContent, SheetTrigger, SheetTitle, SheetDescription } from './ui/sheet';
import { Textarea } from './ui/textarea';
import { motion, AnimatePresence } from 'motion/react';
interface ChatMessage {
id: string;
content: string;
isUser: boolean;
timestamp: Date;
isPlusResponse?: boolean;
sources?: Array<{ name: string; icon: ReactNode; url?: string }>;
}
export function ChatInterface() {
const [messages, setMessages] = useState<ChatMessage[]>([]);
const [inputValue, setInputValue] = useState('');
const [isTyping, setIsTyping] = useState(false);
const [showComingSoon, setShowComingSoon] = useState(false);
const [isDarkMode, setIsDarkMode] = useState(false);
const [isUnivAiPlusMode, setIsUnivAiPlusMode] = useState(false);
const [hasUsedPlusResponse, setHasUsedPlusResponse] = useState(false);
const [currentSources, setCurrentSources] = useState<Array<{ name: string; icon: ReactNode; url?: string }>>([]);
const [showFeedback, setShowFeedback] = useState(false);
const [feedbackType, setFeedbackType] = useState<'positive' | 'negative' | null>(null);
const [feedbackComment, setFeedbackComment] = useState('');
const [lastBotMessageId, setLastBotMessageId] = useState<string | null>(null);
const [leftSheetOpen, setLeftSheetOpen] = useState(false);
const [rightSheetOpen, setRightSheetOpen] = useState(false);
const messagesEndRef = useRef<HTMLDivElement>(null);
// Initialize messages based on current mode
useEffect(() => {
const initialMessage: ChatMessage = {
id: '1',
content: isUnivAiPlusMode
? "Feel free to explore UnivAi+++ for a richer, more responsive conversation experience. Please note: due to limited computational resources, the AI can provide only one response per session. Make it count!"
: "Hello! I'm your AI assistant. How can I help you today? Feel free to ask me anything!",
isUser: false,
timestamp: new Date(),
isPlusResponse: isUnivAiPlusMode
};
setMessages([initialMessage]);
setHasUsedPlusResponse(false);
setCurrentSources([]); // Reset sources when switching modes
setShowFeedback(false);
setFeedbackType(null);
setFeedbackComment('');
}, [isUnivAiPlusMode]);
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};
useEffect(() => {
scrollToBottom();
}, [messages, isTyping]);
useEffect(() => {
// Apply dark mode class to document
if (isDarkMode) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}, [isDarkMode]);
const handleSendMessage = async (e: React.FormEvent) => {
e.preventDefault();
if (!inputValue.trim()) return;
if (isUnivAiPlusMode && hasUsedPlusResponse) return; // Prevent sending if already used Plus response
const userMessage: ChatMessage = {
id: Date.now().toString(),
content: inputValue,
isUser: true,
timestamp: new Date(),
};
setMessages(prev => [...prev, userMessage]);
setInputValue('');
setIsTyping(true);
try {
const res = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: inputValue,
dev_mode: isUnivAiPlusMode,
}),
});
const data = await res.json();
// Optionally, you can extract sources from data if provided
const botResponse: ChatMessage = {
id: (Date.now() + 1).toString(),
content: data.response,
isUser: false,
timestamp: new Date(),
isPlusResponse: isUnivAiPlusMode,
sources: [], // Optionally fill from data.source
};
setMessages(prev => [...prev, botResponse]);
setCurrentSources([]); // Optionally update if sources are available
setIsTyping(false);
setLastBotMessageId(botResponse.id);
// Show feedback form after bot response
setShowFeedback(true);
setFeedbackType(null);
setFeedbackComment('');
// Mark Plus response as used
if (isUnivAiPlusMode) {
setHasUsedPlusResponse(true);
}
} catch (err) {
setIsTyping(false);
}
};
const handleFeedbackSubmit = async () => {
console.log('Feedback submitted:', { messageId: lastBotMessageId, feedbackType, feedbackComment });
if (!lastBotMessageId) return;
const lastBotMsg = messages.find(m => m.id === lastBotMessageId);
if (!lastBotMsg) return;
try {
await fetch('/api/feedback', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: lastBotMsg.content,
response: lastBotMsg.content,
feedback: feedbackType,
}),
});
setFeedbackType(null);
setFeedbackComment('');
} catch (err) {
// Optionally handle error
}
};
const handleComingSoonClick = () => {
setShowComingSoon(true);
setTimeout(() => {
setShowComingSoon(false);
}, 2000);
};
const toggleDarkMode = () => {
setIsDarkMode(!isDarkMode);
};
const toggleUnivAiMode = () => {
setIsUnivAiPlusMode(!isUnivAiPlusMode);
};
const sidebarItems = [
{ icon: <MessageCircle size={20} />, active: true },
{ icon: <BarChart3 size={20} />, active: false },
{ icon: <Search size={20} />, active: false },
{ icon: <User size={20} />, active: false },
{ icon: <Settings size={20} />, active: false },
];
const isInputDisabled = isTyping || (isUnivAiPlusMode && hasUsedPlusResponse);
// Sidebar content components
const LeftSidebarContent = () => (
<>
{/* Logo */}
<div className={`w-9 h-9 rounded-lg flex items-center justify-center mb-6 shadow-lg transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 shadow-red-500/30'
}`}>
{isUnivAiPlusMode ? <Crown className="text-white" size={20} /> : <Bot className="text-white" size={20} />}
</div>
{/* Navigation */}
<div className="flex flex-col gap-3">
{sidebarItems.map((item, index) => (
<motion.button
key={index}
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
onClick={!item.active ? handleComingSoonClick : undefined}
className={`
w-9 h-9 rounded-lg flex items-center justify-center transition-all duration-200
${item.active
? isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 text-white shadow-lg shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 text-white shadow-lg shadow-red-500/30'
: 'bg-white/80 text-red-600 hover:bg-white hover:text-red-700 shadow-sm cursor-pointer dark:bg-gray-800/80 dark:text-red-400 dark:hover:bg-gray-700'
}
`}
>
{item.active ? item.icon : <HelpCircle size={18} />}
</motion.button>
))}
</div>
</>
);
const RightSidebarContent = () => (
<>
{/* AI Status Card - More compact */}
<div className={`rounded-xl p-4 border backdrop-blur-sm shadow-lg transition-all duration-300 min-h-[200px] ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white/90 to-purple-50/90 border-purple-200/50 shadow-purple-100/30 dark:from-gray-800/90 dark:to-purple-900/90 dark:border-purple-600/50 dark:shadow-purple-900/30'
: 'bg-gradient-to-br from-white/90 to-red-50/90 border-red-200/50 shadow-red-100/30 dark:from-gray-800/90 dark:to-gray-700/90 dark:border-gray-600/50 dark:shadow-gray-900/30'
}`}>
<div className="flex items-center justify-center mb-3">
<div className={`w-16 h-16 rounded-full flex items-center justify-center shadow-lg transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-400 to-pink-500 shadow-purple-500/30'
: 'bg-gradient-to-r from-yellow-400 to-orange-500 shadow-yellow-500/30'
}`}>
{isUnivAiPlusMode ? <Crown className="text-white" size={24} /> : <Bot className="text-white" size={24} />}
</div>
</div>
<div className="text-center">
{/* Fixed height container for title */}
<div className="h-6 overflow-hidden flex items-center justify-center mb-1">
<motion.h3
key={isUnivAiPlusMode ? 'plus' : 'regular'}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.2 }}
className={`text-sm transition-all duration-300 whitespace-nowrap flex items-center ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}
>
{isUnivAiPlusMode ? 'UnivAi+++' : 'UnivAi'}
{isUnivAiPlusMode && <Crown className="ml-1" size={12} />}
</motion.h3>
</div>
{/* Fixed height container for description */}
<div className="h-5 overflow-hidden flex items-center justify-center mb-3">
<motion.p
key={isUnivAiPlusMode ? 'plus-desc' : 'regular-desc'}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.2 }}
className={`text-xs text-center transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-700/80 dark:text-purple-300/80'
: 'text-red-700/80 dark:text-red-300/80'
}`}
>
{isUnivAiPlusMode
? 'Smarter with human-like responses'
: 'Any PUP-Related Queries?'
}
</motion.p>
</div>
{/* Fixed button */}
<div className="flex justify-center">
<Button
size="sm"
onClick={toggleUnivAiMode}
className={`text-white border-0 shadow-lg transition-all duration-300 text-xs px-3 py-1 w-40 h-7 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 shadow-purple-500/20'
: 'bg-gradient-to-r from-red-500 to-orange-500 hover:from-red-600 hover:to-orange-600 shadow-red-500/20'
}`}
>
<span className="truncate">
{isUnivAiPlusMode ? 'Switch to UnivAi' : 'Try the New UnivAi+++'}
</span>
</Button>
</div>
</div>
</div>
{/* Chat Stats - Equalized for both modes */}
<div className={`rounded-xl p-3 border backdrop-blur-sm shadow-lg transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white/90 to-pink-50/90 border-pink-200/50 shadow-pink-100/30 dark:from-gray-800/90 dark:to-pink-900/90 dark:border-pink-600/50 dark:shadow-pink-900/30'
: 'bg-gradient-to-br from-white/90 to-orange-50/90 border-orange-200/50 shadow-orange-100/30 dark:from-gray-800/90 dark:to-gray-700/90 dark:border-gray-600/50 dark:shadow-gray-900/30'
}`}>
<h4 className={`mb-2 text-sm transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}>Chat Statistics</h4>
<div className="space-y-2">
<div className="flex justify-between">
<span className={`text-xs transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-700/80 dark:text-purple-300/80'
: 'text-red-700/80 dark:text-red-300/80'
}`}>Response Time</span>
<span className={`text-xs transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}>{isUnivAiPlusMode ? '2.5s' : '1.2s'}</span>
</div>
<div className="flex justify-between">
<span className={`text-xs transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-700/80 dark:text-purple-300/80'
: 'text-red-700/80 dark:text-red-300/80'
}`}>Status</span>
<span className="text-green-600 text-xs">{isUnivAiPlusMode ? 'Premium' : 'Online'}</span>
</div>
<div className="flex justify-between">
<span className={`text-xs transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-700/80 dark:text-purple-300/80'
: 'text-red-700/80 dark:text-red-300/80'
}`}>{isUnivAiPlusMode ? 'Responses Left' : 'Queries Processed'}</span>
<span className={`text-xs transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}>{isUnivAiPlusMode ? (hasUsedPlusResponse ? '0' : '1') : '∞'}</span>
</div>
</div>
</div>
{/* Sources - More compact */}
<div className={`rounded-xl p-3 border backdrop-blur-sm shadow-lg transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white/90 to-amber-50/90 border-amber-200/50 shadow-amber-100/30 dark:from-gray-800/90 dark:to-amber-900/90 dark:border-amber-600/50 dark:shadow-amber-900/30'
: 'bg-gradient-to-br from-white/90 to-yellow-50/90 border-yellow-200/50 shadow-yellow-100/30 dark:from-gray-800/90 dark:to-gray-700/90 dark:border-gray-600/50 dark:shadow-gray-900/30'
}`}>
<h4 className={`mb-2 text-sm transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}>Sources</h4>
<div className="space-y-2 min-h-[40px]">
{currentSources.length === 0 ? (
<div className="flex items-center justify-center py-2">
<p className={`text-xs text-center transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-600/60 dark:text-purple-400/60'
: 'text-red-600/60 dark:text-red-400/60'
}`}>
Sources will appear here after AI responses
</p>
</div>
) : (
currentSources.map((source, index) => (
<motion.div
key={index}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: index * 0.1 }}
className="flex items-center justify-between"
>
<div className="flex items-center gap-2 min-w-0 flex-1">
<div className={`transition-all duration-300 flex-shrink-0 ${
isUnivAiPlusMode
? 'text-purple-600 dark:text-purple-400'
: 'text-red-600 dark:text-red-400'
}`}>
{source.icon}
</div>
<span className={`text-xs transition-all duration-300 truncate ${
isUnivAiPlusMode
? 'text-purple-700/80 dark:text-purple-300/80'
: 'text-red-700/80 dark:text-red-300/80'
}`}>{source.name}</span>
</div>
{source.url && (
<button
onClick={() => window.open(source.url, '_blank')}
className={`text-xs px-2 py-1 rounded-full transition-all duration-300 flex-shrink-0 hover:opacity-80 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-100 to-pink-100 text-purple-700 dark:from-purple-900/30 dark:to-pink-900/30 dark:text-purple-400'
: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400'
}`}
>
View
</button>
)}
</motion.div>
))
)}
</div>
</div>
</>
);
return (
<div className={`h-screen flex p-1 md:p-2 transition-all duration-500 ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-purple-100 via-pink-50 to-amber-50 dark:from-purple-900 dark:via-indigo-900 dark:to-amber-900'
: 'bg-gradient-to-br from-orange-100 via-red-50 to-yellow-50 dark:from-gray-900 dark:via-gray-800 dark:to-gray-900'
}`}>
{/* Coming Soon Toast */}
<AnimatePresence>
{showComingSoon && (
<motion.div
initial={{ opacity: 0, y: -50, x: '-50%' }}
animate={{ opacity: 1, y: 0, x: '-50%' }}
exit={{ opacity: 0, y: -50, x: '-50%' }}
className="fixed top-4 left-1/2 z-50 bg-gradient-to-r from-red-500 to-orange-500 text-white px-6 py-3 rounded-lg shadow-lg shadow-red-500/30"
>
<p className="text-sm">Coming soon!</p>
</motion.div>
)}
</AnimatePresence>
{/* Usage Limit Warning */}
<AnimatePresence>
{isUnivAiPlusMode && hasUsedPlusResponse && (
<motion.div
initial={{ opacity: 0, y: -50, x: '-50%' }}
animate={{ opacity: 1, y: 0, x: '-50%' }}
exit={{ opacity: 0, y: -50, x: '-50%' }}
className="fixed top-16 left-1/2 z-50 bg-gradient-to-r from-purple-500 to-pink-500 text-white px-6 py-3 rounded-lg shadow-lg shadow-purple-500/30"
>
<p className="text-sm">UnivAi+++ limit reached. Switch to UnivAi to continue.</p>
</motion.div>
)}
</AnimatePresence>
{/* Dark Mode Toggle - Top Right */}
<motion.button
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
onClick={toggleDarkMode}
className={`fixed top-2 right-2 md:top-3 md:right-3 z-40 w-8 h-8 md:w-10 md:h-10 rounded-full text-white flex items-center justify-center shadow-lg transition-all duration-200 hover:scale-110 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 shadow-purple-500/30 hover:shadow-purple-500/50'
: 'bg-gradient-to-r from-red-500 to-orange-500 shadow-red-500/30 hover:shadow-red-500/50'
}`}
>
<motion.div
key={isDarkMode ? 'dark' : 'light'}
initial={{ rotate: -180, opacity: 0 }}
animate={{ rotate: 0, opacity: 1 }}
transition={{ duration: 0.3 }}
>
{isDarkMode ? <Sun size={16} className="md:w-[18px] md:h-[18px]" /> : <Moon size={16} className="md:w-[18px] md:h-[18px]" />}
</motion.div>
</motion.button>
{/* Mobile Left Sheet Trigger */}
<Sheet open={leftSheetOpen} onOpenChange={setLeftSheetOpen}>
<SheetTrigger asChild>
<motion.button
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
className={`md:hidden fixed left-0 top-1/2 -translate-y-1/2 z-30 w-8 h-16 rounded-r-lg flex items-center justify-center shadow-lg transition-all duration-200 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 shadow-red-500/30'
}`}
>
<ChevronRight className="text-white" size={20} />
</motion.button>
</SheetTrigger>
<SheetContent side="left" className={`w-20 p-3 transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white/95 to-purple-50/95 border-purple-200/50'
: 'bg-gradient-to-br from-white/95 to-red-50/95 border-red-200/50'
}`}>
<SheetTitle className="sr-only">Navigation Menu</SheetTitle>
<SheetDescription className="sr-only">
Access chat navigation, statistics, search, profile, and settings
</SheetDescription>
<div className="flex flex-col items-center py-3">
<LeftSidebarContent />
</div>
</SheetContent>
</Sheet>
{/* Sidebar - Desktop only */}
<motion.div
initial={{ x: -20, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
className="hidden md:flex w-14 flex-col items-center py-3 px-1 mr-2"
>
<LeftSidebarContent />
</motion.div>
{/* Main Container */}
<div className={`flex-1 flex flex-col rounded-2xl backdrop-blur-sm border overflow-hidden shadow-xl transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-white/95 border-purple-200/50 shadow-purple-100/50 dark:bg-gray-900/95 dark:border-purple-700/50 dark:shadow-purple-900/50'
: 'bg-white/90 border-red-200/50 shadow-red-100/50 dark:bg-gray-900/90 dark:border-gray-700/50 dark:shadow-gray-900/50'
}`}>
{/* Header */}
<motion.div
initial={{ y: -20, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
className={`p-3 md:p-4 border-b backdrop-blur-sm transition-all duration-300 flex-shrink-0 ${
isUnivAiPlusMode
? 'border-purple-200/50 bg-gradient-to-r from-white/95 to-purple-50/95 dark:from-gray-900/95 dark:to-purple-900/95 dark:border-purple-700/50'
: 'border-red-200/50 bg-gradient-to-r from-white/95 to-red-50/95 dark:from-gray-900/95 dark:to-gray-800/95 dark:border-gray-700/50'
}`}
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 md:gap-3 min-w-0 flex-1">
<div className="flex items-center gap-2 md:gap-3 min-w-0 flex-1">
<div className={`w-8 h-8 md:w-10 md:h-10 rounded-full flex items-center justify-center shadow-lg transition-all duration-300 flex-shrink-0 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-400 to-pink-500 shadow-purple-500/30'
: 'bg-gradient-to-r from-yellow-400 to-orange-500 shadow-yellow-500/30'
}`}>
{isUnivAiPlusMode ? <Crown className="text-white" size={16} /> : <Bot className="text-white" size={16} />}
</div>
<div className="min-w-0 flex-1">
<div className="overflow-hidden">
<motion.h1
key={isUnivAiPlusMode ? 'plus-header' : 'regular-header'}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.2 }}
className={`transition-all duration-300 truncate whitespace-nowrap ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}
>
{isUnivAiPlusMode ? 'UnivAi+++' : 'UnivAi'}
{isUnivAiPlusMode && <Crown className="inline ml-1 md:ml-2" size={12} />}
</motion.h1>
</div>
<p className={`text-xs md:text-sm transition-all duration-300 truncate ${
isUnivAiPlusMode
? 'text-purple-700/80 dark:text-purple-300/80'
: 'text-red-700/80 dark:text-red-300/80'
}`}>
{isUnivAiPlusMode ? 'Premium AI Experience' : 'Always ready to help'}
</p>
</div>
</div>
</div>
<div className="flex items-center gap-2 flex-shrink-0">
<div className={`w-5 h-5 md:w-6 md:h-6 rounded-full shadow-lg transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-400 to-pink-500 shadow-purple-500/20'
: 'bg-gradient-to-r from-yellow-400 to-orange-500 shadow-yellow-500/20'
}`}></div>
</div>
</div>
</motion.div>
{/* Chat Container */}
<div className="flex-1 flex min-h-0">
{/* Messages Area */}
<div className="flex-1 flex flex-col min-h-0">
{/* Messages */}
<div className={`flex-1 overflow-y-auto p-2 md:p-4 transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white to-purple-50/30 dark:from-gray-900 dark:to-purple-900/30'
: 'bg-gradient-to-br from-white to-red-50/30 dark:from-gray-900 dark:to-gray-800/30'
}`}>
<div className="max-w-4xl mx-auto space-y-3 md:space-y-4">
{messages.map((message) => (
<Message
key={message.id}
content={message.content}
isUser={message.isUser}
timestamp={message.timestamp}
isPlusResponse={message.isPlusResponse}
isUnivAiPlusMode={isUnivAiPlusMode}
/>
))}
{isTyping && <TypingIndicator isUnivAiPlusMode={isUnivAiPlusMode} />}
<div ref={messagesEndRef} />
</div>
</div>
{/* Feedback Section - Appears after AI responses */}
<AnimatePresence>
{showFeedback && messages.length > 1 && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 20 }}
className={`px-2 md:px-4 pb-2 md:pb-3 transition-all duration-300 flex-shrink-0 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-white to-purple-50/30 dark:from-gray-900 dark:to-purple-900/30'
: 'bg-gradient-to-r from-white to-red-50/30 dark:from-gray-900 dark:to-gray-800/30'
}`}
>
<div className={`max-w-4xl mx-auto rounded-xl p-3 md:p-4 border backdrop-blur-sm shadow-lg transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white/95 to-purple-50/95 border-purple-200/50 shadow-purple-100/30 dark:from-gray-800/95 dark:to-purple-900/95 dark:border-purple-600/50'
: 'bg-gradient-to-br from-white/95 to-red-50/95 border-red-200/50 shadow-red-100/30 dark:from-gray-800/95 dark:to-gray-700/95 dark:border-gray-600/50'
}`}>
<div className="flex items-center gap-2 mb-3">
<MessageSquare className={`${
isUnivAiPlusMode
? 'text-purple-600 dark:text-purple-400'
: 'text-red-600 dark:text-red-400'
}`} size={18} />
<h4 className={`text-sm transition-all duration-300 ${
isUnivAiPlusMode
? 'text-purple-900 dark:text-purple-100'
: 'text-red-900 dark:text-red-100'
}`}>How was this response?</h4>
</div>
<div className="flex gap-2 mb-3">
<Button
variant={feedbackType === 'positive' ? 'default' : 'outline'}
size="sm"
onClick={() => setFeedbackType('positive')}
className={`flex items-center gap-1.5 transition-all duration-300 text-xs ${
feedbackType === 'positive'
? isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 text-white shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 text-white shadow-red-500/30'
: isUnivAiPlusMode
? 'border-purple-200 text-purple-700 hover:bg-purple-50 dark:border-purple-600 dark:text-purple-300'
: 'border-red-200 text-red-700 hover:bg-red-50 dark:border-red-600 dark:text-red-300'
}`}
>
<ThumbsUp size={14} />
Helpful
</Button>
<Button
variant={feedbackType === 'negative' ? 'default' : 'outline'}
size="sm"
onClick={() => setFeedbackType('negative')}
className={`flex items-center gap-1.5 transition-all duration-300 text-xs ${
feedbackType === 'negative'
? isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 text-white shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 text-white shadow-red-500/30'
: isUnivAiPlusMode
? 'border-purple-200 text-purple-700 hover:bg-purple-50 dark:border-purple-600 dark:text-purple-300'
: 'border-red-200 text-red-700 hover:bg-red-50 dark:border-red-600 dark:text-red-300'
}`}
>
<ThumbsDown size={14} />
Not helpful
</Button>
</div>
<Textarea
value={feedbackComment}
onChange={(e) => setFeedbackComment(e.target.value)}
placeholder="Additional comments (optional)..."
className={`mb-2 text-sm transition-all duration-300 ${
isUnivAiPlusMode
? 'border-purple-200 focus:border-purple-400 dark:border-purple-600'
: 'border-red-200 focus:border-red-400 dark:border-red-600'
}`}
rows={2}
/>
<div className="flex justify-end">
<Button
size="sm"
onClick={handleFeedbackSubmit}
disabled={!feedbackType}
className={`text-xs transition-all duration-300 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 text-white shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 hover:from-red-600 hover:to-orange-600 text-white shadow-red-500/30'
}`}
>
Submit Feedback
</Button>
</div>
</div>
</motion.div>
)}
</AnimatePresence>
{/* Input */}
<motion.div
initial={{ y: 20, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
className={`p-2 md:p-4 border-t backdrop-blur-sm transition-all duration-300 flex-shrink-0 ${
isUnivAiPlusMode
? 'border-purple-200/50 bg-gradient-to-r from-white/95 to-purple-50/95 dark:from-gray-900/95 dark:to-purple-900/95 dark:border-purple-700/50'
: 'border-red-200/50 bg-gradient-to-r from-white/95 to-red-50/95 dark:from-gray-900/95 dark:to-gray-800/95 dark:border-gray-700/50'
}`}
>
<div className="max-w-4xl mx-auto">
<form onSubmit={handleSendMessage} className="flex gap-2 md:gap-3">
<div className="flex-1 relative">
<Input
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder={
isUnivAiPlusMode && hasUsedPlusResponse
? "Switch to UnivAi to continue..."
: "Type your message..."
}
className={`backdrop-blur-sm transition-all duration-200 shadow-sm text-sm ${
isUnivAiPlusMode
? 'bg-white/90 border-purple-200 text-purple-900 placeholder:text-purple-500/60 focus:bg-white focus:border-purple-400 dark:bg-gray-800/90 dark:border-purple-600 dark:text-purple-100 dark:placeholder:text-purple-400/60 dark:focus:bg-gray-800'
: 'bg-white/90 border-red-200 text-red-900 placeholder:text-red-500/60 focus:bg-white focus:border-red-400 dark:bg-gray-800/90 dark:border-gray-600 dark:text-red-100 dark:placeholder:text-red-400/60 dark:focus:bg-gray-800'
}`}
disabled={isInputDisabled}
/>
</div>
<Button
type="submit"
disabled={!inputValue.trim() || isInputDisabled}
className={`text-white border-0 shadow-lg transition-all duration-300 px-3 md:px-4 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 hover:from-red-600 hover:to-orange-600 shadow-red-500/30'
}`}
>
<Send size={16} className="md:w-[18px] md:h-[18px]" />
</Button>
</form>
</div>
</motion.div>
</div>
{/* Stats Sidebar - Desktop & Tablet */}
<motion.div
initial={{ x: 20, opacity: 0 }}
animate={{ x: 0, opacity: 1 }}
className={`hidden md:flex w-72 flex-shrink-0 border-l p-4 space-y-4 transition-all duration-300 overflow-y-auto flex-col ${
isUnivAiPlusMode
? 'border-purple-200/50 bg-gradient-to-br from-white/50 to-purple-50/50 dark:from-gray-900/50 dark:to-purple-900/50 dark:border-purple-700/50'
: 'border-red-200/50 bg-gradient-to-br from-white/50 to-yellow-50/50 dark:from-gray-900/50 dark:to-gray-800/50 dark:border-gray-700/50'
}`}
>
<RightSidebarContent />
</motion.div>
</div>
</div>
{/* Mobile Right Sheet Trigger */}
<Sheet open={rightSheetOpen} onOpenChange={setRightSheetOpen}>
<SheetTrigger asChild>
<motion.button
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
className={`md:hidden fixed right-0 top-1/2 -translate-y-1/2 z-30 w-8 h-16 rounded-l-lg flex items-center justify-center shadow-lg transition-all duration-200 ${
isUnivAiPlusMode
? 'bg-gradient-to-r from-purple-500 to-pink-500 shadow-purple-500/30'
: 'bg-gradient-to-r from-red-500 to-orange-500 shadow-red-500/30'
}`}
>
<ChevronLeft className="text-white" size={20} />
</motion.button>
</SheetTrigger>
<SheetContent side="right" className={`w-80 p-4 transition-all duration-300 overflow-y-auto ${
isUnivAiPlusMode
? 'bg-gradient-to-br from-white/95 to-purple-50/95 border-purple-200/50'
: 'bg-gradient-to-br from-white/95 to-red-50/95 border-red-200/50'
}`}>
<SheetTitle className="sr-only">Chat Information Panel</SheetTitle>
<SheetDescription className="sr-only">
View AI status, chat statistics, and source references
</SheetDescription>
<div className="space-y-4">
<RightSidebarContent />
</div>
</SheetContent>
</Sheet>
</div>
);
}
|