package com.example import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.animation.* import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.rememberScrollState import androidx.compose.material.icons.filled.Build import androidx.compose.material.icons.filled.LockOpen import androidx.compose.material.icons.filled.Star import androidx.compose.material.icons.filled.SupervisedUserCircle import androidx.compose.material.icons.filled.AccountBalance import androidx.compose.material.icons.filled.Public import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel import com.example.ui.PortalRole import com.example.ui.PortalViewModel import com.example.ui.screens.* import com.example.ui.theme.BrandGold import com.example.ui.theme.DarkGreyGlass import com.example.ui.theme.DarkGreyGlassElevated import com.example.ui.theme.CyanAccent import com.example.ui.theme.CoralRed import com.example.ui.theme.TextPrimary import com.example.ui.theme.TextSecondary import com.example.ui.theme.MyApplicationTheme import com.example.firebase.FirebaseAuthService class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) FirebaseAuthService.init(applicationContext) enableEdgeToEdge() setContent { MyApplicationTheme { val portalViewModel: PortalViewModel = viewModel() MainPortalLayout(viewModel = portalViewModel) } } } } @OptIn(ExperimentalMaterial3Api::class) @Composable fun MainPortalLayout(viewModel: PortalViewModel) { val userWallet by viewModel.currentUserWallet.collectAsStateWithLifecycle() val allUserWallets by viewModel.allUserWallets.collectAsStateWithLifecycle() val models by viewModel.models.collectAsStateWithLifecycle() val bookings by viewModel.bookings.collectAsStateWithLifecycle() val transactionLogs by viewModel.transactionLogs.collectAsStateWithLifecycle() val loggedInModel by viewModel.loggedInModelFlow.collectAsStateWithLifecycle() var showGateCheck by remember { mutableStateOf(false) } // Authentication navigation flows var userAuthMode by remember { mutableStateOf("login") } // "login", "register" var modelAuthMode by remember { mutableStateOf("login") } // "login", "register" var adminIsAuthenticated by remember { mutableStateOf(false) } Scaffold( topBar = { Column { // Main Role Controller bar representing gorgeous multi-system toggle in a single Android showcase app Surface( color = DarkGreyGlass, modifier = Modifier.windowInsetsPadding(WindowInsets.statusBars) ) { Row( modifier = Modifier .fillMaxWidth() .horizontalScroll(rememberScrollState()) .padding(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically ) { // User App button RoleGateButton( title = "User App", isSelected = viewModel.currentRole == PortalRole.USER_PORTAL, icon = Icons.Default.LockOpen, badgeColor = BrandGold, onClick = { viewModel.setRole(PortalRole.USER_PORTAL) }, modifier = Modifier.width(115.dp).testTag("role_btn_user") ) // Model App button RoleGateButton( title = "Model App", isSelected = viewModel.currentRole == PortalRole.MODEL_PORTAL, icon = Icons.Default.SupervisedUserCircle, badgeColor = CyanAccent, onClick = { viewModel.setRole(PortalRole.MODEL_PORTAL) }, modifier = Modifier.width(115.dp).testTag("role_btn_model") ) // Cash Agent button RoleGateButton( title = "Cash Agent", isSelected = viewModel.currentRole == PortalRole.CASH_AGENT_PANEL, icon = Icons.Default.AccountBalance, badgeColor = BrandGold, onClick = { viewModel.setRole(PortalRole.CASH_AGENT_PANEL) }, modifier = Modifier.width(115.dp).testTag("role_btn_cash_agent") ) // Admin Panel button RoleGateButton( title = "Admin Portal", isSelected = viewModel.currentRole == PortalRole.ADMIN_PANEL, icon = Icons.Default.Build, badgeColor = CoralRed, onClick = { viewModel.setRole(PortalRole.ADMIN_PANEL) }, modifier = Modifier.width(115.dp).testTag("role_btn_admin") ) } } HorizontalDivider(color = DarkGreyGlassElevated) } }, containerColor = MaterialTheme.colorScheme.background ) { innerPadding -> Surface( modifier = Modifier .fillMaxSize() .padding(innerPadding), color = MaterialTheme.colorScheme.background ) { AnimatedContent( targetState = viewModel.currentRole, transitionSpec = { fadeIn() togetherWith fadeOut() }, label = "roleChange" ) { activeRole -> when (activeRole) { PortalRole.USER_PORTAL -> { if (!viewModel.isUserLoggedIn) { if (userAuthMode == "login") { UserLoginScreen( viewModel = viewModel, onNavigateRegister = { userAuthMode = "register" } ) } else { UserRegisterScreen( viewModel = viewModel, onNavigateLogin = { userAuthMode = "login" } ) } } else { userWallet?.let { wallet -> UserPortalView( viewModel = viewModel, userWallet = wallet, models = models, bookings = bookings, logs = transactionLogs ) } ?: Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { CircularProgressIndicator(color = BrandGold) } } } PortalRole.MODEL_PORTAL -> { if (loggedInModel == null) { if (modelAuthMode == "login") { ModelLoginScreen( viewModel = viewModel, onNavigateRegister = { modelAuthMode = "register" } ) } else { ModelRegisterScreen( viewModel = viewModel, onNavigateLogin = { modelAuthMode = "login" } ) } } else { loggedInModel?.let { mProfile -> ModelPortalView( viewModel = viewModel, modelProfile = mProfile, bookings = bookings, logs = transactionLogs ) } ?: Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { CircularProgressIndicator(color = BrandGold) } } } PortalRole.CASH_AGENT_PANEL -> { userWallet?.let { wallet -> val requests by viewModel.cashDepositRequests.collectAsStateWithLifecycle() CashAgentPortalView( viewModel = viewModel, userWallet = wallet, allDepositRequests = requests ) } ?: Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { CircularProgressIndicator(color = BrandGold) } } PortalRole.ADMIN_PANEL -> { if (!adminIsAuthenticated) { AdminLoginScreen( onAdminLoginSuccess = { adminIsAuthenticated = true } ) } else { AdminPortalView( viewModel = viewModel, userWallets = allUserWallets, models = models, bookings = bookings, logs = transactionLogs ) } } } } } } } @Composable fun RoleGateButton( title: String, isSelected: Boolean, icon: androidx.compose.ui.graphics.vector.ImageVector, badgeColor: Color, onClick: () -> Unit, modifier: Modifier = Modifier ) { Surface( onClick = onClick, shape = RoundedCornerShape(8.dp), color = if (isSelected) badgeColor.copy(alpha = 0.12f) else Color.Transparent, border = if (isSelected) BorderStroke(1.2.dp, badgeColor) else null, modifier = modifier ) { Column( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(vertical = 6.dp) ) { Icon( imageVector = icon, contentDescription = title, tint = if (isSelected) badgeColor else TextSecondary, modifier = Modifier.size(18.dp) ) Spacer(modifier = Modifier.height(2.dp)) Text( text = title, fontSize = 11.sp, fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal, color = if (isSelected) TextPrimary else TextSecondary ) } } }