MutableState (Insert, Update, Remove)

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

class TodoViewModel: ViewModel() {
    var todos: List<TodoItem> by mutableStateOf(listOf())

    /*
ADD DEFAULT
 var todos by mutableStateOf(listOf(
        TodoItem()
    ))
        private set   
   */

    fun addItem(todo: TodoItem) {
        todos = todos + todo
    }

    fun removeItem(todo: TodoItem) {
        todos = todos - todo
    }

    fun changeCompletionStatus(index: Int) {
        editItem(index) {
            it.copy(done = !it.done)
        }
    }

    fun changeDescription(index: Int, newDescription: String) {
        editItem(index) { it.copy(text = newDescription) }
    }

    fun editItem2Way(item: TodoItem) {
        var currentEditPosition by mutableStateOf(-1)
        currentEditPosition = todos.indexOfFirst { item.id == it.id }
        println(currentEditPosition)

        todos = todos.toMutableList().also {
            it[currentEditPosition] = TodoItem(text = item.text, done = item.done)
        }
    }

    private fun editItem(index: Int, editAction: (oldItem: TodoItem) -> TodoItem) {
        todos = todos.toMutableList().apply {
            val oldItem = this[index]
            this[index] = editAction(oldItem)
        }
    }
}
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Check
import androidx.compose.ui.graphics.vector.ImageVector
import java.util.*

data class TodoItem (
    val id: UUID = UUID.randomUUID(),
    val text: String,
    val done: Boolean
) {
    val icon: ImageVector = if (done) Icons.Default.Check else Icons.Default.AccountBox
}
LazyColumn {
            itemsIndexed(viewModel.todos) { index, item ->

            }
        }