package com.pixelized.desktop.lwa.ui.navigation.screen.destination.gamemaster

import androidx.compose.runtime.Stable
import androidx.lifecycle.SavedStateHandle
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.pixelized.desktop.lwa.ui.screen.admin.alteration.edit.GMAlterationEditScreen
import com.pixelized.desktop.lwa.utils.extention.ARG

@Stable
object GMAlterationEditDestination {
    private const val ROUTE = "GameMasterAlterationEdit"
    private const val ALTERATION_ID = "id"

    @Stable
    fun baseRoute() = "$ROUTE?${ALTERATION_ID.ARG}"

    @Stable
    fun navigationRoute(alterationId: String?) = "$ROUTE?$ALTERATION_ID=$alterationId"

    @Stable
    fun arguments() = listOf(
        navArgument(ALTERATION_ID) {
            nullable = true
            type = NavType.StringType
        },
    )

    @Stable
    data class Argument(
        val id: String?,
    ) {
        constructor(savedStateHandle: SavedStateHandle) : this(
            id = savedStateHandle.get<String>(ALTERATION_ID),
        )
    }
}

fun NavGraphBuilder.composableGameMasterAlterationEditPage() {
    composable(
        route = GMAlterationEditDestination.baseRoute(),
        arguments = GMAlterationEditDestination.arguments(),
    ) {
        GMAlterationEditScreen()
    }
}

fun NavHostController.navigateToGameMasterAlterationEditPage(
    alterationId: String?,
) {
    val route = GMAlterationEditDestination.navigationRoute(
        alterationId = alterationId,
    )
    navigate(route = route)
}