package com.github.nullptroma.wallenc.ui.screens.settings

import androidx.lifecycle.viewModelScope
import com.github.nullptroma.wallenc.ui.ViewModelBase
import com.github.nullptroma.wallenc.ui.locale.AppLanguage
import com.github.nullptroma.wallenc.ui.locale.AppLocaleController
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SettingsViewModel @Inject constructor(
    private val appLocaleController: AppLocaleController,
) : ViewModelBase<SettingsScreenState>(SettingsScreenState()) {

    init {
        viewModelScope.launch {
            appLocaleController.language.collect { language ->
                updateState(state.value.copy(selectedLanguage = language))
            }
        }
    }

    fun setLanguage(language: AppLanguage) {
        viewModelScope.launch {
            appLocaleController.setLanguage(language)
        }
    }
}
