package com.casic.dcms.ui;

import android.content.Context;
import android.view.View;

import androidx.core.content.ContextCompat;

import com.casic.dcms.R;
import com.casic.dcms.base.AndroidxBaseActivity;
import com.casic.dcms.databinding.ActivityTrendAnalysisBinding;
import com.casic.dcms.utils.Constant;
import com.casic.dcms.utils.TimeOrDateUtil;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;

import java.util.Calendar;

public class TrendAnalysisActivity extends AndroidxBaseActivity<ActivityTrendAnalysisBinding> {

    private final Context context = TrendAnalysisActivity.this;

    @Override
    protected void setupTopBarLayout() {
        viewBinding.titleBarLayout.titleView.setText("趋势分析");
        viewBinding.titleBarLayout.leftBackView.setOnClickListener(v -> finish());
    }

    @Override
    protected void initData() {
        //默认显示当前月的分析数据
        viewBinding.titleBarLayout.dateView.setText(TimeOrDateUtil.timestampToYearMonth(System.currentTimeMillis()));
        viewBinding.wholeCircleProgressBar.setCurrentValue(80);
        //初始化折线图
        Calendar calendar = Calendar.getInstance();
        int maximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    @Override
    protected void initEvent() {
        viewBinding.titleBarLayout.rightImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new TimePickerDialog.Builder()
                        .setThemeColor(ContextCompat.getColor(context, R.color.mainThemeColor))
                        .setTitleStringId("选择日期")
                        .setWheelItemTextSize(16)
                        .setCyclic(false)
                        .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS)
                        .setMaxMillseconds(System.currentTimeMillis())
                        .setType(Type.YEAR_MONTH)
                        .setCallBack(new OnDateSetListener() {
                            @Override
                            public void onDateSet(TimePickerDialog timePickerView, long millSeconds) {
                                String date = TimeOrDateUtil.timestampToYearMonth(millSeconds);
                                viewBinding.titleBarLayout.dateView.setText(date);
                            }
                        }).build().show(getSupportFragmentManager(), "year_month");
            }
        });
    }
}
