package com.example.elva.ui.contacts

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

@HiltViewModel
class ContactsViewModel @Inject constructor() : ViewModel() {

    private val _state = MutableStateFlow(ContactsState())
    val state: StateFlow<ContactsState> = _state

    fun addContact(name: String, phone: String) {
        viewModelScope.launch {
            val updated = _state.value.contacts + "$name - $phone"
            _state.value = ContactsState(contacts = updated)
        }
    }
}

data class ContactsState(
    val contacts: List<String> = emptyList()
)
