package com.zaojiao.app.core.navx

import android.util.Log
import com.zaojiao.app.core.auth.utils.AuthState
import com.zaojiao.app.core.auth.utils.AuthUtils
import com.zaojiao.app.core.nav.LJGNavigator
import kotlin.concurrent.thread

object NavXUtils {
    fun navToRoute(
        route: String,
        needLogin: Boolean = true,
    ) {
        if (needLogin && AuthUtils.state == AuthState.OUT) {
            AuthUtils.requestLogin()
        } else {
            LJGNavigator.navigate(route)
        }
    }

    fun callWithLogin(callback: () -> Unit) {
        if (AuthUtils.state == AuthState.OUT) {
            thread {
                val result = AuthUtils.navToLogin().get()
                Log.e("NavXUtils", "callWithLogin: $result")
            }
        } else {
            callback()
        }

    }
}