package com.applemand.zmanim.nav

import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.applemand.zmanim.feature.calendar.CalendarScreen
import com.applemand.zmanim.feature.dafyomi.DafYomiDetailScreen
import com.applemand.zmanim.feature.ics.IcsExportScreen
import com.applemand.zmanim.feature.locationpicker.LocationPickerScreen
import com.applemand.zmanim.feature.settings.SettingsScreen
import kotlinx.serialization.Serializable

@Serializable object CalendarRoute
@Serializable object SettingsRoute
@Serializable object LocationPickerRoute
@Serializable object DafYomiRoute
@Serializable object IcsExportRoute

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable
fun LuachNavHost(widthDp: Int) {
    val navController = rememberNavController()
    val wsc = WindowSizeClass.calculateFromSize(
        DpSize(widthDp.dp, 900.dp),
    )

    NavHost(
        navController = navController,
        startDestination = CalendarRoute,
    ) {
        composable<CalendarRoute> {
            CalendarScreen(
                windowSizeClass = wsc,
                widthDp = widthDp,
                onOpenSettings = { navController.navigate(SettingsRoute) },
                onOpenLocationPicker = { navController.navigate(LocationPickerRoute) },
                onOpenDafYomi = { navController.navigate(DafYomiRoute) },
                onOpenIcsExport = { navController.navigate(IcsExportRoute) },
            )
        }
        composable<SettingsRoute> {
            SettingsScreen(
                onBack = { navController.popBackStack() },
                onPickLocation = { navController.navigate(LocationPickerRoute) },
            )
        }
        composable<LocationPickerRoute> {
            LocationPickerScreen(onDone = { navController.popBackStack() })
        }
        composable<DafYomiRoute> {
            DafYomiDetailScreen(onBack = { navController.popBackStack() })
        }
        composable<IcsExportRoute> {
            IcsExportScreen(onBack = { navController.popBackStack() })
        }
    }
}
