package com.unis.sxzcl.ui.company;

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.model.DepotModel;
import com.unis.model.bean.MultiDepotBean;
import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentCompanyStatsBinding;
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.company
 * 类名: CompanyStatsFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/12/9 10:00
 * 更新人:
 * 更新时间: 2020/12/9 10:00
 * 更新说明:
 * 版本号: 1.0
 */
public class CompanyStatsFragment extends BaseFragment<FragmentCompanyStatsBinding> {

    private MyPieChart mPieChartHouseStatus;
    private MyBarChart mBarChartFoodType;
    private MyPieChart mPieChartStorageStatus;

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

    @Override
    protected void init() {
        MultiDepotBean selectDepot = DepotModel.get().getSelectDepot();
        mBinding.bar.setTitle(selectDepot.depotName);
        mBinding.bar.setLeftClickListener(v -> onBack());

        mBinding.tvCompany.setText(selectDepot.depotName);
    }

    @Override
    protected void onFirstShow() {
        getHouseStatus();
        getFoodType();
        getStorageStatus();
    }


    private void getHouseStatus() {
        if (mPieChartHouseStatus == null)
            mPieChartHouseStatus = new MyPieChart(mBinding.pieHouseStatus);
        // 仓房状态
        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, "熏蒸"));
        mPieChartHouseStatus.showChart(pieEntries, "仓房状态");
    }

    private void getFoodType() {
        if (mBarChartFoodType == null)
            mBarChartFoodType = new MyBarChart(mBinding.barFoodType);

        // 粮食品种
        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));
        List<String> workTypeLabels = Arrays.asList("玉米", "小麦", "大豆", "稻谷");
        mBarChartFoodType.showChart(workTypeLabels, barEntries);
    }

    private void getStorageStatus() {
        if (mPieChartStorageStatus == null)
            mPieChartStorageStatus = new MyPieChart(mBinding.pieStorageStatus);
        // 储存状态
        List<PieEntry> pieEntries = new ArrayList<>();
        pieEntries.add(new PieEntry(200f, "空仓"));
        pieEntries.add(new PieEntry(290f, "满仓"));
        pieEntries.add(new PieEntry(240f, "半仓"));
        mPieChartStorageStatus.showChart(pieEntries, "储存状态");
    }
}
