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 android.graphics.Color;
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 = {"Холерик", "Сангвінік", "Флегматик", "Меланхолік"};

    @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);
        dataSet.setFillAlpha(200);

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

        XAxis xAxis = radarChart.getXAxis();
        xAxis.setYOffset(0f);
        xAxis.setXOffset(0f);
        xAxis.setValueFormatter(new IndexAxisValueFormatter(labels));

        radarChart.setData(data);
        radarChart.getDescription().setEnabled(false);
        radarChart.getLegend().setEnabled(false);
        radarChart.getXAxis().setTextSize(16f);
        radarChart.getYAxis().setEnabled(false);

        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<>();
        for (int i : Data) {
            if (i < 2) {
                Tempers.add(new RadarEntry(1));
            } else {
                Tempers.add(new RadarEntry(i));
            }
        }
        return Tempers;
    }

}