package com.rhinemann.project;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

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

import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;
import com.github.mikephil.charting.data.RadarEntry;
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;

import java.util.ArrayList;

public class TemperResult extends AppCompatActivity {

    RadarChart radarChart;
    Button homeButton;

    int[] Data;
    String[] labels = {"Choleric", "Sanguine", "Phlegmatic", "Melancholic"};

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

        Data = getIntent().getIntArrayExtra("Temper");

        radarChart = findViewById(R.id.Graph);

        RadarDataSet dataSet = new RadarDataSet(dataValues(), "Tempers");

        dataSet.setColor(R.color.colorPrimary);
        dataSet.setFillColor(R.color.colorAccent);
        dataSet.setLineWidth(2f);
        dataSet.setDrawFilled(true);

        RadarData data = new RadarData();
        data.addDataSet(dataSet);

        data.setDrawValues(false);

        XAxis xAxis = radarChart.getXAxis();
        xAxis.setValueFormatter(new IndexAxisValueFormatter(labels));

        radarChart.setData(data);
        radarChart.getDescription().setEnabled(false);
        radarChart.getLegend().setEnabled(false);
        radarChart.setRotationEnabled(false);
        radarChart.getXAxis().setTextSize(15f);
        radarChart.getXAxis().setAxisMaximum(20f);
        radarChart.getXAxis().setAxisMinimum(-20f);
        radarChart.getYAxis().setAxisMaximum(20f);
        radarChart.getYAxis().setAxisMinimum(-20f);

        homeButton = findViewById(R.id.home);
        homeButton.setOnClickListener(v -> {
            Intent intent = new Intent(TemperResult.this, HomeScreen.class);
            startActivity(intent);
        });
    }

    @NonNull
    private ArrayList<RadarEntry>dataValues(){
        ArrayList<RadarEntry> Tempers = new ArrayList<>();
        Tempers.add(new RadarEntry(Data[0]));
        Tempers.add(new RadarEntry(Data[1]));
        Tempers.add(new RadarEntry(Data[2]));
        Tempers.add(new RadarEntry(Data[3]));
        return Tempers;
    }

}