package com.unis.sxzcl.ui.job_account;

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

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

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

/**
 * 包名: com.unis.sxzcl.ui.job_account
 * 类名: JobAccountFragment
 * 作用描述: 工作统计
 * 创建人: mQ
 * 创建时间: 2020/11/25 18:48
 * 更新人:
 * 更新时间: 2020/11/25 18:48
 * 更新说明:
 * 版本号: 1.0
 */
public class JobAccountFragment extends BaseFragment<FragmentJobAccountBinding> {

    private List<String> monthLabels;
    private List<Integer> barColors;

    private MyBarChart mWorkFinishBarChart;
    private MyBarChart mActiveBarChart;


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

    @Override
    protected void init() {
        mBinding.bar.setLeftClickListener(v -> finish());
        mBinding.bar.setTitle("工作统计");

        monthLabels = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月",
                "7月", "8月", "9月", "10月", "11月", "12月");
        barColors = Arrays.asList(getColorForResId(R.color.colorBlue), getColorForResId(R.color.colorAccentL));

        mWorkFinishBarChart = new MyBarChart(getContext(),mBinding.barChartWorkFinish);
        mActiveBarChart = new MyBarChart(getContext(),mBinding.barChartActive);
    }

    @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}));

        String[] workFinishBarLabels = new String[]{"按时完成", "逾期完成"};
        mWorkFinishBarChart.showChart(monthLabels, workFinishEntries, barColors, workFinishBarLabels);

        // 活跃度统计
        ArrayList<BarEntry> activeEntries = new ArrayList<>();
        activeEntries.add(new BarEntry(0, new float[]{10, 10}));
        activeEntries.add(new BarEntry(1, new float[]{20, 20}));
        activeEntries.add(new BarEntry(2, new float[]{30, 30}));
        activeEntries.add(new BarEntry(3, new float[]{40, 40}));
        activeEntries.add(new BarEntry(4, new float[]{50, 50}));
        activeEntries.add(new BarEntry(5, new float[]{60, 60}));
        activeEntries.add(new BarEntry(6, new float[]{70, 70}));
        activeEntries.add(new BarEntry(7, new float[]{80, 80}));
        activeEntries.add(new BarEntry(8, new float[]{70, 70}));
        activeEntries.add(new BarEntry(9, new float[]{60, 60}));
        activeEntries.add(new BarEntry(10, new float[]{50, 50}));
        activeEntries.add(new BarEntry(11, new float[]{40, 40}));

        String[] activeBarLabels = new String[]{"登录", "完成工作"};
        mActiveBarChart.showChart(monthLabels, activeEntries, barColors, activeBarLabels);

    }

}
