package com.pixelized.headache.ui.navigation.home

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
import androidx.navigation3.ui.NavDisplay
import com.pixelized.headache.ui.navigation.destination.monthSummaryDestinationEntry
import com.pixelized.headache.ui.navigation.destination.reportDestinationEntry
import com.pixelized.headache.ui.navigation.destination.yearSummaryDestinationEntry

val LocalHomeNavigator = staticCompositionLocalOf<HomeNavigator> {
    error("Local Navigation no yet ready")
}

@Composable
fun HomeNavDisplay(
    modifier: Modifier = Modifier,
    navigator: HomeNavigator,
) {
    CompositionLocalProvider(
        LocalHomeNavigator provides navigator,
    ) {
        NavDisplay(
            modifier = modifier,
            backStack = navigator.backStack,
            entryDecorators = listOf(
                rememberSaveableStateHolderNavEntryDecorator(),
                rememberViewModelStoreNavEntryDecorator(),
            ),
            onBack = {
                navigator.popBackstack()
            },
            entryProvider = entryProvider {
                monthSummaryDestinationEntry()
                yearSummaryDestinationEntry()
                reportDestinationEntry()
            }
        )
    }
}