package com.jihe.punchnet.data

import android.app.Application
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

object ButtonRepository {
    private val _buttonState: MutableStateFlow<ButtonState> = MutableStateFlow(ButtonState.ButtonStopped)
    val buttonState: StateFlow<ButtonState> = _buttonState

    fun updateState(state: ButtonState) {
        _buttonState.value = state
    }
}

sealed class ButtonState(val text: String, val enabled: Boolean) {
    object ButtonStarted: ButtonState("停止", true)
    object ButtonStarting: ButtonState("启动中", false)
    object ButtonStopped: ButtonState("启动", true)
    object ButtonStopping: ButtonState("停止中", false)
}

class ButtonViewModel(): ViewModel() {
    val buttonState = ButtonRepository.buttonState

    fun updateState(state: ButtonState) {
        ButtonRepository.updateState(state)
    }
}