package com.mhss.app.mybrain.presentation.main import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.expandVertically import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.background import androidx.compose.foundation.clickable 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.Spacer 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.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Switch import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavHostController import com.mhss.app.mybrain.presentation.plans.UpgradePlanModal import com.mhss.app.mybrain.presentation.tgbot.BotSelectorTopBar import com.mhss.app.mybrain.presentation.tgbot.TgBot import com.mhss.app.mybrain.presentation.tgbot.dialogs.BotLogsViewerDialog import com.mhss.app.mybrain.presentation.tgbot.dialogs.BroadcastComposerDialog import com.mhss.app.mybrain.presentation.tgbot.dialogs.ForceJoinConfigDialog import com.mhss.app.mybrain.presentation.tgbot.dialogs.WelcomeConfigDialog import com.mhss.app.ui.Res import com.mhss.app.ui.components.common.MyBrainAppBar import com.mhss.app.ui.ic_bolt import com.mhss.app.ui.ic_check import com.mhss.app.ui.ic_edit import com.mhss.app.ui.ic_lock import com.mhss.app.ui.ic_send import com.mhss.app.ui.navigation.Screen import com.mhss.app.ui.theme.Blue import com.mhss.app.ui.theme.Green import com.mhss.app.ui.theme.Orange import com.mhss.app.ui.theme.PrimaryColor import com.mhss.app.ui.theme.Purple import com.mhss.app.ui.theme.Red import com.mhss.app.ui.theme.SecondaryColor import org.jetbrains.compose.resources.painterResource import org.koin.compose.viewmodel.koinViewModel @Composable fun SpacesScreen( navController: NavHostController, viewModel: MainViewModel = koinViewModel() ) { val bots by viewModel.botsList.collectAsStateWithLifecycle(emptyList()) val activeBot by viewModel.activeBot.collectAsStateWithLifecycle(null) var showWelcomeDialog by remember { mutableStateOf(false) } var showBroadcastDialog by remember { mutableStateOf(false) } var showForceJoinDialog by remember { mutableStateOf(false) } var showLogsDialog by remember { mutableStateOf(false) } var showPaywallModal by remember { mutableStateOf(false) } var paywallTitle by remember { mutableStateOf("Pro Feature") } var paywallDesc by remember { mutableStateOf("Upgrade your plan to unlock commercial capabilities.") } Scaffold( topBar = { MyBrainAppBar( title = "Bot Modules Hub", actions = { BotSelectorTopBar( bots = bots, activeBot = activeBot, onSelectBot = { viewModel.selectBot(it) }, onDeleteBot = { viewModel.deleteBot(it) }, onAddBotClick = { navController.navigate(Screen.AddBotScreen) }, modifier = Modifier.padding(end = 8.dp) ) } ) } ) { paddingValues -> LazyColumn( modifier = Modifier .fillMaxSize() .padding(paddingValues), verticalArrangement = Arrangement.spacedBy(14.dp) ) { // 1. Bot Status Header Card item { BotStatusHeader( bot = activeBot, onManageBot = { navController.navigate(Screen.AddBotScreen) } ) } // 2. Active Modules Summary Bar item { ActiveModulesBar(bot = activeBot) } // 3. Dynamic Management Cards item { AnimatedVisibility( visible = activeBot?.modulesConfig?.welcome?.isEnabled == true, enter = fadeIn() + expandVertically(), exit = fadeOut() + shrinkVertically() ) { activeBot?.modulesConfig?.welcome?.let { cfg -> WelcomeModuleControlCard( config = cfg, onEditClick = { showWelcomeDialog = true } ) } } } item { AnimatedVisibility( visible = activeBot?.modulesConfig?.broadcast?.isEnabled == true, enter = fadeIn() + expandVertically(), exit = fadeOut() + shrinkVertically() ) { activeBot?.modulesConfig?.broadcast?.let { cfg -> BroadcastModuleControlCard( config = cfg, userCount = activeBot?.userCount ?: 0, onNewBroadcast = { showBroadcastDialog = true } ) } } } item { AnimatedVisibility( visible = activeBot?.modulesConfig?.forceJoin?.isEnabled == true, enter = fadeIn() + expandVertically(), exit = fadeOut() + shrinkVertically() ) { activeBot?.modulesConfig?.forceJoin?.let { cfg -> ForceJoinModuleControlCard( config = cfg, onConfigClick = { showForceJoinDialog = true } ) } } } item { AnimatedVisibility( visible = activeBot?.modulesConfig?.logs?.isEnabled == true, enter = fadeIn() + expandVertically(), exit = fadeOut() + shrinkVertically() ) { activeBot?.modulesConfig?.logs?.entries?.let { logList -> LogsModuleControlCard( logs = logList, onViewLogs = { showLogsDialog = true } ) } } } // 4. CORE MODULES (FREE TIER) item { Text( text = "CORE MODULES (FREE)", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold), color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f), modifier = Modifier.padding(horizontal = 16.dp, vertical = 2.dp) ) } item { ModuleLibraryCard( title = "Welcome Module", subtitle = "Automated /start greeting with custom inline buttons and media", badge = "CORE", badgeColor = PrimaryColor, tag = "W", isEnabled = activeBot?.modulesConfig?.welcome?.isEnabled == true, onToggle = { isChecked -> activeBot?.let { viewModel.toggleModule(it.id, "welcome", isChecked) } } ) } item { ModuleLibraryCard( title = "Broadcast Module", subtitle = "Send announcements to all bot users with delivery tracking", badge = "MARKETING", badgeColor = Blue, tag = "B", isEnabled = activeBot?.modulesConfig?.broadcast?.isEnabled == true, onToggle = { isChecked -> activeBot?.let { viewModel.toggleModule(it.id, "broadcast", isChecked) } } ) } item { ModuleLibraryCard( title = "Force Join (FSub)", subtitle = "Require users to join your Telegram channel before bot access", badge = "GROWTH", badgeColor = Orange, tag = "F", isEnabled = activeBot?.modulesConfig?.forceJoin?.isEnabled == true, onToggle = { isChecked -> activeBot?.let { viewModel.toggleModule(it.id, "force_join", isChecked) } } ) } item { ModuleLibraryCard( title = "Logs and Audit Trail", subtitle = "Real-time command history, user triggers and Telegram API updates", badge = "DIAGNOSTICS", badgeColor = Purple, tag = "L", isEnabled = activeBot?.modulesConfig?.logs?.isEnabled == true, onToggle = { isChecked -> activeBot?.let { viewModel.toggleModule(it.id, "logs", isChecked) } } ) } // 5. PRO MODULES (PAID TIER) item { Spacer(Modifier.height(8.dp)) Row( modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Text( text = "PRO MODULES (PREMIUM)", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold), color = PrimaryColor ) Text( text = "UNLOCK ALL IN PRO", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold, fontSize = 10.sp), color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.clickable { paywallTitle = "Upgrade to Pro Plan" paywallDesc = "Unlock all commercial modules including AI auto-replies, UPI payment gateway, and multi-channel force join." showPaywallModal = true } ) } } item { ModuleLibraryCard( title = "AI Smart Auto-Responder", subtitle = "Context-aware conversational AI answers powered by Gemini and OpenAI", badge = "PRO", badgeColor = PrimaryColor, tag = "AI", isEnabled = false, onToggle = { paywallTitle = "Unlock AI Smart Auto-Responder" paywallDesc = "Enable conversational artificial intelligence to respond to your Telegram users 24/7 automatically." showPaywallModal = true } ) } item { ModuleLibraryCard( title = "UPI and Payment Gateway", subtitle = "Accept payments directly inside Telegram with instant order notifications", badge = "PRO", badgeColor = Green, tag = "PAY", isEnabled = false, onToggle = { paywallTitle = "Unlock Payment Gateway" paywallDesc = "Collect UPI, card, and digital payments directly inside your Telegram bot with instant webhook confirmation." showPaywallModal = true } ) } item { ModuleLibraryCard( title = "Vouchers and Redeem Codes", subtitle = "Generate single-use promo keys, redeemable discounts, and digital licenses", badge = "PRO", badgeColor = Orange, tag = "KEY", isEnabled = false, onToggle = { paywallTitle = "Unlock Redeem Codes System" paywallDesc = "Distribute single-use voucher codes to your bot users to redeem digital files, access, or subscription days." showPaywallModal = true } ) } item { ModuleLibraryCard( title = "Multi-Channel Force Join (5 Channels)", subtitle = "Require users to subscribe to up to 5 channels or groups simultaneously", badge = "PRO", badgeColor = Blue, tag = "MF", isEnabled = false, onToggle = { paywallTitle = "Unlock Multi-Channel Force Join" paywallDesc = "Boost your Telegram network growth by mandating membership across up to 5 channels or partner communities." showPaywallModal = true } ) } item { Spacer(Modifier.height(80.dp)) } } } // Dialogs if (showWelcomeDialog) { activeBot?.modulesConfig?.welcome?.let { cfg -> WelcomeConfigDialog( initialConfig = cfg, onDismiss = { showWelcomeDialog = false }, onSave = { updated -> activeBot?.let { bot -> viewModel.updateWelcomeConfig(bot.id, updated) } showWelcomeDialog = false } ) } } if (showBroadcastDialog) { activeBot?.let { bot -> BroadcastComposerDialog( botName = bot.name, targetAudienceCount = bot.userCount, onDismiss = { showBroadcastDialog = false }, onSendBroadcast = { msg -> viewModel.sendBroadcast(bot.id, msg) showBroadcastDialog = false } ) } } if (showForceJoinDialog) { activeBot?.modulesConfig?.forceJoin?.let { cfg -> ForceJoinConfigDialog( initialConfig = cfg, onDismiss = { showForceJoinDialog = false }, onSave = { updated -> activeBot?.let { bot -> viewModel.updateForceJoinConfig(bot.id, updated) } showForceJoinDialog = false } ) } } if (showLogsDialog) { activeBot?.let { bot -> BotLogsViewerDialog( logs = bot.modulesConfig.logs.entries, onDismiss = { showLogsDialog = false }, onClearLogs = { viewModel.clearLogs(bot.id) } ) } } if (showPaywallModal) { UpgradePlanModal( featureTitle = paywallTitle, featureDescription = paywallDesc, onDismiss = { showPaywallModal = false }, onUpgradeClick = { navController.navigate(Screen.PlansScreen) } ) } } @Composable private fun BotStatusHeader( bot: TgBot?, onManageBot: () -> Unit ) { Card( modifier = Modifier .fillMaxWidth() .padding(horizontal = 14.dp, vertical = 2.dp), shape = RoundedCornerShape(20.dp), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) ) { Row( modifier = Modifier .fillMaxWidth() .padding(14.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp) ) { Box( modifier = Modifier .size(44.dp) .clip(CircleShape) .background( brush = Brush.linearGradient(listOf(PrimaryColor, SecondaryColor)) ), contentAlignment = Alignment.Center ) { Text("BOT", fontSize = 12.sp, fontWeight = FontWeight.Bold, color = Color.White) } Column { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp) ) { Text( text = bot?.name ?: "No Bot Selected", style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold), color = MaterialTheme.colorScheme.onSurface ) Box( modifier = Modifier .size(8.dp) .clip(CircleShape) .background(if (bot?.isOnline == true) Green else Red) ) } Text( text = if (bot != null) "@${bot.username} • Token: ${bot.maskedToken}" else "Connect your bot token to unlock modules", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f) ) } } OutlinedButton( onClick = onManageBot, shape = RoundedCornerShape(10.dp), contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 10.dp, vertical = 4.dp) ) { Text("Manage", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold)) } } } } @Composable private fun ActiveModulesBar(bot: TgBot?) { val cfg = bot?.modulesConfig val activeList = buildList { if (cfg?.welcome?.isEnabled == true) add("Welcome" to PrimaryColor) if (cfg?.broadcast?.isEnabled == true) add("Broadcast" to Blue) if (cfg?.forceJoin?.isEnabled == true) add("Force Join" to Orange) if (cfg?.logs?.isEnabled == true) add("Logs" to Purple) } Column(modifier = Modifier.padding(horizontal = 14.dp)) { Text( text = "ACTIVE MODULES (${activeList.size} RUNNING)", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold), color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f), modifier = Modifier.padding(bottom = 6.dp) ) if (activeList.isEmpty()) { Text( text = "No modules active. Turn on modules from the library below.", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f), modifier = Modifier.padding(start = 2.dp) ) } else { LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) { items(activeList.size) { index -> val (title, color) = activeList[index] Surface( shape = RoundedCornerShape(8.dp), color = color.copy(alpha = 0.15f), border = androidx.compose.foundation.BorderStroke(1.dp, color.copy(alpha = 0.4f)) ) { Row( modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp) ) { Box( modifier = Modifier .size(6.dp) .clip(CircleShape) .background(color) ) Text( text = title, style = MaterialTheme.typography.labelSmall.copy( fontWeight = FontWeight.SemiBold, color = color ) ) } } } } } } } @Composable private fun WelcomeModuleControlCard( config: com.mhss.app.mybrain.presentation.tgbot.WelcomeModuleConfig, onEditClick: () -> Unit ) { Card( modifier = Modifier .fillMaxWidth() .padding(horizontal = 14.dp), shape = RoundedCornerShape(18.dp), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) ) { Column(modifier = Modifier.padding(14.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Surface( shape = CircleShape, color = PrimaryColor.copy(alpha = 0.15f), modifier = Modifier.size(24.dp) ) { Box(contentAlignment = Alignment.Center) { Text("W", fontSize = 11.sp, fontWeight = FontWeight.Bold, color = PrimaryColor) } } Text( text = "Welcome Greeting Manager", style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) } OutlinedButton( onClick = onEditClick, shape = RoundedCornerShape(8.dp), contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 8.dp, vertical = 2.dp) ) { Text("Edit Greeting", style = MaterialTheme.typography.labelSmall) } } Spacer(Modifier.height(8.dp)) Box( modifier = Modifier .fillMaxWidth() .clip(RoundedCornerShape(10.dp)) .background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.35f)) .padding(10.dp) ) { Text( text = "\"${config.messageText}\"", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurface, maxLines = 3, overflow = TextOverflow.Ellipsis ) } Spacer(Modifier.height(6.dp)) Text( text = "Buttons configured: \"${config.button1Text}\", \"${config.button2Text}\"", style = MaterialTheme.typography.labelSmall, color = PrimaryColor, fontSize = 11.sp ) } } } @Composable private fun BroadcastModuleControlCard( config: com.mhss.app.mybrain.presentation.tgbot.BroadcastModuleConfig, userCount: Int, onNewBroadcast: () -> Unit ) { Card( modifier = Modifier .fillMaxWidth() .padding(horizontal = 14.dp), shape = RoundedCornerShape(18.dp), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) ) { Column(modifier = Modifier.padding(14.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Surface( shape = CircleShape, color = Blue.copy(alpha = 0.15f), modifier = Modifier.size(24.dp) ) { Box(contentAlignment = Alignment.Center) { Text("B", fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Blue) } } Text( text = "Broadcast Manager", style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) } Button( onClick = onNewBroadcast, shape = RoundedCornerShape(8.dp), colors = ButtonDefaults.buttonColors(containerColor = Blue), contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 10.dp, vertical = 2.dp) ) { Text("New Broadcast", style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.Bold)) } } Spacer(Modifier.height(10.dp)) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { Text( text = "Total Campaigns: ${config.totalBroadcastsSent}", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f) ) Text( text = "Audience Reach: $userCount / 500 (Free)", style = MaterialTheme.typography.labelSmall, color = Blue, fontWeight = FontWeight.SemiBold ) } } } } @Composable private fun ForceJoinModuleControlCard( config: com.mhss.app.mybrain.presentation.tgbot.ForceJoinModuleConfig, onConfigClick: () -> Unit ) { Card( modifier = Modifier .fillMaxWidth() .padding(horizontal = 14.dp), shape = RoundedCornerShape(18.dp), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) ) { Column(modifier = Modifier.padding(14.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Surface( shape = CircleShape, color = Orange.copy(alpha = 0.15f), modifier = Modifier.size(24.dp) ) { Box(contentAlignment = Alignment.Center) { Text("F", fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Orange) } } Text( text = "Force Subscription (FSub)", style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) } OutlinedButton( onClick = onConfigClick, shape = RoundedCornerShape(8.dp), contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 8.dp, vertical = 2.dp) ) { Text("Configure", style = MaterialTheme.typography.labelSmall) } } Spacer(Modifier.height(8.dp)) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween ) { Text( text = "Channel: ${config.channelUsername}", style = MaterialTheme.typography.bodySmall.copy(fontWeight = FontWeight.Medium), color = Orange ) Text( text = "getChatMember Active", style = MaterialTheme.typography.labelSmall, color = Green ) } } } } @Composable private fun LogsModuleControlCard( logs: List, onViewLogs: () -> Unit ) { Card( modifier = Modifier .fillMaxWidth() .padding(horizontal = 14.dp), shape = RoundedCornerShape(18.dp), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp) ) { Column(modifier = Modifier.padding(14.dp)) { Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Surface( shape = CircleShape, color = Purple.copy(alpha = 0.15f), modifier = Modifier.size(24.dp) ) { Box(contentAlignment = Alignment.Center) { Text("L", fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Purple) } } Text( text = "Live Event Logs (${logs.size})", style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) } OutlinedButton( onClick = onViewLogs, shape = RoundedCornerShape(8.dp), contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 8.dp, vertical = 2.dp) ) { Text("Open Logs", style = MaterialTheme.typography.labelSmall) } } Spacer(Modifier.height(8.dp)) val latest = logs.firstOrNull() if (latest != null) { Text( text = "Latest: [${latest.level}] ${latest.title} - ${latest.details}", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f), maxLines = 1, overflow = TextOverflow.Ellipsis ) } } } } @Composable private fun ModuleLibraryCard( title: String, subtitle: String, badge: String, badgeColor: Color, tag: String, isEnabled: Boolean, onToggle: (Boolean) -> Unit ) { Card( modifier = Modifier .fillMaxWidth() .padding(horizontal = 14.dp), shape = RoundedCornerShape(16.dp), colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface), elevation = CardDefaults.cardElevation(defaultElevation = 1.dp) ) { Row( modifier = Modifier .fillMaxWidth() .padding(14.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween ) { Row( modifier = Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp) ) { Surface( shape = RoundedCornerShape(10.dp), color = badgeColor.copy(alpha = 0.15f), modifier = Modifier.size(38.dp) ) { Box(contentAlignment = Alignment.Center) { Text( text = tag, fontSize = 12.sp, fontWeight = FontWeight.Bold, color = badgeColor ) } } Column(modifier = Modifier.weight(1f)) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp) ) { Text( text = title, style = MaterialTheme.typography.titleSmall.copy(fontWeight = FontWeight.Bold) ) Surface( shape = RoundedCornerShape(4.dp), color = badgeColor.copy(alpha = 0.15f) ) { Text( text = badge, modifier = Modifier.padding(horizontal = 4.dp, vertical = 1.dp), style = MaterialTheme.typography.labelSmall.copy( fontWeight = FontWeight.Bold, fontSize = 9.sp, color = badgeColor ) ) } } Text( text = subtitle, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f), maxLines = 2, overflow = TextOverflow.Ellipsis ) } } Spacer(Modifier.width(8.dp)) Switch( checked = isEnabled, onCheckedChange = onToggle, colors = SwitchDefaults.colors( checkedThumbColor = Color.White, checkedTrackColor = badgeColor ) ) } } }