package com.example.stupidgame

import Question
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.view.KeyEventDispatcher.Component
import com.example.stupidgame.ui.theme.StupidGameTheme

class MainActivity : ComponentActivity() {

    var mTrueButton: Button? = null
    var mFalseButton:Button? = null
    var mNextButton:Button? = null
    var mCheatButton:Button? = null
    var mQuestion: TextView? = null
    var ACTIVITY = "MainActivity"
    val mQuestions = arrayOf (Question (R.string.question1,true),
        Question (R.string.question2,false),
        Question (R.string.question3,true),
        Question (R.string.question4,false),
        Question (R.string.question5,false))
    var mCurrent = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d (ACTIVITY,"onCreate")
        setContentView(R.layout.activity_main)
        mTrueButton = findViewById(R.id.truebutton)
        mFalseButton = findViewById(R.id.falsebutton)
        mNextButton = findViewById (R.id.nextbutton)
        mCheatButton = findViewById (R.id.maincheatbutton)
        mQuestion = findViewById (R.id.question)
        mQuestion!!.setText (mQuestions[mCurrent].mQuestionTextID)
        mNextButton!!.setOnClickListener {

            mCurrent = (mCurrent+1)%mQuestions.size
            mQuestion!!.setText (mQuestions[mCurrent].mQuestionTextID)
        }
        mTrueButton!!.setOnClickListener {
            GradeAnswer (true)
        }
        mFalseButton!!.setOnClickListener {
            GradeAnswer (false)
        }

    }

    fun GradeAnswer (ans:Boolean) {

        if (ans==mQuestions[mCurrent].mAnswer)
            Toast.makeText (this,R.string.correct,Toast.LENGTH_SHORT).show()
        else
            Toast.makeText (this,R.string.incorrect,Toast.LENGTH_SHORT).show()


    }
    override fun onStart() {
        super.onStart()
        Log.d (ACTIVITY,"onStart")
    }
    override fun onResume() {
        super.onResume()
        Log.d (ACTIVITY,"onResume")
    }
    override fun onPause() {
        super.onPause()
        Log.d (ACTIVITY,"onPause")
    }
    override fun onStop() {
        super.onStop()
        Log.d (ACTIVITY,"onStop")
    }
    override fun onDestroy() {
        super.onDestroy()
        Log.d (ACTIVITY,"onDestroy")
    }
    override fun onRestart() {
        super.onRestart()
        Log.d (ACTIVITY,"onRestart")
    }

}