package com.example.chemical.ui.plan.unlock;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ActivityUtils;
import com.example.chemical.ChemicalApp;
import com.example.chemical.databinding.ActivityUnlockBinding;
import com.example.chemical.ui.common.BaseCountDownActivity;
import com.example.chemical.ui.plan.room.RoomTool;
import com.example.chemical.ui.plan.room.bean.input_add.InventoryItemBean;
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetDoorVo;
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetVo;
import com.example.chemical.ui.plan.room.dao.HxpCabinetDAO;
import com.example.chemical.ui.plan.room.dao.HxpDoorDAO;
import com.example.chemical.ui.plan.room.dao.HxpInventoryDAO;
import com.example.chemical.ui.verify.DoubleVerifyActivity;
import com.example.chemical.ui.verify.TwoVerificationActivity;
import com.example.chemical.utils.UiManager;
import com.rc.httpcore.bean.HxpChemicalVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class UnlockActivity extends BaseCountDownActivity<ActivityUnlockBinding> {
    private ActivityUnlockBinding binding;

    /**
     * 是否管控
     */
    private boolean isControl = false;

    @NonNull
    @Override
    protected ActivityUnlockBinding createViewBinding() {
        return binding = ActivityUnlockBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initViews(@Nullable Bundle savedInstanceState) {
        super.initViews(savedInstanceState);

        HxpCabinetDAO hxpCabinetDAO = RoomTool.getInstance().hxpCabinetDAO();
        HxpDoorDAO hxpDoorDAO = RoomTool.getInstance().hxpDoorDAO();
        HxpInventoryDAO hxpInventoryDAO = RoomTool.getInstance().hxpInventoryDAO();

        List<InventoryItemBean> inventoryItemBeanList = hxpInventoryDAO.getAll();
        for (int i = 0; i < inventoryItemBeanList.size(); i++) {
            InventoryItemBean inventoryItemBean = inventoryItemBeanList.get(i);
            HxpChemicalVo hxpChemicalVo = inventoryItemBean.getHxpChemicalVo();
            if (1 == hxpChemicalVo.getChemicalLevel()) {
                isControl = true;
                break;
            }
        }


        // 柜门信息理应需要从柜门表中遍历塞到柜子中  观察数据是否异常
        List<HxpCabinetVo> cabinetList = hxpCabinetDAO.getAll();
        List<HxpCabinetDoorVo> doorList = hxpDoorDAO.getAll();

        binding.cabinetTV.setText(cabinetList.size() + "个");
        binding.doorTV.setText(doorList.size() + "个");
        binding.unlockGV.setAdapter(new UnlockAdapter(this, cabinetList, doorList));

        binding.cancelBT.setOnClickListener(v -> finish());

        binding.validateBT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.startActivity(DoubleVerifyActivity.class);
//                /* 以下前同事代码*/
//                String verifyType = ChemicalApp.confs.getVerifyType();
//                Map<String, Object> map = new HashMap<>();
//                map.put("chemicalLevel", isControl ? 1 : 2);
//                map.put("mTag", 0);
//                if (verifyType.length() == 1) {
////                    map.put("dooId",)
//                    map.put("mVerTyps", Integer.valueOf(verifyType));
//                    UiManager.INSTANCE.switcher(UnlockActivity.this, map, TwoVerificationActivity.class);
//                } else {
//                    map.put("mVerTyps", 0);
//                }
            }
        });
    }
}
