package com.casic.dcms.ui;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

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

import com.casic.dcms.R;
import com.casic.dcms.adapter.AnalysisRecycleAdapter;
import com.casic.dcms.base.BaseActivity;
import com.casic.dcms.utils.ColorHelper;
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.qmuiteam.qmui.widget.QMUITopBarLayout;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author : Pengxh
 * @time : 2021/4/15 16:03
 * @email : 290677893@qq.com
 **/
public class DataAnalysisActivity extends BaseActivity implements View.OnClickListener {

    private static final String TAG = "DataAnalysisActivity";
    private Context context = this;

    @BindView(R.id.dataTopLayout)
    QMUITopBarLayout dataTopLayout;
    @BindView(R.id.startDateView)
    TextView startDateView;
    @BindView(R.id.selectStartDateView)
    ImageView selectStartDateView;
    @BindView(R.id.endDateView)
    TextView endDateView;
    @BindView(R.id.selectEndDateView)
    ImageView selectEndDateView;
    @BindView(R.id.analysisRecyclerView)
    RecyclerView analysisRecyclerView;

    @Override
    public int initLayoutView() {
        return R.layout.activity_case_analysis;
    }

    @Override
    protected void setupTopBarLayout() {
        dataTopLayout.setTitle("统计分析").setTextColor(ContextCompat.getColor(this, R.color.white));
        dataTopLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.mainThemeColor));
        dataTopLayout.addLeftImageButton(R.drawable.ic_left_white, 1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void initData() {
        AnalysisRecycleAdapter adapter = new AnalysisRecycleAdapter(this);
        analysisRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        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:
                        ToastHelper.showToast("趋势分析", ToastHelper.INFO);
                        break;
                    default:
                        break;
                }
//                startActivity(intent);
            }
        });
    }

    @Override
    public void initEvent() {

    }

    @OnClick({R.id.selectStartDateView, R.id.selectEndDateView})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.selectStartDateView:
                new TimePickerDialog.Builder().setThemeColor(ColorHelper.getResourcesColor(this, R.color.mainThemeColor))
                        .setTitleStringId("请选择起始时间")
                        .setWheelItemTextSize(16)
                        .setCyclic(false)
                        .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS)
                        .setMaxMillseconds(System.currentTimeMillis())
                        .setType(Type.YEAR_MONTH_DAY)
                        .setCallBack((timePickerView, millSeconds) -> {
                            String date = TimeOrDateUtil.rTimestampToDate(millSeconds);

                            startDateView.setText(date);
                            SaveKeyValues.putValue("begTime", date);
                        }).build().show(getSupportFragmentManager(), "year_month_day");
                break;
            case R.id.selectEndDateView:
                new TimePickerDialog.Builder().setThemeColor(ColorHelper.getResourcesColor(this, R.color.mainThemeColor))
                        .setTitleStringId("请选择结束时间")
                        .setWheelItemTextSize(16)
                        .setCyclic(false)
                        .setMinMillseconds(System.currentTimeMillis() - Constant.FIVE_YEARS)
                        .setMaxMillseconds(System.currentTimeMillis())
                        .setType(Type.YEAR_MONTH_DAY)
                        .setCallBack((timePickerView, millSeconds) -> {
                            String date = TimeOrDateUtil.rTimestampToDate(millSeconds);

                            endDateView.setText(date);
                            SaveKeyValues.putValue("endTime", date);
                        }).build().show(getSupportFragmentManager(), "year_month_day");
                break;
            default:
                break;
        }
    }
}
