package com.swoosh.microblog

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.compose.runtime.getValue
import androidx.navigation.compose.rememberNavController
import com.swoosh.microblog.data.AccountManager
import com.swoosh.microblog.ui.navigation.Routes
import com.swoosh.microblog.ui.navigation.SwooshNavGraph
import com.swoosh.microblog.ui.theme.SwooshTheme
import com.swoosh.microblog.ui.theme.ThemeViewModel

class MainActivity : ComponentActivity() {

    private val themeViewModel: ThemeViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        val accountManager = AccountManager(this)
        val startDestination = if (accountManager.isConfigured) Routes.FEED else Routes.SETUP

        setContent {
            val themeMode by themeViewModel.themeMode.collectAsStateWithLifecycle()

            SwooshTheme(themeMode = themeMode) {
                val navController = rememberNavController()
                SwooshNavGraph(
                    navController = navController,
                    startDestination = startDestination,
                    themeViewModel = themeViewModel
                )
            }
        }
    }
}
