package com.example.views;

import com.example.components.BarChart;
import com.example.components.Card;
import com.example.components.LineChart;
import com.example.components.PieChart;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.HasDynamicTitle;
import com.vaadin.flow.router.Route;

import java.util.List;

@Route("")
public class DashboardView extends VerticalLayout implements HasDynamicTitle {

    public DashboardView() {
        addClassName("dialect-content");

        List<String> months = List.of(
                getTranslation("month.jan"), getTranslation("month.feb"),
                getTranslation("month.mar"), getTranslation("month.apr"),
                getTranslation("month.may"), getTranslation("month.jun"));

        LineChart lineChart = new LineChart();
        lineChart.setWidthFull();
        lineChart.setHeight("400px");
        lineChart.setData(getTranslation("chart.revenueSeries"),
                List.of(30.0, 40.0, 35.0, 50.0, 49.0, 60.0),
                months);
        lineChart.addPointClickListener(e -> {
            Notification.show(getTranslation("chart.pointClick",
                    e.getSeriesIndex(), e.getDataPointIndex()));
        });

        BarChart barChart = new BarChart();
        barChart.setWidthFull();
        barChart.setHeight("400px");
        barChart.setData(getTranslation("chart.revenueSeries"),
                List.of(30.0, 40.0, 35.0, 50.0, 49.0, 60.0),
                months);
        barChart.addPointClickListener(e -> {
            Notification.show(getTranslation("chart.pointClick",
                    e.getSeriesIndex(), e.getDataPointIndex()));
        });

        PieChart pieChart = new PieChart();
        pieChart.setWidthFull();
        pieChart.setHeight("400px");
        pieChart.setData(
                List.of(30.0, 40.0, 35.0, 50.0),
                List.of(getTranslation("region.north"), getTranslation("region.south"),
                        getTranslation("region.east"), getTranslation("region.west")));
        pieChart.addPointClickListener(e -> {
            Notification.show(getTranslation("chart.sliceClick", e.getDataPointIndex()));
        });

        add(new Card(getTranslation("card.revenueTrend"), lineChart),
                new Card(getTranslation("card.revenueByMonth"), barChart),
                new Card(getTranslation("card.revenueByRegion"), pieChart));
    }

    @Override
    public String getPageTitle() {
        return getTranslation("page.dashboard");
    }
}
