package com.wd.workoffice.ui.activity.mes.report;

import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkBaseActivity;
import com.wd.workoffice.ui.adapter.ReportBadAdapter;
import com.wd.workoffice.ui.adapter.ReportProBadAdapter;
import com.wd.workoffice.ui.adapter.ReportTopAdapter;

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

import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class MesReportActivity extends WorkBaseActivity {


    @BindView(R.id.tv_report)
    TextView tvReport;
    @BindView(R.id.tv_bad)
    TextView tvBad;
    @BindView(R.id.tb_title)
    Toolbar tbTitle;
    @BindView(R.id.rv_top)
    RecyclerView rvTop;
    @BindView(R.id.rv_pro_bad)
    RecyclerView rvProBad;
    @BindView(R.id.rv_bad)
    RecyclerView rvBad;
    @BindView(R.id.ll_report)
    LinearLayout llReport;
    @BindView(R.id.ll_bad)
    LinearLayout llBad;
    private ReportBadAdapter badAdapter;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        setSupportActionBar(tbTitle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        rvBad.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        rvProBad.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        rvTop.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
    }


    @Override
    protected void initData() {
        List<Object> badList = new ArrayList<>();
        badList.add(null);
        badList.add(null);
        badList.add(null);
        List<Object> topList = new ArrayList<>();
        topList.add(null);
        topList.add(null);
        topList.add(null);
        List<Object> proBadList = new ArrayList<>();
        proBadList.add(null);
        proBadList.add(null);
        proBadList.add(null);
        badAdapter = new ReportBadAdapter(R.layout.item_mes_report_bad, badList);
        ReportTopAdapter topAdapter = new ReportTopAdapter(R.layout.item_mes_report_top, badList);
        ReportProBadAdapter proBadAdapter = new ReportProBadAdapter(R.layout.item_mes_report_pro_bad, badList);
        badAdapter.bindToRecyclerView(rvBad);
        topAdapter.bindToRecyclerView(rvTop);
        proBadAdapter.bindToRecyclerView(rvProBad);
    }

//    private void getData() {
//        RtfUtils.getMesRtf().searchList("1", WorkUtils.convertMapToBody(param)).compose(Transformer.schedule()).subscribe(new WorkObserver<BaseMesBean>() {
//            @Override
//            public void doOnSubscribe(Disposable d) {
//            }
//
//            @Override
//            public void onFail(String errorMsg) {
//                hideLoading();
//                toast(errorMsg);
//            }
//
//            @Override
//            public void onSuccess(BaseMesBean data) {
//                hideLoading();
//                if (!data.isSuccess()) {
//                    toast(data.getMessage());
//                    return;
//                }
//                List<SearchBean.ListBean> getList = JSON.parseObject(data.getData().toString(), SearchBean.class).getList();
//                if (page == 1) {
//                    srlRefresh.finishRefresh();
//                    dataList.clear();
//                    dataList.addAll(getList);
//                    dataAdapter.notifyDataSetChanged();
//                    dataAdapter.loadMoreComplete();
//                } else {
//                    dataAdapter.loadMoreComplete();
//                    dataList.addAll(getList);
//                    dataAdapter.notifyDataSetChanged();
//                }
//                if (getList.size() == 0) {
//                    dataAdapter.loadMoreEnd();
//                } else {
//                    page++;
//                }
//            }
//        }); }


    @Override
    protected void initEvent() {
        badAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                startActivity(MesReportDetailActivity.class);
            }
        });
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_mes_report;
    }


    @OnClick({R.id.tv_report, R.id.tv_bad})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_report:
                changView(0);
                break;
            case R.id.tv_bad:
                changView(1);
                break;
        }
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void changView(int type) {
        if (type == 0) {
            llReport.setVisibility(View.VISIBLE);
            llBad.setVisibility(View.GONE);
            tvReport.setBackgroundResource(R.drawable.shape_report_choose);
            tvReport.setTextColor(Color.WHITE);
            tvBad.setBackgroundResource(R.drawable.shape_report);
            tvBad.setTextColor(Color.parseColor("#FF4A92DE"));
        } else {
            llReport.setVisibility(View.GONE);
            llBad.setVisibility(View.VISIBLE);
            tvBad.setBackgroundResource(R.drawable.shape_report_choose);
            tvBad.setTextColor(Color.WHITE);
            tvReport.setBackgroundResource(R.drawable.shape_report);
            tvReport.setTextColor(Color.parseColor("#FF4A92DE"));
        }
    }
}
