import { useState } from 'react'; import { useTelegram } from '../../hooks/useTelegram'; import { usePezkuwi } from '@/contexts/PezkuwiContext'; import { useWallet } from '@/contexts/WalletContext'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Input } from '@/components/ui/input'; import { Skeleton } from '@/components/ui/skeleton'; import { MessageCircle, Plus, RefreshCw, Search, Pin, Clock, User, Eye, ChevronRight, ArrowLeft, Send, ThumbsUp, MessageSquare, Hash } from 'lucide-react'; import { cn } from '@/lib/utils'; export interface ForumThread { id: string; title: string; content: string; author: string; authorAddress?: string; createdAt: Date; replyCount: number; viewCount: number; lastReplyAt?: Date; lastReplyAuthor?: string; isPinned?: boolean; tags?: string[]; } export interface ForumReply { id: string; content: string; author: string; authorAddress?: string; createdAt: Date; likes: number; userLiked?: boolean; } // Mock data const mockThreads: ForumThread[] = [ { id: '1', title: 'Pezkuwi Forum\'a Hoş Geldiniz!', content: 'Bu, Pezkuwi vatandaşları için resmi topluluk forumudur. Dijital devletimiz, yönetişim, geliştirme ve daha fazlası hakkında serbestçe tartışabilirsiniz.\n\nLütfen saygılı olun ve topluluk kurallarımıza uyun.', author: 'Admin', createdAt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 7), replyCount: 45, viewCount: 1234, isPinned: true, tags: ['duyuru', 'kurallar'], lastReplyAt: new Date(Date.now() - 1000 * 60 * 30), lastReplyAuthor: 'YeniVatandaş', }, { id: '2', title: 'HEZ nasıl stake edilir ve ödül kazanılır?', content: 'Herkese merhaba! İlk HEZ tokenlarımı aldım ve stake etmeye başlamak istiyorum. Biri adım adım süreci açıklayabilir mi? Minimum miktar ne kadar?', author: 'KriptoYeni', createdAt: new Date(Date.now() - 1000 * 60 * 60 * 5), replyCount: 12, viewCount: 256, tags: ['staking', 'yardım'], lastReplyAt: new Date(Date.now() - 1000 * 60 * 60 * 2), lastReplyAuthor: 'StakingPro', }, { id: '3', title: 'Öneri: Uygulamaya Kürtçe dil desteği eklenmeli', content: 'Kürt dijital devleti olarak, tüm uygulamalarımızda tam Kürtçe dil desteği (Kurmancî ve Soranî) olması gerektiğini düşünüyorum.\n\nNe düşünüyorsunuz?', author: 'KürtGeliştirici', createdAt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2), replyCount: 28, viewCount: 567, tags: ['öneri', 'yerelleştirme'], lastReplyAt: new Date(Date.now() - 1000 * 60 * 60 * 4), lastReplyAuthor: 'DilUzmanı', }, { id: '4', title: 'Hata: Cüzdan bakiyesi güncellenmiyor', content: 'Transfer yaptıktan sonra cüzdan bakiyem hemen güncellenmiyor. Sayfayı birkaç kez yenilemem gerekiyor. Bu sorunu yaşayan başka var mı?', author: 'TeknikKullanıcı', createdAt: new Date(Date.now() - 1000 * 60 * 60 * 12), replyCount: 8, viewCount: 89, tags: ['hata', 'cüzdan'], lastReplyAt: new Date(Date.now() - 1000 * 60 * 60 * 6), lastReplyAuthor: 'GeliştiriciEkibi', }, ]; const mockReplies: ForumReply[] = [ { id: '1', content: 'Burada olmak harika! Topluluğa katılmak için sabırsızlanıyorum.', author: 'YeniVatandaş', createdAt: new Date(Date.now() - 1000 * 60 * 30), likes: 5, }, { id: '2', content: 'Hoş geldiniz! Dokümantasyon bölümündeki staking rehberini kontrol etmeyi unutmayın.', author: 'Yardımcı', createdAt: new Date(Date.now() - 1000 * 60 * 60), likes: 12, }, ]; function ThreadCard({ thread, onClick }: { thread: ForumThread; onClick: () => void }) { const { hapticSelection } = useTelegram(); const handleClick = () => { hapticSelection(); onClick(); }; const formatDate = (date: Date) => { const now = new Date(); const diff = now.getTime() - date.getTime(); const hours = Math.floor(diff / (1000 * 60 * 60)); const days = Math.floor(hours / 24); if (hours < 1) return 'Az önce'; if (hours < 24) return `${hours}s önce`; if (days < 7) return `${days}g önce`; return date.toLocaleDateString('tr-TR', { day: 'numeric', month: 'short' }); }; return (
{/* Title with pin badge */}
{thread.isPinned && ( Sabit )}

{thread.title}

{/* Preview */}

{thread.content.length > 100 ? thread.content.slice(0, 100) + '...' : thread.content}

{/* Tags */} {thread.tags && thread.tags.length > 0 && (
{thread.tags.slice(0, 3).map(tag => (
{tag}
))}
)} {/* Meta info */}
{thread.author}
{formatDate(thread.createdAt)}
{thread.replyCount}
{thread.viewCount}
{/* Last reply info */} {thread.lastReplyAt && thread.lastReplyAuthor && (
Son yanıt: {thread.lastReplyAuthor}{' '} · {formatDate(thread.lastReplyAt)}
)}
); } function ThreadView({ thread, replies, onBack, onReply, onLikeReply, isConnected }: { thread: ForumThread; replies: ForumReply[]; onBack: () => void; onReply: (content: string) => void; onLikeReply: (replyId: string) => void; isConnected: boolean; }) { const { hapticImpact } = useTelegram(); const [replyContent, setReplyContent] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const formatDate = (date: Date) => { return date.toLocaleDateString('tr-TR', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }); }; const handleSubmitReply = async () => { if (!replyContent.trim() || isSubmitting) return; setIsSubmitting(true); hapticImpact('medium'); try { await onReply(replyContent); setReplyContent(''); } finally { setIsSubmitting(false); } }; return (
{/* Header */}

{thread.title}

{/* Content */}
{/* Original post */}

{thread.author}

{formatDate(thread.createdAt)}
{/* Tags */} {thread.tags && thread.tags.length > 0 && (
{thread.tags.map(tag => ( {tag} ))}
)}

{thread.content}

{/* Replies */}
{replies.length} Yanıt
{replies.map(reply => (
{reply.author} {formatDate(reply.createdAt)}

{reply.content}

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

Henüz yanıt yok. İlk yanıtı siz yazın!

)}
{/* Reply input */} {isConnected ? (
setReplyContent(e.target.value)} placeholder="Yanıtınızı yazın..." className="flex-1 bg-gray-800 border-gray-700 text-white placeholder:text-gray-500" onKeyDown={(e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmitReply(); } }} />
) : (
Yanıt yazmak için cüzdanınızı bağlayın
)}
); } export function ForumSection() { const { hapticNotification, showAlert } = useTelegram(); const { selectedAccount } = usePezkuwi(); const { isConnected } = useWallet(); const [threads, setThreads] = useState(mockThreads); const [selectedThread, setSelectedThread] = useState(null); const [replies, setReplies] = useState(mockReplies); const [isLoading, setIsLoading] = useState(false); const [searchQuery, setSearchQuery] = useState(''); const handleRefresh = async () => { setIsLoading(true); hapticNotification('success'); await new Promise(resolve => setTimeout(resolve, 1000)); setThreads(mockThreads); setIsLoading(false); }; const handleCreateThread = () => { if (!isConnected) { showAlert('Konu oluşturmak için cüzdanınızı bağlayın'); return; } showAlert('Konu oluşturma özelliği yakında!'); }; const handleReply = async (content: string) => { if (!isConnected || !selectedThread) return; const newReply: ForumReply = { id: String(Date.now()), content, author: selectedAccount?.meta?.name || 'Anonim', createdAt: new Date(), likes: 0, }; setReplies(prev => [...prev, newReply]); hapticNotification('success'); }; const handleLikeReply = (replyId: string) => { setReplies(prev => prev.map(reply => { if (reply.id !== replyId) return reply; return { ...reply, likes: reply.userLiked ? reply.likes - 1 : reply.likes + 1, userLiked: !reply.userLiked, }; })); }; const filteredThreads = threads.filter(thread => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || thread.content.toLowerCase().includes(searchQuery.toLowerCase()) ); // Sort: pinned first, then by date const sortedThreads = [...filteredThreads].sort((a, b) => { if (a.isPinned && !b.isPinned) return -1; if (!a.isPinned && b.isPinned) return 1; return b.createdAt.getTime() - a.createdAt.getTime(); }); if (selectedThread) { return ( setSelectedThread(null)} onReply={handleReply} onLikeReply={handleLikeReply} isConnected={isConnected} /> ); } return (
{/* Header */}

Forum

{/* Search */}
setSearchQuery(e.target.value)} placeholder="Konularda ara..." className="pl-9 bg-gray-900 border-gray-800 text-white placeholder:text-gray-500" />
{/* Stats */}
{threads.length} Konu
{threads.filter(t => t.isPinned).length} Sabitlenmiş
{/* Thread List */}
{isLoading ? ( <> {[...Array(4)].map((_, i) => ( ))} ) : sortedThreads.length === 0 ? (

{searchQuery ? 'Konu bulunamadı' : 'Henüz konu yok'}

{!searchQuery && ( )}
) : ( sortedThreads.map(thread => ( setSelectedThread(thread)} /> )) )}
); } export default ForumSection;