package com.isidroid.c23.ext

import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.navArgument
import com.isidroid.c23.ui.navigation.Content
import com.isidroid.c23.ui.navigation.Map
import com.isidroid.c23.ui.navigation.PrintJobs
import com.isidroid.c23.ui.navigation.RenderPreview

val String?.isEdgeToEdge
    get() = arrayOf(
        RenderPreview.route,
        Content.route,
        Map.route,
        PrintJobs.route
    ).any {
        this?.contains(it) == true
    }


@Composable
fun BasicNavHost(
    navController: NavHostController,
    startDestination: String,
    modifier: Modifier = Modifier,
    builder: NavGraphBuilder.() -> Unit
) {
    val screenTransitionDuration = 200
    NavHost(
        navController = navController,
        startDestination = startDestination,
        modifier = modifier,
        enterTransition = {
            fadeIn(tween(screenTransitionDuration))
        },
        exitTransition = {
            fadeOut(tween(screenTransitionDuration))
        },
        popEnterTransition = {
            fadeIn(tween(screenTransitionDuration))
        },
        popExitTransition = {
            fadeOut(tween(screenTransitionDuration))
        },
        builder = builder
    )
}

internal fun makeNavArgument(name: String, type: NavType<*>, nullable: Boolean = true, defaultValue: Any? = null) = navArgument(name){
    this.type = type
    this.nullable = nullable
    this.defaultValue = defaultValue
}