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 MBTI extends AppCompatActivity {

    Integer questionId;
    TextView MBTIQuestion, MBTIAnswer;
    String[] MBTIQuestions, MBTIAnswers;
    String Result;
    char[] ResultChar;
    Button aButton, bButton, Home;

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

        questionId = 0;

        MBTIQuestion = findViewById(R.id.MBTI_Question);
        MBTIAnswer = findViewById(R.id.MBTI_Answer);

        MBTIQuestions = getResources().getStringArray(R.array.MBTI_Questions);
        MBTIAnswers = getResources().getStringArray(R.array.MBTI_Answers);

        aButton = findViewById(R.id.Button_A);
        bButton = findViewById(R.id.Button_B);


        Result = "MBTI";
        ResultChar = Result.toCharArray();

        MBTIQuestion.setText(MBTIQuestions[questionId]);
        MBTIAnswer.setText(MBTIAnswers[questionId]);

        aButton.setOnClickListener(v -> {
            switch (questionId) {
                case 0:
                    ResultChar[0] = 'E';
                    break;
                case 1:

                    ResultChar[1] = 'S';
                    break;
                case 2:
                    ResultChar[2] = 'T';
                    break;
                case 3:
                    ResultChar[3] = 'J';
                    break;
            }

            Result = String.valueOf(ResultChar);

            if (questionId < 3) {
                questionId++;
                MBTIQuestion.setText(MBTIQuestions[questionId]);
                MBTIAnswer.setText(MBTIAnswers[questionId]);
            } else { MBTIResult(); }
        });

        bButton.setOnClickListener(v -> {
            switch (questionId) {
                case 0:
                    ResultChar[0] = 'I';
                    break;
                case 1:

                    ResultChar[1] = 'N';
                    break;
                case 2:
                    ResultChar[2] = 'F';
                    break;
                case 3:
                    ResultChar[3] = 'P';
                    break;
            }

            Result = String.valueOf(ResultChar);

            if (questionId < 3) {
                questionId++;
                MBTIQuestion.setText(MBTIQuestions[questionId]);
                MBTIAnswer.setText(MBTIAnswers[questionId]);
            } else { MBTIResult(); }
        });

        Home = findViewById(R.id.home);

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

    }

    public void MBTIResult(){
        Intent intent = new Intent(MBTI.this, MBTIResult.class);
        intent.putExtra("Result", Result);
        startActivity(intent);
    }

}