"use client" import { useState } from "react" import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/components/ui/card" import { MessageSquare, ThumbsUp, ChevronUp, Search, Image as ImageIcon, CheckCircle, Lock, X, Send } from "lucide-react" import { useActiveUser, isDemoUser } from "@/hooks/useActiveUser" import { PremiumGate } from "@/components/PremiumGate" interface Doubt { id: string author: string avatar: string timeAgo: string subject: string topic: string title: string content: string upvotes: number replies: number isSolved: boolean hasModeratorReply: boolean } export default function CommunityPage() { const { user, hasAccessTo, loading } = useActiveUser() const isDemo = isDemoUser(user?.id) const currentUserName = user?.name || (isDemo ? "Neha Verma" : "Student") const currentUserInitials = currentUserName.substring(0, 2).toUpperCase() const [activeFilter, setActiveFilter] = useState<'all' | 'my-doubts' | 'solved' | 'unsolved'>('all') const [searchQuery, setSearchQuery] = useState('') const [isAskModalOpen, setIsAskModalOpen] = useState(false) const [expandedDoubtId, setExpandedDoubtId] = useState(null) const mockDoubts: Doubt[] = [ { id: "1", author: "Rahul Verma", avatar: "RV", timeAgo: "2 hours ago", subject: "Physics", topic: "Rotational Mechanics", title: "Why does friction act forwards in a rolling wheel?", content: "I'm confused about the direction of friction when a car accelerates forward. My book says friction pushes the wheel forward, but shouldn't it oppose motion?", upvotes: 42, replies: 5, isSolved: true, hasModeratorReply: true }, { id: "2", author: "Priya Sharma", avatar: "PS", timeAgo: "5 hours ago", subject: "Chemistry", topic: "Chemical Kinetics", title: "How to quickly identify a pseudo first-order reaction?", content: "Are there any tricks to spot these in MCQs? I always end up wasting 2 minutes trying to derive the rate law.", upvotes: 18, replies: 2, isSolved: false, hasModeratorReply: false }, ...(isDemo ? [{ id: "3", author: currentUserName, avatar: currentUserInitials, timeAgo: "1 day ago", subject: "Mathematics", topic: "Definite Integration", title: "Applying King's Rule when limits are -a to a", content: "I keep messing up the signs when applying the property f(x) + f(-x). Can someone show a step-by-step for the modulus function?", upvotes: 12, replies: 8, isSolved: true, hasModeratorReply: true }] : []) ] const filteredDoubts = mockDoubts.filter(d => { if (activeFilter === 'my-doubts' && d.author !== currentUserName) return false if (activeFilter === 'solved' && !d.isSolved) return false if (activeFilter === 'unsolved' && d.isSolved) return false if (searchQuery && !d.title.toLowerCase().includes(searchQuery.toLowerCase())) return false return true }) if (!hasAccessTo("doubt-resolution-community") && !isDemo) { return (

Doubt Forum

Ask questions, share knowledge, and learn together with the community.

Premium Feature

The Doubt Forum is a premium feature. Upgrade your plan to ask doubts and interact with tutors and the community.

) } return (

Doubt Forum

Ask questions, share knowledge, and learn together with the community.

setSearchQuery(e.target.value)} />
setActiveFilter('all')}>All Doubts setActiveFilter('my-doubts')}>My Doubts setActiveFilter('solved')}>Solved setActiveFilter('unsolved')}>Unsolved
{loading ? (
Loading doubts...
) : (<>{filteredDoubts.map((doubt) => ( {/* Upvote Sidebar */}
{doubt.upvotes}
{/* Main Content */}
{doubt.subject} • {doubt.topic}
{doubt.timeAgo}

{doubt.title}

{doubt.content}

{doubt.avatar}
{doubt.author} {doubt.hasModeratorReply && ( Expert Replied )}
{doubt.isSolved && ( Solved )}
{/* Expanded Replies Section */} {expandedDoubtId === doubt.id && (
AI
PragatiVeer AI Expert

This is a great question! When the car accelerates, the engine applies a torque to the wheel, making it want to spin faster. If there were no friction, the bottom of the tire would slip backward relative to the road. Therefore, static friction acts in the forward direction on the tire to oppose this backward slipping motion.

)}
))} {filteredDoubts.length === 0 && (

{activeFilter === 'my-doubts' ? "No Doubts Asked Yet" : "No doubts found matching your criteria."}

{activeFilter === 'my-doubts' ? "You haven't asked any doubts yet. Click 'Ask a Doubt' above to get answers from mentors and peers." : "Try selecting another filter or clearing your search query."}

)} )}
{/* Ask Doubt Modal */} {isAskModalOpen && (

Ask a Doubt