package com.convenient.android.lib.ui.sample.ad.page

import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.convenient.android.lib.ui.sample.ad.viewmodel.AdConfigViewModel
import com.convenient.android.lib.ui.theme.SampleTheme

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/9/5
 * description:
 */

object AdRouteConfig {

    const val AD_ROUTE_HOME = "ad_home"

    const val AD_ROUTE_BANNER = "ad_banner"

    const val AD_ROUTE_NATIVE = "ad_native"

    const val AD_ROUTE_INTERSTITIAL = "ad_interstitial"

    const val AD_ROUTE_REWARD_VIDEO = "ad_reward_video"

    const val AD_APP_OPEN = "ad_app_open"
}


@Composable
fun AdMainPage() {
    val viewModel: AdConfigViewModel = viewModel()
    val navHostController = rememberNavController()
    NavHost(navHostController = navHostController, viewModel = viewModel)
}

@Composable
fun NavHost(navHostController: NavHostController, viewModel: AdConfigViewModel) {
    androidx.navigation.compose.NavHost(
        modifier = Modifier.padding(all = 8.dp),
        navController = navHostController, startDestination = AdRouteConfig.AD_ROUTE_HOME
    ) {
        composable(AdRouteConfig.AD_ROUTE_HOME) {
            AdHomePage(viewModel = viewModel,navHostController)
        }

        composable(AdRouteConfig.AD_ROUTE_BANNER){
            AdBannerPage()
        }
        composable(AdRouteConfig.AD_ROUTE_NATIVE){
            AdNativePage()
        }
        composable(AdRouteConfig.AD_ROUTE_REWARD_VIDEO){
            AdRewardVideoPage()
        }
        composable(AdRouteConfig.AD_ROUTE_INTERSTITIAL){
            AdInterstitialPage()
        }
        composable(AdRouteConfig.AD_APP_OPEN){
            AdAppOpenPage()
        }
    }
}


@Preview
@Composable
fun AdMainPagePreview() {
    SampleTheme {
        AdMainPage()
    }
}

