import { Component } from '@angular/core';

@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss']
})
export class Tab3Page {

  public student: any = {
    cityList: ['学前', '小学', '中学', '大学'],
    city: '小学'
  };
  public searchQuery: string = '';
  public userAnswer: string = '';
  public answerChecked: boolean = false;
  public isCorrect: boolean = false;

  public questions: any = {
    '学前': [
      { title: '学前题目1', content: '苹果是什么颜色的？', answer: '红色' },
      { title: '学前题目2', content: '天空是什么颜色的？', answer: '蓝色' }
    ],
    '小学': [
      { title: '小学题目1', content: '中国的首都是哪里？', answer: '北京' },
      { title: '小学题目2', content: '长江是世界第几长河流？', answer: '第三' }
    ],
    '中学': [
      { title: '中学题目1', content: '光的传播速度是多少？', answer: '299792458米/秒' },
      { title: '中学题目2', content: '元素周期表的第一元素是什么？', answer: '氢' }
    ],
    '大学': [
      { title: '大学题目1', content: '相对论是谁提出的？', answer: '爱因斯坦' },
      { title: '大学题目2', content: 'DNA的双螺旋结构是谁发现的？', answer: '沃森和克里克' }
    ]
  };

  public currentQuestion: any = this.questions[this.student.city][0];

  constructor() {}

  refreshQuestion() {
    const currentQuestions = this.questions[this.student.city];
    const randomIndex = Math.floor(Math.random() * currentQuestions.length);
    this.currentQuestion = currentQuestions[randomIndex];
    this.userAnswer = '';
    this.answerChecked = false;
  }

  checkAnswer() {
    this.answerChecked = true;
    this.isCorrect = this.userAnswer === this.currentQuestion.answer;
  }
}