package xyz.pixelatedw.recipe.data import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update class RecipesView : ViewModel() { private val _activeRecipe = MutableStateFlow( null ) val activeRecipe = _activeRecipe.asStateFlow() private val _recipes = MutableStateFlow>( arrayListOf() ) val recipes = _recipes.asStateFlow() private val _search = MutableStateFlow(null) val search = _search.asStateFlow() private val _keepScreenOn = MutableStateFlow(false) val keepScreenOn = _keepScreenOn.asStateFlow() fun setKeepScreenOn(flag: Boolean) { _keepScreenOn.update { flag } } fun setRecipes(recipes: List) { _recipes.update { recipes } } fun removeRecipe(recipe: RecipeWithTags) { _recipes.value = _recipes.value.toMutableList().apply { remove(recipe) }.toList() } fun setSearch(search: String) { _search.update { search } } fun setActive(recipe: RecipeWithTags) { _activeRecipe.update { recipe } } }