package com.example.iot_controlhost.ui.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.iot_controlhost.adapter.UvTaskAdapter;
import com.example.iot_controlhost.base.BaseDialog;
import com.example.iot_controlhost.databinding.DialogUvtaskBinding;
import com.example.iot_controlhost.databinding.ItemUvTaskBinding;
import com.example.iot_controlhost.model.MyTask;
import com.example.iot_controlhost.utils.MMKVUtil;
import com.example.iot_controlhost.utils.MyUtil;
import com.example.iot_controlhost.utils.global.AutoModelSet;
import com.example.iot_controlhost.utils.global.RxTag;
import com.example.iot_controlhost.utils.log.UserLog;
import com.xuexiang.rxutil2.rxbus.RxBusUtils;

import java.util.List;

/**
 * @Description 消毒计划设置
 * @Author DuanKaiji
 * @CreateTime 2024年03月07日 17:33
 */
public class UvTaskDialog extends BaseDialog<DialogUvtaskBinding> {
    public UvTaskDialog(@NonNull Context context, List<MyTask> data) {
        super(context);
        UvTaskAdapter uvTaskAdapter = new UvTaskAdapter(data, ItemUvTaskBinding.class, binding.tvTipNone);
        uvTaskAdapter.setContext(context);
        binding.rvUvTask.setLayoutManager(new LinearLayoutManager(context));
        binding.rvUvTask.setAdapter(uvTaskAdapter);
        binding.btnInsert.setOnClickListener(view -> new UvTaskInsertDialog(context, uvTaskAdapter).show());
        MyUtil.changeIcon(context, binding.ivAuto, AutoModelSet.isAutoDisinfect(), binding.llAutoSetParam,binding.llAutoSetParamNone);
        binding.ivAuto.setOnClickListener(v -> {
            //修改自动模式-消毒灯计划
            boolean oldValue = AutoModelSet.isAutoDisinfect();
            MMKVUtil.put(AutoModelSet.AUTO_DISINFECT, !oldValue);
            UserLog.operate("本机屏幕", (!oldValue ? "启用" : "停用") + "自动消毒计划");
            MyUtil.changeIcon(context, binding.ivAuto, AutoModelSet.isAutoDisinfect(), binding.llAutoSetParam,binding.llAutoSetParamNone);
            RxBusUtils.get().post(RxTag.UPDATE_AUTO, 3);
        });
    }
}
