package com.navinfo.outdoor.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.lzy.okgo.model.HttpParams;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.activity.FragmentManagement;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseFragment;
import com.navinfo.outdoor.bean.HasSubmitBean;
import com.navinfo.outdoor.bean.TaskPrefectureBean;
import com.navinfo.outdoor.http.Callback;
import com.navinfo.outdoor.http.HttpInterface;
import com.navinfo.outdoor.http.OkGoBuilder;

/**
 * 记录-已提交
 */
public class HasSubmitFragment extends BaseFragment implements View.OnClickListener {


    private ConstraintLayout clPoi;
    private TextView auditProcess;
    private TextView auditThrough;
    private TextView auditNotThrough;
    private ConstraintLayout clCharging;
    private TextView tvCharging;
    private TextView chargingAuditProcess;
    private TextView chargingAuditThrough;
    private TextView chargingAuditNotThrough;
    private ConstraintLayout clRoad;
    private TextView tvRoad;
    private TextView roadAuditProcess;
    private TextView roadAuditThrough;
    private TextView roadAuditNotThrough;
    private ConstraintLayout clOther;
    private TextView otherAuditProcess;
    private TextView otherAuditThrough;
    private TextView otherAuditNotThrough;
    private ConstraintLayout clPoiVideo;
    private TextView tvPoiVideo;
    private TextView poiVideoAuditProcess;
    private TextView poiVideoAuditThrough;
    private TextView poiVideoAuditProcessauditNotThrough;
    private int hasPage;

    public static HasSubmitFragment newInstance(Bundle bundle) {
        HasSubmitFragment fragment = new HasSubmitFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_has_submit;
    }

    protected void initView() {
        super.initView();
        clPoi = (ConstraintLayout) findViewById(R.id.cl_poi);
        clPoi.setOnClickListener(this::onClick);
        auditProcess = (TextView) findViewById(R.id.audit_process);
        auditThrough = (TextView) findViewById(R.id.audit_through);
        auditNotThrough = (TextView) findViewById(R.id.audit_not_through);

        clRoad = (ConstraintLayout) findViewById(R.id.cl_road);
        clRoad.setOnClickListener(this::onClick);
        roadAuditProcess = (TextView) findViewById(R.id.road_audit_process);
        roadAuditThrough = (TextView) findViewById(R.id.road_audit_through);
        roadAuditNotThrough = (TextView) findViewById(R.id.road_audit_not_through);
        clCharging = (ConstraintLayout) findViewById(R.id.cl_charging);
        clCharging.setOnClickListener(this::onClick);
        chargingAuditProcess = (TextView) findViewById(R.id.charging_audit_process);
        chargingAuditThrough = (TextView) findViewById(R.id.charging_audit_through);
        chargingAuditNotThrough = (TextView) findViewById(R.id.charging_audit_not_through);

        clOther = (ConstraintLayout) findViewById(R.id.cl_other);
        clOther.setOnClickListener(this::onClick);
        otherAuditProcess = (TextView) findViewById(R.id.other_audit_process);
        otherAuditThrough = (TextView) findViewById(R.id.other_audit_through);
        otherAuditNotThrough = (TextView) findViewById(R.id.other_audit_not_through);

        clPoiVideo = (ConstraintLayout) findViewById(R.id.cl_poiVideo);
        clPoiVideo.setOnClickListener(this::onClick);
        tvPoiVideo = (TextView) findViewById(R.id.tv_poiVideo);
        poiVideoAuditProcess = (TextView) findViewById(R.id.poiVideo_audit_process);
        poiVideoAuditThrough = (TextView) findViewById(R.id.poiVideo_audit_through);
        poiVideoAuditProcessauditNotThrough = (TextView) findViewById(R.id.poiVideo_audit_processaudit_not_through);
        initPoiSubMitWork();//poi
        initPoiVideoSubMitWork();//poi录像
        initRoadSubMitWork();//道路录像
        initChaningSubMitWork();//充电站录像
        initOtherSubMitWork();//其他录像

    }

    private void initOtherSubMitWork() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("type", "5");
        httpParams.put("pageSize", "10");
        httpParams.put("pageNum", hasPage);
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.GET_COMMIT_LIST)
                .cls(HasSubmitBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<HasSubmitBean>() {
                    @Override
                    public void onSuccess(HasSubmitBean hasSubmitBean, int id) {
                        dismissLoadingDialog();
                        if (hasSubmitBean.getCode() == 200){
                            HasSubmitBean.BodyBean hasSubmitBeanBody = hasSubmitBean.getBody();
                            if (hasSubmitBeanBody!=null){
                                otherAuditProcess.setText(hasSubmitBeanBody.getAuditingCount()+"");
                                otherAuditThrough.setText(hasSubmitBeanBody.getPassCount()+"");
                                otherAuditNotThrough.setText(hasSubmitBeanBody.getNotPassCount()+"");
                                hasPage++;
                            }

                        }else {
                            Toast.makeText(getActivity(), hasSubmitBean.getMessage()+"", Toast.LENGTH_SHORT).show();
                        }

                        Log.d("TAG", "onSuccess: " + hasSubmitBean.getBody() + "");
                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Log.d("TAG", "onError: " + e.getMessage());
                        Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show();
                    }
                });
    }

    private void initChaningSubMitWork() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("type", "2");
        httpParams.put("pageSize", "10");
        httpParams.put("pageNum", "2");
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.GET_COMMIT_LIST)
                .cls(HasSubmitBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<HasSubmitBean>() {
                    @Override
                    public void onSuccess(HasSubmitBean hasSubmitBean, int id) {
                        dismissLoadingDialog();
                        if (hasSubmitBean.getCode() == 200){
                            HasSubmitBean.BodyBean hasSubmitBeanBody = hasSubmitBean.getBody();
                            if (hasSubmitBeanBody!=null){
                                chargingAuditProcess.setText(hasSubmitBeanBody.getAuditingCount()+"");
                                chargingAuditThrough.setText(hasSubmitBeanBody.getPassCount()+"");
                                chargingAuditNotThrough.setText(hasSubmitBeanBody.getNotPassCount()+"");
                            }
                        }else {
                            Toast.makeText(getActivity(), hasSubmitBean.getMessage()+"", Toast.LENGTH_SHORT).show();
                        }

                        Log.d("TAG", "onSuccess: " + hasSubmitBean.getBody() + "");
                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Log.d("TAG", "onError: " + e.getMessage());
                        Toast.makeText(getActivity(), e.getMessage()+"", Toast.LENGTH_SHORT).show();
                    }
                });
    }

    private void initRoadSubMitWork() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("type", "4");
        httpParams.put("pageSize", "10");
        httpParams.put("pageNum", hasPage);
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.GET_COMMIT_LIST)
                .cls(HasSubmitBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<HasSubmitBean>() {
                    @Override
                    public void onSuccess(HasSubmitBean hasSubmitBean, int id) {
                        dismissLoadingDialog();
                        if (hasSubmitBean.getCode() == 200){
                            HasSubmitBean.BodyBean hasSubmitBeanBody = hasSubmitBean.getBody();
                            if (hasSubmitBeanBody!=null){
                                roadAuditProcess.setText(hasSubmitBeanBody.getAuditingCount()+"");
                                roadAuditThrough.setText(hasSubmitBeanBody.getPassCount()+"");
                                roadAuditNotThrough.setText(hasSubmitBeanBody.getNotPassCount()+"");
                          hasPage++;
                            }
                        }else {
                            Toast.makeText(getActivity(), hasSubmitBean.getMessage(), Toast.LENGTH_SHORT).show();
                        }

                        Log.d("TAG", "onSuccess: " + hasSubmitBean.getBody() + "");
                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Log.d("TAG", "onError: " + e.getMessage());
                        Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show();
                    }
                });
    }

    private void initPoiVideoSubMitWork() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("type", "3");
        httpParams.put("pageSize", "10");
        httpParams.put("pageNum", hasPage);
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.GET_COMMIT_LIST)
                .cls(HasSubmitBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<HasSubmitBean>() {
                    @Override
                    public void onSuccess(HasSubmitBean hasSubmitBean, int id) {
                        dismissLoadingDialog();
                        if (hasSubmitBean.getCode() == 200){
                            HasSubmitBean.BodyBean hasSubmitBeanBody = hasSubmitBean.getBody();
                            if (hasSubmitBeanBody!=null){
                                poiVideoAuditProcess.setText(hasSubmitBeanBody.getAuditingCount()+"");
                                poiVideoAuditThrough.setText(hasSubmitBeanBody.getPassCount()+"");
                                poiVideoAuditProcessauditNotThrough.setText(hasSubmitBeanBody.getNotPassCount()+"");
                           hasPage++;
                            }
                        }else {
                            Toast.makeText(getActivity(), hasSubmitBean.getMessage()+"", Toast.LENGTH_SHORT).show();
                        }

                        Log.d("TAG", "onSuccess: " + hasSubmitBean.getBody() + "");
                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Log.d("TAG", "onError: " + e.getMessage());
                        Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show();
                    }
                });
    }

    private void initPoiSubMitWork() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("type", "1");
        httpParams.put("pageSize", "10");
        httpParams.put("pageNum", hasPage);
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.GET_COMMIT_LIST)
                .cls(HasSubmitBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<HasSubmitBean>() {
                    @Override
                    public void onSuccess(HasSubmitBean hasSubmitBean, int id) {
                        dismissLoadingDialog();
                        if (hasSubmitBean.getCode() == 200){
                            HasSubmitBean.BodyBean hasSubmitBeanBody = hasSubmitBean.getBody();
                            if (hasSubmitBeanBody!=null){
                                auditProcess.setText(hasSubmitBeanBody.getAuditingCount()+"");
                                auditThrough.setText(hasSubmitBeanBody.getPassCount()+"");
                                auditNotThrough.setText(hasSubmitBeanBody.getNotPassCount()+"");
                            hasPage++;
                                Log.d("TAG", "onSuccess: " + hasSubmitBean.getBody() + "");
                            }
                        }else {
                            Toast.makeText(getActivity(), hasSubmitBean.getMessage()+"", Toast.LENGTH_SHORT).show();
                        }


                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Log.d("TAG", "onError: " + e.getMessage());
                        Toast.makeText(getActivity(), "请求失败", Toast.LENGTH_SHORT).show();
                    }
                });
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cl_poi:
                Intent poiIntent = new Intent(getContext(), FragmentManagement.class);
                poiIntent.putExtra("tag", 31);
                poiIntent.putExtra("type", 1);
                startActivity(poiIntent);
                break;
            case R.id.cl_road:
                Intent roadIntent = new Intent(getContext(), FragmentManagement.class);
                roadIntent.putExtra("tag", 31);
                roadIntent.putExtra("type", 4);
                startActivity(roadIntent);
                break;
            case R.id.cl_charging:
                Intent chargingIntent = new Intent(getContext(), FragmentManagement.class);
                chargingIntent.putExtra("tag", 31);
                chargingIntent.putExtra("type", 2);
                startActivity(chargingIntent);
                break;
            case R.id.cl_other:
                Intent otherIntent = new Intent(getContext(), FragmentManagement.class);
                otherIntent.putExtra("tag", 31);
                otherIntent.putExtra("type", 5);
                startActivity(otherIntent);
                break;
            case R.id.cl_poiVideo:
                Intent poiVideoIntent = new Intent(getContext(), FragmentManagement.class);
                poiVideoIntent.putExtra("tag", 31);
                poiVideoIntent.putExtra("type", 3);
                startActivity(poiVideoIntent);
                break;
        }
    }
}