package com.rhinemann.project;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

public class Temper extends AppCompatActivity {

    Integer questionId, temper;
    int[] temperAnswers;
    TextView temperQuestion;
    String[] temperQuestions;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_temper);

        temperQuestions = getResources().getStringArray(R.array.Temper_Questions);
        temperQuestion = findViewById(R.id.Temper_Question);
        questionId = 0;
        temper = 0;
        temperAnswers = new int[]{0, 0, 0, 0};

        temperQuestion.setText(temperQuestions[questionId]);

        Button yesButton = findViewById(R.id.Button_Yes);

        yesButton.setOnClickListener(v -> Test(1));

        Button noButton = findViewById(R.id.Button_No);

        noButton.setOnClickListener(v -> Test(0));

        Button Home = findViewById(R.id.home);

        Home.setOnClickListener(v -> {
            Intent intent = new Intent(Temper.this, HomeScreen.class);
            startActivity(intent);
        });

    }

    public void Test(int amount) {
        if (questionId <= 19) {
            temper = 0;
        } else if (questionId <= 39) {
            temper = 1;
        } else if (questionId <= 59){
            temper = 2;
        } else {
            temper = 3;
        }

        temperAnswers[temper] += amount;

        if (questionId < 79) {
            questionId ++;
            temperQuestion.setText(temperQuestions[questionId]);
        } else {
            graphResult();
        }
    }

    public void graphResult(){
        Intent intent = new Intent(Temper.this, TemperResult.class);
        intent.putExtra("Temper", temperAnswers);
        startActivity(intent);
    }

}