package com.jihe.punchnet.screen

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.jihe.punchnet.data.RouteViewModel
import com.jihe.punchnet.data.ServiceViewModel

sealed class Screen(val route: String) {
    object MainScreen: Screen("main");
    object RouteScreen: Screen("routes")
    object ProfileScreen: Screen("profile")
}

val bottomNavItems = listOf(
    Screen.MainScreen,
    Screen.RouteScreen,
    Screen.ProfileScreen,
)

@Composable
fun MainApp(
    serviceViewModel: ServiceViewModel = viewModel(),
    routeModel: RouteViewModel = viewModel(),
    navController: NavHostController,
) {

    Scaffold(
        bottomBar = {
            AppBottomNavigation(navController = navController)
        }
    ){ paddingValues ->
        /*
        Image(
            painter = painterResource(R.drawable.punchnet_log),
            contentDescription = null,
            modifier = Modifier.padding(paddingValues).size(200.dp)
        )
         */
        AppNavHost2(serviceViewModel, routeModel, navController, paddingValues)
    }
}

@Composable
fun CustomHeaderScreen(
    text: String,
    onBack: @Composable (() -> Unit)? = null,
    onMenu: @Composable (() -> Unit)? = null,
    body: @Composable () -> Unit,
) {
    Column(
        modifier = Modifier.fillMaxWidth(),
    ) {
        Box (
            modifier = Modifier
                .fillMaxWidth()
                .height(56.dp)
                .background(MaterialTheme.colorScheme.background),
            //.padding(horizontal = 16.dp),
            contentAlignment = Alignment.CenterStart
        ) {
            Row (
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.SpaceBetween,
                modifier = Modifier.fillMaxWidth()
            ) {

                Box(
                    modifier = Modifier.fillMaxHeight()
                        .padding(horizontal = 8.dp)
                        .width(35.dp)
                ) {
                    if (onBack != null) {
                        onBack()
                    }
                }


                Text(
                    text,
                    // color = MaterialTheme.colorScheme.onPrimary,
                    style = MaterialTheme.typography.titleLarge,
                )

                Box(
                    modifier = Modifier.fillMaxHeight()
                        .padding(horizontal = 8.dp)
                        .width(35.dp)
                ) {
                    if (onMenu != null) {
                        onMenu()
                    }
                }

            }
        }

        Box(modifier = Modifier.fillMaxSize()) {
            body()
        }
    }
}
