package de.tsschulz.tt_tagebuch.app

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import de.tsschulz.tt_tagebuch.app.ui.AppRoot
import de.tsschulz.tt_tagebuch.app.ui.TtTagebuchTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val context = LocalContext.current
            val dependencies = remember {
                try {
                    AppDependencies(context.applicationContext)
                } catch (t: Throwable) {
                    android.util.Log.e("MainActivity", "Failed to initialize AppDependencies", t)
                    throw t
                }
            }
            TtTagebuchTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background,
                ) {
                    AppRoot(dependencies)
                }
            }
        }
    }
}
