package com.craigvg.lichun_android.ui.screens.home.components import androidx.compose.animation.Crossfade import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.RestartAlt import androidx.compose.material3.* 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.platform.LocalView import androidx.compose.ui.unit.dp import com.craigvg.lichun_android.domain.models.GameSpeedScale import com.craigvg.lichun_android.ui.components.dialogs.ConfirmationDialog 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.utils.HapticFeedback /** * Game controls card (Tier 3 polish): * - PRIMARY: time speed, with a single named vocabulary (Slow / Normal / Fast / * Instant) shared by the label and the pip meter. The game auto-starts, so * there is no redundant Start control. * - DEMOTED + GUARDED: "Start a New Life" sits below a divider and asks for * confirmation ("ends your current life") before restarting. * * Android parity with iOS GameControlsCard.swift (T014). */ @Composable fun GameControlsCard( gameSpeed: Int, onSpeedChange: (Int) -> Unit, onRestart: () -> Unit = {} ) { var showRestartConfirm by remember { mutableStateOf(false) } val view = LocalView.current val speedName = GameSpeedScale.label(gameSpeed) Card( modifier = Modifier.fillMaxWidth(), shape = RoundedCornerShape(AppSpacing.cornerRadius), colors = CardDefaults.cardColors(containerColor = AppColors.surfaceElevated) ) { Column( modifier = Modifier .fillMaxWidth() .padding(AppSpacing.md) ) { Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically ) { Text( text = "Speed of Time", style = AppTypography.bodyBold, color = AppColors.primaryText, modifier = Modifier.weight(1f) ) Crossfade(targetState = speedName, label = "speedName") { name -> Text( text = name, style = AppTypography.captionBold, color = AppColors.primary, modifier = Modifier .clip(RoundedCornerShape(AppSpacing.smallCornerRadius)) .background(AppColors.primary.copy(alpha = 0.12f)) .padding(horizontal = AppSpacing.sm, vertical = AppSpacing.xxs) ) } } Spacer(modifier = Modifier.height(AppSpacing.sm)) SpeedButtonsView( gameSpeed = gameSpeed, onSpeedChange = onSpeedChange ) Spacer(modifier = Modifier.height(AppSpacing.md)) HorizontalDivider(color = AppColors.disabledText.copy(alpha = 0.3f)) Spacer(modifier = Modifier.height(AppSpacing.md)) // Demoted, guarded life action. OutlinedButton( onClick = { showRestartConfirm = true }, modifier = Modifier .fillMaxWidth() .height(AppSpacing.buttonHeight), shape = RoundedCornerShape(AppSpacing.cornerRadius), colors = ButtonDefaults.outlinedButtonColors(contentColor = AppColors.warning) ) { Icon(Icons.Default.RestartAlt, null, modifier = Modifier.size(18.dp)) Spacer(modifier = Modifier.width(AppSpacing.xs)) Text("Start a New Life", style = AppTypography.bodyBold) } } } if (showRestartConfirm) { ConfirmationDialog( title = "Start a new life?", message = "This ends your current life and starts over from birth. Your current character's progress will be lost.", confirmTitle = "Start New Life", cancelTitle = "Keep Playing", isDestructive = true, onConfirm = { HapticFeedback.warning(view.context) showRestartConfirm = false onRestart() }, onCancel = { showRestartConfirm = false } ) } }