package com.pixelized.headache.ui.page

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import com.pixelized.headache.ui.navigation.home.HomeNavigator
import com.pixelized.headache.ui.navigation.main.MainNavDisplay
import com.pixelized.headache.ui.navigation.main.MainNavigator

val LocalSnack = staticCompositionLocalOf<SnackbarHostState> {
    error("Local SnackHost no yet ready")
}

val LocalErrorSnack = staticCompositionLocalOf<SnackbarHostState> {
    error("Local SnackHost for Error no yet ready")
}

@Composable
fun MainPage(
    mainNavigator: MainNavigator,
    homeNavigator: HomeNavigator,
    snack: SnackbarHostState = remember { SnackbarHostState() },
    errorSnack: SnackbarHostState = remember { SnackbarHostState() },
) {
    CompositionLocalProvider(
        LocalSnack provides snack,
        LocalErrorSnack provides errorSnack,
    ) {
        Scaffold(
            contentWindowInsets = remember { WindowInsets(0, 0, 0, 0) },
            snackbarHost = {
                SnackbarHost(
                    hostState = snack,
                )
                SnackbarHost(
                    hostState = errorSnack,
                    snackbar = {
                        Snackbar(
                            containerColor = MaterialTheme.colorScheme.error,
                            contentColor = MaterialTheme.colorScheme.onError,
                            actionContentColor = MaterialTheme.colorScheme.onError,
                            snackbarData = it,
                        )
                    }
                )
            },
            content = { padding ->
                MainNavDisplay(
                    modifier = Modifier.padding(paddingValues = padding),
                    mainNavigator = mainNavigator,
                    homeNavigator = homeNavigator,
                )
            }
        )
    }
}