package com.casic.dcms.ui;

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

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;

import com.casic.dcms.R;
import com.casic.dcms.adapter.AnalysisRecycleAdapter;
import com.casic.dcms.base.AndroidxBaseActivity;
import com.casic.dcms.databinding.ActivityCaseAnalysisBinding;
import com.casic.dcms.utils.Constant;
import com.casic.dcms.utils.SaveKeyValues;
import com.casic.dcms.utils.TimeOrDateUtil;
import com.casic.dcms.utils.ToastHelper;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;

/**
 * @author : Pengxh
 * @time : 2021/4/15 16:03
 * @email : 290677893@qq.com
 */
public class DataAnalysisActivity extends AndroidxBaseActivity<ActivityCaseAnalysisBinding> {

    private final Context context = DataAnalysisActivity.this;

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

    @Override
    protected void initData() {
        AnalysisRecycleAdapter adapter = new AnalysisRecycleAdapter(this);
        viewBinding.analysisRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        viewBinding.analysisRecyclerView.setAdapter(adapter);
        adapter.setOnGridItemClickListener(new AnalysisRecycleAdapter.OnGridItemClickListener() {
            @Override
            public void onClick(int position) {
                Intent intent = new Intent();
                switch (position) {
                    case 0:
                        intent.setClass(context, EventSourceActivity.class);
                        startActivity(intent);
                        break;
                    case 1:
                        ToastHelper.showToast("案卷状态", ToastHelper.INFO);
                        break;
                    case 2:
                        intent.setClass(context, HighEventListActivity.class);
                        startActivity(intent);
                        break;
                    case 3:
                        ToastHelper.showToast("街道统计", ToastHelper.INFO);
                        break;
                    case 4:
                        ToastHelper.showToast("处理统计", ToastHelper.INFO);
                        break;
                    case 5:
                        intent.setClass(context, TrendAnalysisActivity.class);
                        startActivity(intent);
                        break;
                }
            }
        });
    }

    @Override
    protected void initEvent() {
        viewBinding.selectStartDateView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new TimePickerDialog.Builder()
                        .setThemeColor(ContextCompat.getColor(DataAnalysisActivity.this, R.color.mainThemeColor))
                        .setTitleStringId("请选择起始时间")
                        .setWheelItemTextSize(16)
                        .setCyclic(false)
                        .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS)
                        .setMaxMillseconds(System.currentTimeMillis())
                        .setType(Type.YEAR_MONTH_DAY)
                        .setCallBack(new OnDateSetListener() {
                            @Override
                            public void onDateSet(TimePickerDialog timePickerView, long millSeconds) {
                                String date = TimeOrDateUtil.timestampToDate(millSeconds);
                                viewBinding.startDateView.setText(date);
                                SaveKeyValues.putValue("begTime", date);
                            }
                        }).build().show(getSupportFragmentManager(), "year_month_day");
            }
        });
        viewBinding.selectEndDateView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new TimePickerDialog.Builder()
                        .setThemeColor(ContextCompat.getColor(DataAnalysisActivity.this, R.color.mainThemeColor))
                        .setTitleStringId("请选择结束时间")
                        .setWheelItemTextSize(16)
                        .setCyclic(false)
                        .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS)
                        .setMaxMillseconds(System.currentTimeMillis())
                        .setType(Type.YEAR_MONTH_DAY)
                        .setCallBack(new OnDateSetListener() {
                            @Override
                            public void onDateSet(TimePickerDialog timePickerView, long millSeconds) {
                                String date = TimeOrDateUtil.timestampToDate(millSeconds);
                                viewBinding.endDateView.setText(date);
                                SaveKeyValues.putValue("endTime", date);
                            }
                        }).build().show(getSupportFragmentManager(), "year_month_day");
            }
        });
    }
}