package com.jaytux.simd.frontend

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import com.jaytux.simd.frontend.theme.SimdTheme
import com.jaytux.simd.frontend.ui.DataState
import com.jaytux.simd.frontend.ui.ErrorSnackBar
import com.jaytux.simd.frontend.ui.topBar
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
@Preview
fun App() {
    SimdTheme {
        val scope = rememberCoroutineScope()
        val snackState = remember { SnackbarHostState() }
        val data = DataState(scope, {
            println(it)
            snackState.showSnackbar(it, duration = SnackbarDuration.Short)
        })

        Scaffold(
            topBar = { topBar(data) },
            snackbarHost = { SnackbarHost(snackState) { ErrorSnackBar(it) } }
        ) {
            Surface(Modifier.padding(top = it.calculateTopPadding())) {
                mainView(data)
            }
        }
    }
}