package com.craigvg.lichun_android.ui.screens.settings import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.craigvg.lichun_android.ui.theme.AppColors import com.craigvg.lichun_android.ui.theme.AppSpacing import com.craigvg.lichun_android.ui.theme.AppTypography import com.craigvg.lichun_android.viewmodel.GameStateViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle @OptIn(ExperimentalMaterial3Api::class) @Composable fun DebugToolsScreen( gameStateViewModel: GameStateViewModel = hiltViewModel(), onBack: () -> Unit = {} ) { val person by gameStateViewModel.person.collectAsStateWithLifecycle() var customAmount by remember { mutableStateOf("100") } var customResource by remember { mutableStateOf(DebugResource.MONEY) } var presetsExpanded by remember { mutableStateOf(false) } Scaffold( topBar = { TopAppBar( title = { Text("Debug Tools", style = AppTypography.headline) }, navigationIcon = { IconButton(onClick = onBack) { Icon( imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back", tint = AppColors.primaryText ) } }, colors = TopAppBarDefaults.topAppBarColors( containerColor = AppColors.surfaceElevated ) ) }, containerColor = AppColors.background ) { paddingValues -> Column( modifier = Modifier .fillMaxSize() .padding(paddingValues) .verticalScroll(rememberScrollState()) .padding(AppSpacing.md), verticalArrangement = Arrangement.spacedBy(AppSpacing.md) ) { ResourceSummaryCard( energy = person.calcEnergy, money = person.money, diamonds = person.diamonds ) GrantSection(title = "Energy") { GrantButton("+25") { gameStateViewModel.sendDebugGrant(energy = 25) } GrantButton("+50") { gameStateViewModel.sendDebugGrant(energy = 50) } GrantButton("Fill") { gameStateViewModel.sendDebugGrant(energy = 100, mode = "set") } } GrantSection(title = "Money") { GrantButton("+$500") { gameStateViewModel.sendDebugGrant(money = 500) } GrantButton("+$5,000") { gameStateViewModel.sendDebugGrant(money = 5000) } } GrantSection(title = "Diamonds") { GrantButton("+10") { gameStateViewModel.sendDebugGrant(diamonds = 10) } GrantButton("+100") { gameStateViewModel.sendDebugGrant(diamonds = 100) } } Card( shape = RoundedCornerShape(AppSpacing.cornerRadius), colors = CardDefaults.cardColors(containerColor = AppColors.surfaceElevated) ) { Column( modifier = Modifier.padding(AppSpacing.md), verticalArrangement = Arrangement.spacedBy(AppSpacing.sm) ) { Text("Custom grant", style = AppTypography.bodyBold, color = AppColors.primaryText) SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) { DebugResource.entries.forEachIndexed { index, resource -> SegmentedButton( selected = customResource == resource, onClick = { customResource = resource }, shape = SegmentedButtonDefaults.itemShape( index = index, count = DebugResource.entries.size ) ) { Text(resource.label) } } } OutlinedTextField( value = customAmount, onValueChange = { customAmount = it.filter { ch -> ch.isDigit() } }, label = { Text("Amount") }, modifier = Modifier.fillMaxWidth(), singleLine = true ) Button( onClick = { val amount = customAmount.toIntOrNull() if (amount == null || amount <= 0) return@Button when (customResource) { DebugResource.MONEY -> gameStateViewModel.sendDebugGrant(money = amount) DebugResource.ENERGY -> gameStateViewModel.sendDebugGrant(energy = amount.coerceAtMost(100)) DebugResource.DIAMONDS -> gameStateViewModel.sendDebugGrant(diamonds = amount.coerceAtMost(10_000)) } }, modifier = Modifier.fillMaxWidth() ) { Text("Apply") } } } Card( shape = RoundedCornerShape(AppSpacing.cornerRadius), colors = CardDefaults.cardColors(containerColor = AppColors.surfaceElevated) ) { Column(modifier = Modifier.padding(AppSpacing.md)) { TextButton(onClick = { presetsExpanded = !presetsExpanded }) { Text( if (presetsExpanded) "Hide life presets" else "Show life presets", color = AppColors.primary ) } if (presetsExpanded) { val presets = listOf( "Teen" to "teen", "Young adult" to "youngAdult", "Adult" to "adult", "Wealthy" to "wealthy", "Low energy" to "lowEnergy", "Relationships" to "relationships" ) presets.forEach { (label, preset) -> TextButton( onClick = { gameStateViewModel.sendDebugSetup(preset) } ) { Text(label, color = AppColors.primaryText) } } } } } } } } private enum class DebugResource(val label: String) { MONEY("Money"), ENERGY("Energy"), DIAMONDS("Diamonds") } @Composable private fun ResourceSummaryCard(energy: Int, money: Double, diamonds: Int) { Card( shape = RoundedCornerShape(AppSpacing.cornerRadius), colors = CardDefaults.cardColors(containerColor = AppColors.surfaceElevated) ) { Column( modifier = Modifier.padding(AppSpacing.md), verticalArrangement = Arrangement.spacedBy(AppSpacing.sm) ) { Text("Current resources", style = AppTypography.bodyBold, color = AppColors.primaryText) Row(horizontalArrangement = Arrangement.spacedBy(AppSpacing.sm)) { SummaryPill("Energy", energy.toString(), AppColors.energy, Modifier.weight(1f)) SummaryPill("Money", "$${money.toInt()}", AppColors.money, Modifier.weight(1f)) SummaryPill("Diamonds", diamonds.toString(), AppColors.diamond, Modifier.weight(1f)) } } } } @Composable private fun SummaryPill(label: String, value: String, color: androidx.compose.ui.graphics.Color, modifier: Modifier) { Column( modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp) ) { Text(label, style = AppTypography.caption, color = AppColors.secondaryText) Text(value, style = AppTypography.bodyBold, color = color) } } @Composable private fun GrantSection(title: String, content: @Composable RowScope.() -> Unit) { Card( shape = RoundedCornerShape(AppSpacing.cornerRadius), colors = CardDefaults.cardColors(containerColor = AppColors.surfaceElevated) ) { Column( modifier = Modifier.padding(AppSpacing.md), verticalArrangement = Arrangement.spacedBy(AppSpacing.sm) ) { Text(title, style = AppTypography.bodyBold, color = AppColors.primaryText) Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(AppSpacing.sm), content = content ) } } } @Composable private fun RowScope.GrantButton(label: String, onClick: () -> Unit) { OutlinedButton( onClick = onClick, modifier = Modifier.weight(1f) ) { Text(label) } }