All files / components/exercises MultiplyExercise.js

0% Statements 0/195
0% Branches 0/42
0% Functions 0/31
0% Lines 0/193

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
export default {
    name: 'MultiplyExercise',
    emits: ['back', 'points-updated'],
    data() {
        return {
            isSetupMode: true,
            settings: {
                mode: null,      // 'learn' lub 'challenge'
                range: null,     // 'to100' lub 'to1000'
                rangeDescriptions: {
                    to100: 'Mnożenie do 100 (max 10x10)',
                    to1000: 'Mnożenie do 1000 (różne kombinacje)'
                }
            },
            exercise: {
                num1: 0,
                num2: 0,
                currentIndex: 0,
                totalQuestions: 10,
                isComplete: false,
                current: null
            },
            userAnswer: '',
            stats: {
                points: 0,
                correctAnswers: 0,
                mistakes: 0,
                currentStreak: 0
            },
            feedback: {
                message: '',
                type: ''
            },
            timer: {
                time: 0,
                isRunning: false,
                interval: null
            },
            showSummary: false,
            setupValidation: {
                mode: { required: true, selected: false },
                range: { required: true, selected: false }
            },
            setupFeedback: {
                show: true,
                message: 'Wybierz opcje aby rozpocząć ćwiczenie! 😊',
                type: 'info'
            },
            pointsMultiplier: {
                current: 1,
                message: '',
                isAnimating: false
            },
            successSound: null
        }
    },
    methods: {
        updateSetupValidation(field, value) {
            this.setupValidation[field].selected = !!value;
            this.checkSetupCompleteness();
        },
 
        checkSetupCompleteness() {
            const missing = [];
            if (!this.settings.mode) missing.push('tryb ćwiczenia');
            if (!this.settings.range) missing.push('zakres liczb');
 
            if (missing.length > 0) {
                this.setupFeedback = {
                    show: true,
                    message: `Wybierz jeszcze: ${missing.join(', ')} 😊`,
                    type: 'info'
                };
            } else {
                this.setupFeedback = {
                    show: true,
                    message: 'Świetnie! Możesz rozpocząć ćwiczenie! 🎉',
                    type: 'success'
                };
            }
        },
 
        async startExercise() {
            if (!this.settings.mode || !this.settings.range) {
                this.setupFeedback = {
                    show: true,
                    message: 'Wybierz wszystkie potrzebne opcje przed rozpoczęciem 😊',
                    type: 'warning'
                };
                return;
            }
 
            // Reset wszystkich statystyk na początku nowego ćwiczenia
            this.stats = {
                points: 0,
                correctAnswers: 0,
                mistakes: 0,
                currentStreak: 0
            };
 
            // Reset mnożnika punktów
            this.pointsMultiplier = {
                current: 1,
                message: '',
                isAnimating: false
            };
 
            // Reset ćwiczenia
            this.exercise = {
                num1: 0,
                num2: 0,
                currentIndex: 0,
                totalQuestions: 10,
                isComplete: false,
                current: null
            };
 
            // Wyłącz tryb setup
            this.isSetupMode = false;
 
            // Wygeneruj pierwsze pytanie
            await this.generateQuestion();
 
            // Uruchom timer jeśli to tryb wyzwań
            if (this.settings.mode === 'challenge') {
                this.startTimer();
            }
        },
 
        async generateQuestion() {
            try {
                // Użyj lokalnej funkcji zamiast API do generowania pytań
                const question = this.generateLocalQuestion();
 
                // Aktualizacja current
                this.exercise.current = {
                    num1: question.num1,
                    num2: question.num2
                };
                console.log('🔍 Lokalnie wygenerowane pytanie:', question);
 
                // Reset odpowiedzi użytkownika i feedbacku
                this.userAnswer = '';
                this.feedback = {
                    message: '',
                    type: ''
                };
            } catch (error) {
                console.error('Error generating question:', error);
                this.feedback = {
                    message: 'Wystąpił błąd podczas generowania pytania: ' + error.message,
                    type: 'error'
                };
            }
        },
 
        generateLocalQuestion() {
            console.log('🔍 Generuję lokalne pytanie dla zakresu:', this.settings.range);
 
            let num1, num2;
 
            if (this.settings.range === 'to100') {
                // Dla zakresu do 100 (max 10×10)
                num1 = Math.floor(Math.random() * 10) + 1; // 1-10
                num2 = Math.floor(Math.random() * 10) + 1; // 1-10
            } else {
                // Dla zakresu do 1000:
                // - druga liczba: jednocyfrowa (2-9)
                // - pierwsza liczba: zapewniająca wynik ≤ 1000
                num2 = Math.floor(Math.random() * 8) + 2; // 2-9
 
                // Maksymalna wartość num1, aby wynik nie przekroczył 1000
                const maxNum1 = Math.floor(1000 / num2);
 
                // Minimalny zakres powinien być 10 lub większy dla sensownych zadań
                const minNum1 = 10;
 
                num1 = Math.floor(Math.random() * (maxNum1 - minNum1 + 1)) + minNum1;
            }
 
            console.log(`🔍 Wygenerowano: ${num1} × ${num2} = ${num1 * num2}`);
 
            return {
                num1: num1,
                num2: num2,
                answer: num1 * num2
            };
        },
 
        async checkAnswer() {
            if (!this.userAnswer) {
                this.feedback = {
                    message: 'Wprowadź odpowiedź!',
                    type: 'error',
                    animation: 'animate-shake'
                };
                return;
            }
 
            try {
                // Sprawdź odpowiedź lokalnie
                const num1 = this.exercise.current.num1;
                const num2 = this.exercise.current.num2;
                const expectedAnswer = num1 * num2;
                const userAnswer = parseInt(this.userAnswer);
                const isCorrect = userAnswer === expectedAnswer;
 
                if (isCorrect) {
                    this.handleCorrectAnswer();
                } else {
                    this.handleIncorrectAnswer(expectedAnswer);
                }
 
                // Inkrementujemy licznik pytań i sprawdzamy, czy to koniec ćwiczenia
                this.exercise.currentIndex++;
                if (this.exercise.currentIndex >= this.exercise.totalQuestions) {
                    this.completeExercise();
                } else {
                    // Generujemy nowe pytanie po krótkiej pauzie
                    setTimeout(() => {
                        try {
                            this.generateQuestion();
                        } catch (err) {
                            console.error('Error generating next question:', err);
                            this.feedback = {
                                message: 'Wystąpił błąd podczas generowania pytania. Spróbuj odświeżyć stronę.',
                                type: 'error'
                            };
                        }
                    }, 1500);
                }
            } catch (error) {
                console.error('Error checking answer:', error);
                this.feedback = {
                    message: 'Wystąpił błąd podczas sprawdzania odpowiedzi. Spróbuj ponownie.',
                    type: 'error',
                    animation: 'animate-shake'
                };
            }
        },
 
        handleCorrectAnswer() {
            // Zwiększ statystyki
            this.stats.correctAnswers++;
            this.stats.currentStreak++;
 
            // Zaktualizuj mnożnik i dodaj 10 punktów bazowych
            this.updatePointsMultiplier();
            this.addPoints(10);
 
            // Zapisz stan po dodaniu punktów
            setTimeout(() => {
                try {
                    fetch('/api/log-status', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        credentials: 'same-origin',
                        body: JSON.stringify({
                            component: 'MultiplyExercise',
                            method: 'handleCorrectAnswer',
                            data: {
                                event: 'after_points_update',
                                pointsMultiplier: this.pointsMultiplier.current,
                                totalPoints: this.stats.points,
                                streak: this.stats.currentStreak
                            }
                        })
                    }).catch(err => console.error('Error logging after points update:', err));
                } catch (error) {
                    console.error('Error logging after points update:', error);
                }
            }, 10);
 
            // Ustaw feedback dla użytkownika
            this.feedback = {
                message: 'Brawo! Poprawna odpowiedź! 🎉',
                type: 'success',
                animation: 'animate-bounce'
            };
 
            // Synchronizuj punkty z główną aplikacją po poprawnej odpowiedzi
            setTimeout(() => {
                try {
                    this.$root.syncUserPoints();
                } catch (err) {
                    console.error('Error synchronizing points:', err);
                }
            }, 500);
 
            // Odtwórz dźwięk sukcesu jeśli jest dostępny
            if (this.successSound) {
                try {
                    this.successSound.currentTime = 0;
                    this.successSound.play().catch(error => {
                        console.log('Nie można odtworzyć dźwięku, wyłączam:', error.message);
                        this.successSound = null; // Wyłącz dźwięk jeśli wystąpił błąd
                    });
                } catch (error) {
                    console.log('Błąd podczas odtwarzania dźwięku:', error.message);
                    this.successSound = null;
                }
            }
 
            // Generuj nowe pytanie po krótkim opóźnieniu
            setTimeout(async () => {
                this.exercise.currentIndex++;
                if (this.exercise.currentIndex >= this.exercise.totalQuestions) {
                    this.completeExercise();
                } else {
                    try {
                        await this.generateQuestion();
                    } catch (err) {
                        console.error('Error generating next question:', err);
                        this.feedback = {
                            message: 'Wystąpił błąd podczas generowania pytania. Spróbuj odświeżyć stronę.',
                            type: 'error'
                        };
                    }
                }
            }, 1500);
        },
 
        handleIncorrectAnswer(expectedAnswer) {
            this.stats.mistakes++;
            this.stats.currentStreak = 0;
            this.feedback = {
                message: `Niestety, spróbuj jeszcze raz. Poprawna odpowiedź to ${expectedAnswer}`,
                type: 'error',
                animation: 'animate-shake'
            };
        },
 
        addPoints(points) {
            // Bazowa liczba punktów wynosi 10 punktów, chyba że przekazano inną wartość
            const basePoints = points || 10;
 
            console.log('📊 addPoints - BEFORE', {
                currentPoints: this.stats.points,
                basePoints: basePoints,
                multiplier: this.pointsMultiplier.current
            });
 
            // Bezpieczne logowanie - zawijamy w blok try-catch
            try {
                const logRequest = {
                    component: 'MultiplyExercise',
                    method: 'addPoints',
                    data: {
                        event: 'before_points_add',
                        currentPoints: this.stats.points,
                        basePoints: basePoints,
                        multiplier: this.pointsMultiplier.current
                    }
                };
 
                // Używamy setTimeout aby wykonać fetch asynchronicznie i nie blokować głównego kodu
                setTimeout(() => {
                    try {
                        fetch('/api/log-status', {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            credentials: 'same-origin',
                            body: JSON.stringify(logRequest)
                        }).catch(err => console.error('Error logging before points add:', err));
                    } catch (err) {
                        console.error('Error in fetch before points add:', err);
                    }
                }, 10);
            } catch (error) {
                console.error('Error preparing log data:', error);
            }
 
            // Mnożymy punkty bazowe przez mnożnik
            const adjustedPoints = Math.round(basePoints * this.pointsMultiplier.current);
            this.stats.points += adjustedPoints;
 
            console.log('📊 addPoints - AFTER', {
                newTotal: this.stats.points,
                calculation: `${basePoints} × ${this.pointsMultiplier.current} = ${adjustedPoints}`
            });
 
            // Emitujemy zdarzenie z rzeczywistą liczbą dodanych punktów (po uwzględnieniu mnożnika)
            this.$emit('points-updated', adjustedPoints);
 
            // Log po dodaniu punktów - bezpieczne wykonanie
            setTimeout(() => {
                try {
                    fetch('/api/log-status', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        credentials: 'same-origin',
                        body: JSON.stringify({
                            component: 'MultiplyExercise',
                            method: 'addPoints',
                            data: {
                                event: 'after_points_add',
                                newTotal: this.stats.points,
                                basePoints: basePoints,
                                multiplier: this.pointsMultiplier.current,
                                adjustedPoints: adjustedPoints
                            }
                        })
                    }).catch(err => console.error('Error logging after points add:', err));
                } catch (error) {
                    console.error('Error logging after points add:', error);
                }
            }, 20);
        },
 
        completeExercise() {
            this.exercise.isComplete = true;
            if (this.timer.interval) {
                clearInterval(this.timer.interval);
                this.timer.isRunning = false;
            }
            // Dodaj logikę podsumowania
            this.showSummary = true;
            const accuracy = ((this.exercise.totalQuestions - this.stats.mistakes) / this.exercise.totalQuestions) * 100;
 
            this.feedback = {
                message: `Gratulacje! Ukończyłeś ćwiczenie!\n` +
                    `Zdobyte punkty: ${this.stats.points}\n` +
                    `Poprawne odpowiedzi: ${this.stats.correctAnswers}/${this.exercise.totalQuestions}\n` +
                    `Dokładność: ${Math.round(accuracy)}%`,
                type: 'success'
            };
 
            // Wyświetlanie podsumowania na dłużej zanim wrócimy do menu
            setTimeout(() => {
                // Po czasie wróć do menu głównego
                this.isSetupMode = true;
            }, 5000);
        },
 
        startTimer() {
            this.timer = {
                isRunning: true,
                time: 60,
                interval: setInterval(() => {
                    this.timer.time--;
                    if (this.timer.time <= 0) {
                        this.completeExercise();
                    }
                }, 1000)
            };
        },
 
        updatePointsMultiplier() {
            console.log('📊 updatePointsMultiplier - START', {
                currentStreak: this.stats.currentStreak,
                settings: this.settings,
                prevMultiplier: this.pointsMultiplier.current
            });
 
            // Stan początkowy (logowanie do serwera)
            try {
                fetch('/api/log-status', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    credentials: 'same-origin',
                    body: JSON.stringify({
                        component: 'MultiplyExercise',
                        method: 'updatePointsMultiplier',
                        data: {
                            currentStreak: this.stats.currentStreak,
                            settings: this.settings,
                            prevMultiplier: this.pointsMultiplier.current
                        }
                    })
                });
            } catch (error) {
                console.error('Error logging multiplier status:', error);
            }
 
            let multiplier = 1;
            let messages = [];
            let multiplierDetails = [];
 
            if (this.settings.mode === 'challenge') {
                console.log('📊 Challenge mode detected - applying 1.5 multiplier');
                multiplier *= 1.5;
                messages.push('🚀');
                multiplierDetails.push('challenge mode: ×1.5');
 
                // Logowanie po zastosowaniu mnożnika challenge
                try {
                    fetch('/api/log-status', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        credentials: 'same-origin',
                        body: JSON.stringify({
                            component: 'MultiplyExercise',
                            method: 'updatePointsMultiplier',
                            data: {
                                event: 'challenge_multiplier_applied',
                                multiplier: multiplier,
                                mode: this.settings.mode
                            }
                        })
                    });
                } catch (error) {
                    console.error('Error logging challenge multiplier:', error);
                }
            }
 
            if (this.stats.currentStreak > 2) {
                console.log('📊 Streak > 2 detected - applying 1.2 multiplier');
                multiplier *= 1.2;
                messages.push('🔥');
                multiplierDetails.push('streak bonus: ×1.2');
 
                // Logowanie po zastosowaniu mnożnika za serię
                try {
                    fetch('/api/log-status', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        credentials: 'same-origin',
                        body: JSON.stringify({
                            component: 'MultiplyExercise',
                            method: 'updatePointsMultiplier',
                            data: {
                                event: 'streak_multiplier_applied',
                                streak: this.stats.currentStreak,
                                multiplier: multiplier
                            }
                        })
                    });
                } catch (error) {
                    console.error('Error logging streak multiplier:', error);
                }
            }
 
            // Dodatkowe mnożniki dla różnych zakresów
            if (this.settings.range && this.settings.range === 'to1000') {
                console.log('📊 to1000 range detected - applying 1.5 multiplier');
                multiplier *= 1.5;
                messages.push('🏆');
                multiplierDetails.push('harder range: ×1.5');
 
                // Logowanie po zastosowaniu mnożnika za zakres
                try {
                    fetch('/api/log-status', {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        credentials: 'same-origin',
                        body: JSON.stringify({
                            component: 'MultiplyExercise',
                            method: 'updatePointsMultiplier',
                            data: {
                                event: 'range_multiplier_applied',
                                range: this.settings.range,
                                multiplier: multiplier
                            }
                        })
                    });
                } catch (error) {
                    console.error('Error logging range multiplier:', error);
                }
            }
 
            // Sprawdź czy mnożnik się zmienił i animuj jeśli tak
            const prevMultiplier = this.pointsMultiplier.current;
            this.pointsMultiplier.current = multiplier;
            this.pointsMultiplier.message = messages.join(' ');
 
            console.log('📊 updatePointsMultiplier - RESULT', {
                prevMultiplier,
                newMultiplier: multiplier,
                change: multiplier - prevMultiplier,
                messages,
                details: multiplierDetails,
                pointsMultiplier: this.pointsMultiplier
            });
 
            // Logowanie wynikowego mnożnika
            try {
                fetch('/api/log-status', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    credentials: 'same-origin',
                    body: JSON.stringify({
                        component: 'MultiplyExercise',
                        method: 'updatePointsMultiplier',
                        data: {
                            event: 'multiplier_result',
                            prevMultiplier: prevMultiplier,
                            newMultiplier: multiplier,
                            change: multiplier - prevMultiplier,
                            messages: messages,
                            details: multiplierDetails
                        }
                    })
                });
            } catch (error) {
                console.error('Error logging multiplier result:', error);
            }
 
            // Animacja przy zmianie mnożnika
            if (prevMultiplier !== multiplier) {
                console.log('📊 Multiplier changed - animating badge');
                this.pointsMultiplier.isAnimating = true;
                setTimeout(() => {
                    this.pointsMultiplier.isAnimating = false;
                    console.log('📊 Animation ended');
                }, 1500);
            }
        },
 
        cleanupExercise() {
            // Czyszczenie timera
            if (this.timer.interval) {
                clearInterval(this.timer.interval);
            }
 
            // Reset wszystkich statystyk
            this.stats = {
                points: 0,
                correctAnswers: 0,
                mistakes: 0,
                currentStreak: 0
            };
 
            // Reset mnożnika
            this.pointsMultiplier = {
                current: 1,
                message: '',
                isAnimating: false
            };
 
            // Reset ćwiczenia
            this.exercise = {
                num1: 0,
                num2: 0,
                currentIndex: 0,
                totalQuestions: 10,
                isComplete: false,
                current: null
            };
 
            // Reset feedbacku
            this.feedback = {
                message: '',
                type: ''
            };
 
            // Reset timera
            this.timer = {
                time: 0,
                isRunning: false,
                interval: null
            };
 
            this.userAnswer = '';
            this.showSummary = false;
        }
    },
    watch: {
        'settings.mode'(newValue) {
            this.updateSetupValidation('mode', newValue);
            this.checkSetupCompleteness();
        },
        'settings.range'(newValue) {
            this.updateSetupValidation('range', newValue);
            this.checkSetupCompleteness();
        }
    },
    template: `
        <div class="max-w-4xl mx-auto p-4">
            <div v-if="isSetupMode" class="space-y-8">
                <div class="flex items-center mb-4">
                    <button @click="cleanupExercise(); $emit('back')" class="text-indigo-600 hover:text-indigo-800">← Powrót</button>
                    <div class="ml-auto space-x-4">
                        <span class="bg-blue-100 text-blue-800 px-3 py-1 rounded-full">Punkty: {{ stats.points }}</span>
                        <span class="bg-green-100 text-green-800 px-3 py-1 rounded-full">Seria: {{ stats.currentStreak }}</span>
                    </div>
                </div>
 
                <!--Komunikat pomocniczy-->
                <div v-if="setupFeedback.show" 
                     :class="['p-4 rounded-lg text-center transition-all duration-300',
                             setupFeedback.type === 'info' ? 'bg-blue-100 text-blue-800' :
                             setupFeedback.type === 'warning' ? 'bg-yellow-100 text-yellow-800' :
                             setupFeedback.type === 'success' ? 'bg-green-100 text-green-800' : '']"
                >
                    <p class="text-lg font-medium">{{ setupFeedback.message }}</p>
                </div>
 
                <!--Wybór trybu-->
                <div>
                    <h3 class="text-lg font-medium mb-4">Wybierz tryb:</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div 
                            @click="settings.mode = 'learn'; checkSetupCompleteness()"
                            :class="['p-6 rounded-lg cursor-pointer border-2 text-center transition-all duration-300',
                                    settings.mode === 'learn' ? 'border-indigo-600 bg-indigo-50 transform scale-105' :
                                    'border-gray-200 hover:border-indigo-300']"
                        >
                            <div class="text-3xl mb-2">📚</div>
                            <h4 class="font-medium">Tryb nauki</h4>
                            <p class="text-sm text-gray-600">Ucz się w swoim tempie</p>
                        </div>
                        <div 
                            @click="settings.mode = 'challenge'"
                            :class="['p-6 rounded-lg cursor-pointer border-2 text-center',
                                    settings.mode === 'challenge' ? 'border-indigo-600 bg-indigo-50' : 'border-gray-200']"
                        >
                            <div class="text-3xl mb-2">⭐</div>
                            <h4 class="font-medium">Tryb wyzwań</h4>
                            <p class="text-sm text-gray-600">Sprawdź swoje umiejętności</p>
                        </div>
                    </div>
                </div>
 
                <!--Wybór zakresu-->
                <div>
                    <h3 class="text-lg font-medium mb-4">Wybierz zakres:</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div 
                            @click="settings.range = 'to100'"
                            :class="['p-6 rounded-lg cursor-pointer border-2 text-center',
                                    settings.range === 'to100' ? 'border-indigo-600 bg-indigo-50' : 'border-gray-200']"
                        >
                            <div class="text-3xl mb-2">🔢</div>
                            <h4 class="font-medium">Mnożenie do 100</h4>
                            <p class="text-sm text-gray-600">Max 10x10</p>
                        </div>
                        <div 
                            @click="settings.range = 'to1000'"
                            :class="['p-6 rounded-lg cursor-pointer border-2 text-center',
                                    settings.range === 'to1000' ? 'border-indigo-600 bg-indigo-50' : 'border-gray-200']"
                        >
                            <div class="text-3xl mb-2">🔢</div>
                            <h4 class="font-medium">Mnożenie do 1000</h4>
                            <p class="text-sm text-gray-600">Różne kombinacje</p>
                        </div>
                    </div>
                </div>
 
                <button
                    @click="startExercise"
                    :disabled="!settings.mode || !settings.range"
                    :class="[
                        'w-full py-3 rounded-lg transition-all duration-300',
                        (!settings.mode || !settings.range)
                            ? 'bg-gray-300 cursor-not-allowed opacity-50'
                            : 'bg-indigo-600 text-white hover:bg-indigo-700 transform hover:scale-105'
                    ]"
                >
                    <span class="flex items-center justify-center">
                        <span>Rozpocznij ćwiczenie</span>
                        <span v-if="setupFeedback.type === 'success'" class="ml-2">🎮</span>
                    </span>
                </button>
            </div>
 
            <!--Główne ćwiczenie-->
            <div v-else>
                <div class="flex justify-between items-center mb-6">
                    <button @click="cleanupExercise(); isSetupMode = true" class="text-indigo-600 hover:text-indigo-800">← Wróć do ustawień</button>
                    <div class="flex items-center space-x-4">
                        <span class="bg-blue-100 text-blue-800 px-3 py-1 rounded-full">Punkty: {{ stats.points }}</span>
                        <span class="bg-green-100 text-green-800 px-3 py-1 rounded-full">Seria: {{ stats.currentStreak }}</span>
                        <div class="multiplier-badge px-3 py-1 rounded-full flex items-center space-x-2" 
                             :class="[pointsMultiplier.current > 1 ? 'bg-yellow-100' : 'bg-gray-100', 
                                     {'animate-bounce-gentle': pointsMultiplier.isAnimating}]">
                            <span class="text-xl">{{ pointsMultiplier.current > 1 ? '🌟' : '⭐' }}</span>
                            <span class="font-bold" :class="pointsMultiplier.current > 1 ? 'text-yellow-800' : 'text-gray-800'">×{{ pointsMultiplier.current.toFixed(1) }}</span>
                            <span class="text-sm" :class="pointsMultiplier.current > 1 ? 'text-yellow-700' : 'text-gray-700'">{{ pointsMultiplier.message }}</span>
                        </div>
                        <span v-if="timer.time" class="bg-red-100 text-red-800 px-3 py-1 rounded-full">Czas: {{ timer.time }}s</span>
                    </div>
                </div>
 
                <div class="math-exercise-container" v-if="!exercise.isComplete">
                    <div class="math-problem" v-if="exercise.current">{{ exercise.current.num1 }} × {{ exercise.current.num2 }} = ?</div>
                    <input v-model="userAnswer" @keyup.enter="checkAnswer" type="number" class="answer-input" placeholder="?" autofocus>
                    <div v-if="feedback.message" 
                         :class="['feedback-message', 
                                 feedback.type === 'success' ? 'bg-green-100 text-green-700' : 
                                 feedback.type === 'error' ? 'bg-red-100 text-red-700' : 
                                 'bg-blue-100 text-blue-700', 
                                 feedback.animation]">{{ feedback.message }}</div>
                </div>
 
                <div v-else class="math-exercise-container">
                    <h3 class="text-2xl font-bold text-indigo-600 mb-6">🎉 Ćwiczenie zakończone! 🎉</h3>
                    <div class="space-y-4 text-lg">
                        <p><span class="font-semibold">Zdobyte punkty:</span> <span class="text-indigo-600 font-bold">{{ stats.points }}</span></p>
                        <p><span class="font-semibold">Najdłuższa seria:</span> <span class="text-green-600 font-bold">{{ stats.currentStreak }}</span></p>
                        <p><span class="font-semibold">Liczba błędów:</span> <span class="text-red-600 font-bold">{{ stats.mistakes }}</span></p>
                        <p v-if="pointsMultiplier.current > 1">
                            <span class="font-semibold">Mnożnik bonusowy:</span> 
                            <span class="text-yellow-600 font-bold">×{{ pointsMultiplier.current.toFixed(1) }}</span>
                            <span class="text-sm ml-2">{{ pointsMultiplier.message }}</span>
                        </p>
                    </div>
                    <div class="mt-8 space-x-4">
                        <button @click="isSetupMode = true" class="bg-indigo-600 text-white px-6 py-3 rounded-lg hover:bg-indigo-700 transition-colors text-lg">Spróbuj ponownie</button>
                    </div>
                </div>
            </div>
        </div>
    `,
    mounted() {
        // Inicjalizacja dźwięku z obsługą błędów
        try {
            // Używamy ścieżki bezwzględnej, aby uniknąć problemów z względnymi URL
            const fullPath = window.location.origin + '/assets/sounds/success.mp3';
            this.successSound = new Audio(fullPath);
            this.successSound.preload = 'auto';
 
            this.successSound.onerror = (e) => {
                console.log('Nie można załadować dźwięku:', e);
                this.successSound = null; // Ustawiamy na null jeśli nie można załadować
            };
 
            // Próbujemy wstępnie załadować dźwięk
            console.log('Próbuję załadować dźwięk z:', fullPath);
        } catch (err) {
            console.log('Inicjalizacja dźwięku nie powiodła się:', err);
            this.successSound = null;
        }
 
        this.checkSetupCompleteness();
 
        // Upewnij się, że mnożnik jest zainicjalizowany
        this.updatePointsMultiplier();
    }
};