import { useApp } from '../store'; import { channels, playlists, videos, standaloneVideos, formatNumber, getChannel, getPlaylistVideos } from '../data'; import { Play, Clock, CheckCircle, Trophy, Flame, Star, BookOpen } from 'lucide-react'; export default function Dashboard() { const { progress, setView, followedChannelIds, markVideoWatched } = useApp(); const followedChannels = channels.filter(c => followedChannelIds.includes(c.id)); const followedPlaylists = playlists.filter(p => followedChannelIds.includes(p.channelId)); // Get playlists with progress const playlistsInProgress = followedPlaylists .map(pl => ({ playlist: pl, channel: getChannel(pl.channelId), plVideos: getPlaylistVideos(pl.id), currentIndex: progress.playlistProgress[pl.id] || 0, completedCount: getPlaylistVideos(pl.id).filter(v => progress.watchedVideos.includes(v.id)).length, })) .filter(p => p.plVideos.length > 0) .sort((a, b) => { // Prioritize playlists in progress const aProgress = a.completedCount / a.plVideos.length; const bProgress = b.completedCount / b.plVideos.length; if (aProgress > 0 && aProgress < 1 && bProgress > 0 && bProgress < 1) return bProgress - aProgress; if (aProgress > 0 && aProgress < 1) return -1; if (bProgress > 0 && bProgress < 1) return 1; return 0; }); // Get recent videos from followed channels const recentVideos = standaloneVideos .filter(v => followedChannelIds.includes(v.channelId)) .concat( followedPlaylists.flatMap(pl => (videos[pl.id] || []).slice(-2) ) ) .sort(() => Math.random() - 0.5) .slice(0, 8); const totalVideosAvailable = followedPlaylists.reduce((sum, pl) => sum + (videos[pl.id]?.length || 0), 0) + standaloneVideos.filter(v => followedChannelIds.includes(v.channelId)).length; const overallProgress = totalVideosAvailable > 0 ? Math.round((progress.watchedVideos.length / totalVideosAvailable) * 100) : 0; return (
{/* Hero Stats */}

مرحبًا بك في مساري! 🎯

واصل رحلة التعلم من حيث توقفت

{progress.streak}
أيام متتالية
{progress.watchedVideos.length}
فيديو مُشاهد
{progress.completedPlaylists.length}
قائمة مكتملة
{followedChannels.length}
قناة متابعة
{overallProgress}%
نسبة الإنجاز
{/* Playlists Progress */}

قوائم التشغيل الخاصة بك

{playlistsInProgress.length} قائمة
{playlistsInProgress.slice(0, 9).map(({ playlist, channel, plVideos, completedCount }) => { const percentage = plVideos.length > 0 ? Math.round((completedCount / plVideos.length) * 100) : 0; const isComplete = progress.completedPlaylists.includes(playlist.id); const nextVideoIndex = completedCount; const nextVideo = plVideos[nextVideoIndex]; return ( ); })}
{/* Channel Grid */}

قنواتك المتابعة

{followedChannels.map(ch => { const chPlaylists = playlists.filter(p => p.channelId === ch.id); const chVideosWatched = [...standaloneVideos, ...Object.values(videos).flat()].filter( v => v.channelId === ch.id && progress.watchedVideos.includes(v.id) ).length; return ( ); })}
{/* Recent Videos */} {recentVideos.length > 0 && (

جديد من قنواتك

{recentVideos.map(video => { const channel = getChannel(video.channelId); const isWatched = progress.watchedVideos.includes(video.id); return ( ); })}
)} {/* Achievements */}

الإنجازات

{[ { emoji: '🌟', title: 'أول فيديو', desc: 'شاهد أول فيديو', done: progress.watchedVideos.length >= 1 }, { emoji: '📚', title: 'طالب مجتهد', desc: 'شاهد 10 فيديوهات', done: progress.watchedVideos.length >= 10 }, { emoji: '🔥', title: 'متسلسل', desc: '3 أيام متتالية', done: progress.streak >= 3 }, { emoji: '🏆', title: 'منتهٍ', desc: 'أكمل أول قائمة', done: progress.completedPlaylists.length >= 1 }, { emoji: '💎', title: 'محترف', desc: 'أكمل 3 قوائم', done: progress.completedPlaylists.length >= 3 }, { emoji: '🎯', title: 'هادف', desc: 'شاهد 50 فيديو', done: progress.watchedVideos.length >= 50 }, { emoji: '🚀', title: 'صاروخي', desc: '7 أيام متتالية', done: progress.streak >= 7 }, { emoji: '👑', title: 'ملك التعلم', desc: 'أكمل 10 قوائم', done: progress.completedPlaylists.length >= 10 }, ].map((ach, i) => (
{ach.emoji}
{ach.title}
{ach.desc}
{ach.done &&
✅ مُحقق
}
))}
); }