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

    Integer questionId, discipline;
    int[] profileAnswers;
    TextView profileQuestion;
    String[] profileQuestions;

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

        profileQuestions = getResources().getStringArray(R.array.Profile_Questions);
        profileQuestion = findViewById(R.id.Profile_Question);
        questionId = 0;
        discipline = 0;
        profileAnswers = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

        profileQuestion.setText(profileQuestions[questionId]);



        //Кнопка плюс
        Button plusButton = findViewById(R.id.Button_Plus);

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

        //Кнопка мінус
        Button minusButton = findViewById(R.id.Button_Minus);

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

        //Кнопка нуль
        Button zeroButton = findViewById(R.id.Button_Zero);

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

        //Кнопка два плюси
        Button doublePlusButton = findViewById(R.id.Button_Double_Plus);

        doublePlusButton.setOnClickListener(v -> Test(2));

        //Кнопка два мінуси
        Button doubleMinusButton = findViewById(R.id.Button_Double_Minus);

        doubleMinusButton.setOnClickListener(v -> Test(-2));

        //Кнорка Меню
        Button Home = findViewById(R.id.home);

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

    public void Test(int amount) {
        if (questionId < 102){
            questionId ++;
            profileQuestion.setText(profileQuestions[questionId]);
        } else {
            graphResult();
        }

        profileAnswers[discipline] += amount;

        if (discipline == 16){
            discipline = 0;
        } else {
            discipline ++;
        }
    }

    public void graphResult() {
        Intent intent = new Intent(Profile.this, Graph.class);
        intent.putExtra("profileAnswers", profileAnswers);
        startActivity(intent);
    }

}