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 (
واصل رحلة التعلم من حيث توقفت