package com.tomhempel.unityudp

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.lifecycle.viewmodel.compose.viewModel
import com.tomhempel.unityudp.ui.HomeScreen
import com.tomhempel.unityudp.ui.MainViewModel
import com.tomhempel.unityudp.ui.ProjectScreen
import com.tomhempel.unityudp.ui.Screen
import com.tomhempel.unityudp.ui.theme.UnityUDPTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            UnityUDPTheme {
                val viewModel: MainViewModel = viewModel()
                val screen by viewModel.screen.collectAsState()

                when (val currentScreen = screen) {
                    is Screen.Home -> HomeScreen(viewModel = viewModel)
                    is Screen.Project -> ProjectScreen(
                        projectId = currentScreen.projectId,
                        viewModel = viewModel
                    )
                }
            }
        }
    }
}
