package com.iscs.bozzys.ui.pages.vm

import androidx.lifecycle.viewModelScope
import com.iscs.bozzys.ui.common.VMBase
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

class VMReturnDevice : VMBase() {

    private val _state = MutableStateFlow(StateReturnDevice())

    val state = _state.asStateFlow()

    fun init() {

    }

    fun showExceptDialog(mac: String) {
        _state.value = _state.value.copy(showExceptDialog = true, exceptDeviceMac = mac)
    }

    fun hideExceptDialog() {
        _state.value = _state.value.copy(showExceptDialog = false)
    }

    fun reportExcept() {
        viewModelScope.launch {
            loading.emit(StateLoading(show = true, content = "异常上报中..."))
            delay(2000)
            loading.emit(StateLoading())
            toast.emit("上报成功")
        }
    }

}

/**
 * 当前页面状态
 *
 * @param showExceptDialog  是否显示异常上报Dialog
 */
data class StateReturnDevice(val showExceptDialog: Boolean = false, val exceptDeviceMac: String = "")