package com.pixelized.biblib.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import com.pixelized.biblib.ui.screen.launch.LauncherViewModel
import com.pixelized.biblib.ui.theme.BibLibTheme
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class MainActivity : ComponentActivity() {

    private val launcherViewModel: LauncherViewModel by viewModels()

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

        // Disable system inset consuming.
        WindowCompat.setDecorFitsSystemWindows(window, false)

        // splashscreen management
        installSplashScreen().apply {
            setKeepOnScreenCondition {
                launcherViewModel.isLoadingDone.not()
            }
        }

        // Compose
        setContent {
            BibLibActivityTheme {
                MainContent(
                    launcherViewModel = launcherViewModel
                )
            }
        }
    }

    @Composable
    private fun BibLibActivityTheme(
        content: @Composable () -> Unit,
    ) {
        BibLibTheme {
            Surface(
                color = MaterialTheme.colors.surface,
                content = content,
            )
        }
    }
}