package com.iscs.bozzys.ui.base

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel

class VMLoading : ViewModel() {

    // 处理ViewModel中显示的内容
    var state by mutableStateOf(StateLoading())
        private set

    /**
     * 显示loading
     */
    fun show(content: String = "", timeout: Int = -1) {
        state = state.copy(show = true, content = content)
    }

    /**
     * 显示loading
     */
    fun show(stateLoading: StateLoading) {
        state = stateLoading
    }

    /**
     * 隐藏
     */
    fun hide() {
        state = state.copy(show = false)
    }

}

/**
 * loading状态类
 *
 * @param show      是否显示loading
 * @param content   loading时提示的内容
 */
data class StateLoading(var show: Boolean = false, var content: Any = "", var timeout: Int = -1)