@@ -86,15 +86,20 @@ window.FirebaseManager = {
8686 db . collection ( 'quizResults' ) . add ( result ) . then ( function ( docRef ) {
8787 console . log ( '✅ Resultado salvo com ID:' , docRef . id ) ;
8888
89- // Atualizar estatísticas do usuário
90- if ( window . userAccountManager ) {
91- window . userAccountManager . updateStats ( {
92- score : percentage ,
93- timeSpent : timeSpent
94- } ) ;
95- }
89+ // DELAY REALISTA: Simular processamento do ranking (2-3 segundos)
90+ setTimeout ( function ( ) {
91+ // Atualizar estatísticas do usuário após delay
92+ if ( window . userAccountManager ) {
93+ window . userAccountManager . updateStats ( {
94+ score : percentage ,
95+ timeSpent : timeSpent
96+ } ) ;
97+ }
98+
99+ console . log ( '✅ Resultado salvo e estatísticas atualizadas após processamento' ) ;
100+ console . log ( 'ℹ️ RANKING: Será atualizado automaticamente todos os dias às 19h para economizar Firebase reads' ) ;
101+ } , Math . random ( ) * 1000 + 2000 ) ; // 2-3 segundos aleatórios
96102
97- console . log ( '✅ Resultado salvo e estatísticas atualizadas' ) ;
98103 resolve ( ) ;
99104 } ) . catch ( function ( error ) {
100105 console . error ( '❌ Erro ao salvar resultado:' , error ) ;
@@ -138,13 +143,20 @@ window.onLoginModalClose = function() {
138143window . onLoginSuccess = function ( ) {
139144 // Salvar resultado pendente se existir
140145 if ( pendingResult ) {
146+ // Mostrar mensagem de processamento
147+ alert ( '💾 Salvando resultado... O ranking é atualizado diariamente às 19h!' ) ;
148+
141149 window . FirebaseManager . saveQuizResult (
142150 pendingResult . difficulty ,
143151 pendingResult . score ,
144152 pendingResult . totalQuestions ,
145153 pendingResult . wrongAnswers
146154 ) . then ( function ( ) {
147- alert ( 'Seu resultado foi salvo! Agora você aparece no ranking! 🏆' ) ;
155+ // Delay para simular processamento do ranking
156+ setTimeout ( function ( ) {
157+ alert ( 'Seu resultado foi salvo! Você aparecerá no ranking após às 19h! 🏆' ) ;
158+ } , Math . random ( ) * 1000 + 2000 ) ; // 2-3 segundos
159+
148160 pendingResult = null ;
149161 hideResultsModal ( ) ; // Fecha tela de resultados e reinicia
150162 } ) ;
@@ -154,13 +166,20 @@ window.onLoginSuccess = function() {
154166window . onRegisterSuccess = function ( ) {
155167 // Salvar resultado pendente se existir
156168 if ( pendingResult ) {
169+ // Mostrar mensagem de processamento
170+ alert ( '💾 Salvando resultado... O ranking é atualizado diariamente às 19h!' ) ;
171+
157172 window . FirebaseManager . saveQuizResult (
158173 pendingResult . difficulty ,
159174 pendingResult . score ,
160175 pendingResult . totalQuestions ,
161176 pendingResult . wrongAnswers
162177 ) . then ( function ( ) {
163- alert ( 'Seu resultado foi salvo! Bem-vindo ao ranking! 🏆' ) ;
178+ // Delay para simular processamento do ranking
179+ setTimeout ( function ( ) {
180+ alert ( 'Seu resultado foi salvo! Bem-vindo ao ranking (atualizado às 19h)! 🏆' ) ;
181+ } , Math . random ( ) * 1000 + 2000 ) ; // 2-3 segundos
182+
164183 pendingResult = null ;
165184 hideResultsModal ( ) ; // Fecha tela de resultados e reinicia
166185 } ) ;
@@ -269,33 +288,51 @@ function startSimulation(difficulty) {
269288 return ;
270289 }
271290
272- // CORREÇÃO AUTOMÁTICA: Se correct é undefined, tentar encontrar a resposta correta
291+ // CORREÇÃO CRÍTICA: Mapear correctAnswer para correct se não existe
292+ if ( typeof q . correct !== 'number' && typeof q . correctAnswer === 'number' ) {
293+ q . correct = q . correctAnswer ;
294+ console . log ( '✅ Mapeamento correctAnswer -> correct:' , q . correctAnswer , 'para pergunta:' , q . question . substring ( 0 , 50 ) + '...' ) ;
295+ console . log ( '📋 DEBUG: Opções da pergunta:' , q . options ) ;
296+ console . log ( '🎯 DEBUG: Resposta correta será:' , q . options [ q . correctAnswer ] ) ;
297+ }
298+
299+ // CORREÇÃO AUTOMÁTICA: Só tentar corrigir se realmente há um problema
273300 if ( typeof q . correct !== 'number' || q . correct < 0 || q . correct >= q . options . length ) {
274301 console . log ( '⚠️ Tentando corrigir pergunta com correct inválido:' , q . question . substring ( 0 , 50 ) + '...' ) ;
302+ console . log ( '🔍 Valor atual de q.correct:' , q . correct , 'Tipo:' , typeof q . correct ) ;
303+ console . log ( '🔍 Tamanho de options:' , q . options . length ) ;
275304
276305 // Verificar se há um campo alternativo ou tentar deduzir
277306 var correctIndex = - 1 ;
278307
279- // Estratégia 1: Procurar por um campo 'answer' ou 'correctAnswer'
280- if ( q . answer && typeof q . answer === 'string' ) {
308+ // Estratégia 1: Usar correctAnswer se for número válido
309+ if ( typeof q . correctAnswer === 'number' && q . correctAnswer >= 0 && q . correctAnswer < q . options . length ) {
310+ correctIndex = q . correctAnswer ;
311+ console . log ( 'Tentativa 1 - usando correctAnswer numérico:' , q . correctAnswer ) ;
312+ }
313+
314+ // Estratégia 2: Procurar por um campo 'answer' como string
315+ if ( correctIndex === - 1 && q . answer && typeof q . answer === 'string' ) {
281316 correctIndex = q . options . indexOf ( q . answer ) ;
282- console . log ( 'Tentativa 1 - campo answer:' , q . answer , 'índice:' , correctIndex ) ;
317+ console . log ( 'Tentativa 2 - campo answer:' , q . answer , 'índice:' , correctIndex ) ;
283318 }
284319
285- // Estratégia 2 : Procurar por um campo 'correctAnswer'
320+ // Estratégia 3 : Procurar por um campo 'correctAnswer' como string
286321 if ( correctIndex === - 1 && q . correctAnswer && typeof q . correctAnswer === 'string' ) {
287322 correctIndex = q . options . indexOf ( q . correctAnswer ) ;
288- console . log ( 'Tentativa 2 - campo correctAnswer:' , q . correctAnswer , 'índice:' , correctIndex ) ;
323+ console . log ( 'Tentativa 3 - campo correctAnswer string :' , q . correctAnswer , 'índice:' , correctIndex ) ;
289324 }
290325
291- // Estratégia 3 : Se ainda não encontrou, usar a primeira opção como padrão temporário
326+ // Estratégia 4 : Se ainda não encontrou, usar a primeira opção como último recurso
292327 if ( correctIndex === - 1 ) {
293328 correctIndex = 0 ;
294329 console . log ( '⚠️ USANDO PRIMEIRA OPÇÃO COMO PADRÃO para:' , q . question . substring ( 0 , 50 ) ) ;
295330 }
296331
297332 q . correct = correctIndex ;
298333 console . log ( '✅ Pergunta corrigida - novo índice correct:' , correctIndex ) ;
334+ } else {
335+ console . log ( '✅ Pergunta já tem correct válido:' , q . correct ) ;
299336 }
300337
301338 // Verificar novamente se a resposta correta existe
@@ -420,6 +457,17 @@ function nextQuestion() {
420457 console . log ( '✅ Resposta CORRETA!' ) ;
421458 } else {
422459 console . log ( '❌ Resposta INCORRETA!' ) ;
460+
461+ // DEBUG DETALHADO: Vamos verificar os valores exatos
462+ console . log ( '🔍 DEBUG RESPOSTA INCORRETA:' ) ;
463+ console . log ( '- Pergunta:' , question . question ) ;
464+ console . log ( '- Todas as opções:' , question . options ) ;
465+ console . log ( '- selectedOption (índice):' , selectedOption ) ;
466+ console . log ( '- question.correct (índice correto):' , question . correct ) ;
467+ console . log ( '- Resposta escolhida:' , question . options [ selectedOption ] ) ;
468+ console . log ( '- Resposta correta:' , question . options [ question . correct ] ) ;
469+ console . log ( '- Campo correctAnswer original:' , question . correctAnswer ) ;
470+
423471 wrongAnswers . push ( {
424472 question : question . question ,
425473 selectedAnswer : question . options [ selectedOption ] || 'Opção não encontrada' ,
@@ -564,10 +612,16 @@ function saveResults() {
564612 if ( window . getCurrentUser && window . getCurrentUser ( ) ) {
565613 console . log ( '✅ Usuário já logado, salvando automaticamente...' ) ;
566614
615+ // Mostrar mensagem de processamento
616+ alert ( '💾 Salvando resultado... O ranking é atualizado diariamente às 19h!' ) ;
617+
567618 window . FirebaseManager . saveQuizResult ( currentDifficulty , score , currentQuiz . length , wrongAnswers )
568619 . then ( function ( ) {
569- alert ( 'Seu resultado foi salvo no ranking! 🏆' ) ;
570- hideResultsModal ( ) ;
620+ // Delay para simular processamento do ranking
621+ setTimeout ( function ( ) {
622+ alert ( 'Seu resultado foi salvo! Você aparecerá no ranking após às 19h! 🏆' ) ;
623+ hideResultsModal ( ) ;
624+ } , Math . random ( ) * 1000 + 2000 ) ; // 2-3 segundos
571625 } ) ;
572626 } else {
573627 console . log ( '❌ Usuário não logado, solicitando login...' ) ;
0 commit comments