package com.example.livingai.pages.home

import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.livingai.domain.usecases.AppDataUseCases
import com.example.livingai.pages.navigation.Route
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class HomeViewModel(
    private val appDataUseCases: AppDataUseCases
): ViewModel() {
    private val _splashCondition = mutableStateOf(true)
    val splashCondition: State<Boolean> = _splashCondition

    private val _startDestination = mutableStateOf<Route>(Route.AppStartNavigation)
    val startDestination: State<Route> = _startDestination

    init {
        appDataUseCases.readAppEntry().onEach { shouldStartFromHomeScreen ->
//            if(shouldStartFromHomeScreen){
                _startDestination.value = Route.HomeNavigation
//            }else{
//                _startDestination.value = Route.AppStartNavigation
//            }
            delay(350) //Without this delay, the onBoarding screen will show for a momentum.
            _splashCondition.value = false
        }.launchIn(viewModelScope)
    }
}