class LearningPlatform { constructor() { this.currentDay = 1; this.maxDays = 10; this.isInitialized = false; } async initialize() { try { // مقداردهی اولیه سیستم احراز هویت AuthMiddleware.initializeApp(); // بارگذاری کامپوننت‌ها this.loadComponents(); // بارگذاری محتوا await this.loadContent(); // راه‌اندازی رابط کاربری this.setupEventListeners(); this.updateUI(); this.isInitialized = true; console.log('Platform initialized successfully'); } catch (error) { console.error('Failed to initialize platform:', error); this.showError('خطا در بارگذاری برنامه. لطفاً صفحه را رفرش کنید.'); } } loadComponents() { // بارگذاری هدر و فوتر if (typeof HeaderComponent !== 'undefined') { HeaderComponent.render(); } if (typeof NavigationComponent !== 'undefined') { NavigationComponent.render(); } } async loadContent() { // بارگذاری همزمان محتوا await Promise.all([ this.loadLesson(), this.loadQuiz(), this.loadExercise() ]); } async loadLesson() { try { const response = await fetch(`data/lessons/day${this.currentDay}.json`); if (!response.ok) throw new Error('Lesson not found'); const lessonData = await response.json(); if (typeof LessonUI !== 'undefined') { LessonUI.render(lessonData); } } catch (error) { console.error('Error loading lesson:', error); document.getElementById('lessonContent').innerHTML = '
خطا در بارگذاری محتوا
'; } } async loadQuiz() { try { const response = await fetch(`data/quizzes/day${this.currentDay}.json`); if (!response.ok) throw new Error('Quiz not found'); const quizData = await response.json(); if (typeof QuizUI !== 'undefined') { QuizUI.render(quizData); } } catch (error) { console.error('Error loading quiz:', error); document.getElementById('quizForm').innerHTML = '
خطا در بارگذاری آزمون
'; } } async loadExercise() { try { const response = await fetch(`data/exercises/day${this.currentDay}.json`); if (!response.ok) throw new Error('Exercise not found'); const exerciseData = await response.json(); if (typeof ExerciseUI !== 'undefined') { ExerciseUI.render(exerciseData); } } catch (error) { console.error('Error loading exercise:', error); document.getElementById('exerciseContent').innerHTML = '
خطا در بارگذاری تمرین
'; } } setupEventListeners() { // مدیریت تغییر روز document.addEventListener('dayChanged', (event) => { this.currentDay = event.detail.day; this.loadContent(); this.updateUI(); }); // مدیریت وضعیت احراز هویت document.addEventListener('authStateChanged', () => { this.updateUI(); }); // جلوگیری از ارسال فرم‌ها document.addEventListener('submit', (e) => { e.preventDefault(); }); } updateUI() { this.updateAuthDisplay(); this.updateProgressDisplay(); this.updateNavigation(); } updateAuthDisplay() { const authSection = document.getElementById('authSection'); const user = authManager.getCurrentUser(); if (authSection) { if (user) { authSection.innerHTML = `
${user.profile.fullName ? user.profile.fullName.charAt(0) : user.username.charAt(0)}
خوش آمدید, ${user.profile.fullName || user.username}! ${this.getRoleText(user.role)}
`; } else { authSection.innerHTML = `

برای ذخیره پیشرفت و شرکت در آزمون‌ها وارد شوید

`; } } } updateProgressDisplay() { const user = authManager.getCurrentUser(); const progressContent = document.getElementById('progressContent'); if (progressContent && user) { const progress = user.progress || {}; progressContent.innerHTML = `
${progress.totalScore || 0}
امتیاز کل
${progress.completedLessons?.length || 0}
درس‌های تکمیل شده
${this.currentDay}
درس فعلی
`; } } updateNavigation() { const progressIndicator = document.getElementById('progressIndicator'); if (progressIndicator) { progressIndicator.innerHTML = ` روز ${this.currentDay} از ${this.maxDays} `; } } getRoleText(role) { const roles = { 'student': 'دانشجو', 'instructor': 'مربی', 'admin': 'مدیر' }; return roles[role] || role; } // متدهای عمومی showLogin() { ModalComponent.showLogin(); } showRegister() { ModalComponent.showRegister(); } logout() { authManager.logout(); this.updateUI(); ModalComponent.showMessage('خروج', 'با موفقیت از سیستم خارج شدید.'); } nextDay() { if (this.currentDay < this.maxDays) { this.currentDay++; this.loadContent(); this.updateUI(); } } previousDay() { if (this.currentDay > 1) { this.currentDay--; this.loadContent(); this.updateUI(); } } showError(message) { ModalComponent.showError(message); } } // ایجاد نمونه اصلی برنامه const app = new LearningPlatform(); // راه‌اندازی برنامه هنگام بارگذاری صفحه document.addEventListener('DOMContentLoaded', () => { app.initialize(); });