package com.pixelized.desktop.lwa.ui.screen.splash

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.pixelized.desktop.lwa.BuildKonfig
import com.pixelized.desktop.lwa.ui.navigation.screen.LocalScreenController
import com.pixelized.desktop.lwa.ui.navigation.screen.destination.navigateToMainPage
import com.pixelized.desktop.lwa.ui.theme.lwa
import kotlinx.coroutines.delay
import lwacharactersheet.composeapp.generated.resources.Res
import lwacharactersheet.composeapp.generated.resources.app_name
import lwacharactersheet.composeapp.generated.resources.app_version
import org.jetbrains.compose.resources.stringResource

@Composable
fun SplashScreen() {
    val screen = LocalScreenController.current

    Surface {
        SplashContent(
            modifier = Modifier
                .fillMaxSize()
                .padding(all = 16.dp),
        )
    }

    LaunchedEffect(Unit) {
        delay(3000)
        screen.navigateToMainPage()
    }
}

@Composable
private fun SplashContent(
    modifier: Modifier = Modifier,
) {
    Box(
        modifier = modifier,
    ) {
        Text(
            modifier = Modifier.align(Alignment.Center),
            style = MaterialTheme.lwa.typography.system.h3,
            text = stringResource(Res.string.app_name)
        )
        Text(
            modifier = Modifier.align(Alignment.BottomEnd),
            style = MaterialTheme.lwa.typography.system.caption,
            text = stringResource(Res.string.app_version, BuildKonfig.version)
        )
    }
}