package de.krisenvorrat.app

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import de.krisenvorrat.app.domain.usecase.SeedDatabaseUseCase
import de.krisenvorrat.app.ui.MainScreen
import de.krisenvorrat.app.ui.theme.KrisenvorratTheme
import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

    @Inject internal lateinit var seedDatabaseUseCase: SeedDatabaseUseCase

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycleScope.launch { seedDatabaseUseCase() }
        enableEdgeToEdge()
        setContent {
            KrisenvorratTheme {
                MainScreen()
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    KrisenvorratTheme {
        Text(
            text = "Krisenvorrat",
            style = MaterialTheme.typography.headlineLarge
        )
    }
}
