package com.unis.sxzcl.ui.work_condition;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.PieEntry;
import com.unis.sxzcl.R;
import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentWorkConditionBinding;
import com.unis.sxzcl.widget.MyBarChart;
import com.unis.sxzcl.widget.MyPieChart;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 包名: com.unis.sxzcl.ui.work_condition
 * 类名: WorkConditionFragment
 * 作用描述: 作业情况统计
 * 创建人: mQ
 * 创建时间: 2020/11/13 16:23
 * 更新人:
 * 更新时间: 2020/11/13 16:23
 * 更新说明:
 * 版本号: 1.0
 */
public class WorkConditionFragment extends BaseFragment<FragmentWorkConditionBinding> {


    private MyBarChart mBarChart;
    private MyBarChart mWorkFinishBarChart;
    private MyPieChart mPieChart;

    @Override
    protected FragmentWorkConditionBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentWorkConditionBinding.inflate(inflater,container,false);
    }

    @Override
    protected void init() {
        mBinding.bar.setLeftClickListener(v -> finish());

        mWorkFinishBarChart = new MyBarChart(getContext(),mBinding.barChartWorkFinish);
        mBarChart = new MyBarChart(getContext(),mBinding.barChart);
        mPieChart = new MyPieChart(getContext(),mBinding.pieChart);
    }

    @Override
    protected void onFirstShow() {
        // 任务完成情况
        ArrayList<BarEntry> workFinishEntries = new ArrayList<>();
        workFinishEntries.add(new BarEntry(0, new float[]{10, 10}));
        workFinishEntries.add(new BarEntry(1, new float[]{20, 20}));
        workFinishEntries.add(new BarEntry(2, new float[]{30, 30}));
        workFinishEntries.add(new BarEntry(3, new float[]{40, 40}));
        workFinishEntries.add(new BarEntry(4, new float[]{50, 50}));
        workFinishEntries.add(new BarEntry(5, new float[]{60, 60}));
        workFinishEntries.add(new BarEntry(6, new float[]{70, 70}));
        workFinishEntries.add(new BarEntry(7, new float[]{80, 80}));
        workFinishEntries.add(new BarEntry(8, new float[]{70, 70}));
        workFinishEntries.add(new BarEntry(9, new float[]{60, 60}));
        workFinishEntries.add(new BarEntry(10, new float[]{50, 50}));
        workFinishEntries.add(new BarEntry(11, new float[]{40, 40}));

        List<String> workFinishLabels = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月",
                "7月", "8月", "9月", "10月", "11月", "12月");
        List<Integer> workFinishColors = Arrays.asList(getColorForResId(R.color.colorBlue), getColorForResId(R.color.colorAccentL));
        String[] workFinishBarLabels = new String[]{"按时完成", "逾期完成"};
        mWorkFinishBarChart.showChart(workFinishLabels, workFinishEntries, workFinishColors, workFinishBarLabels);

        // 工作类型排行
        ArrayList<BarEntry> barEntries = new ArrayList<>();
        barEntries.add(new BarEntry(0, 140));
        barEntries.add(new BarEntry(1, 120));
        barEntries.add(new BarEntry(2, 80));
        barEntries.add(new BarEntry(3, 50));
        barEntries.add(new BarEntry(4, 20));
        List<String> workTypeLabels = Arrays.asList("粮情监测", "通风作业", "熏蒸作业", "药剂领用", "仓房设施");
        mBarChart.showChart(workTypeLabels, barEntries);

        // 工作类型占比
        List<PieEntry> pieEntries = new ArrayList<>();
        pieEntries.add(new PieEntry(200f, "质量管理"));
        pieEntries.add(new PieEntry(290f, "储粮管理"));
        pieEntries.add(new PieEntry(240f, "安全生产"));
        pieEntries.add(new PieEntry(160f, "药剂管理"));
        pieEntries.add(new PieEntry(380f, "其他"));
        mPieChart.showChart(pieEntries, "工作类型占比");

    }

}
