package com.craigvg.lichun_android.ui.screens.dating import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import com.craigvg.lichun_android.domain.models.DateMiniGameState import com.craigvg.lichun_android.domain.models.DateQuestion import com.craigvg.lichun_android.domain.models.DateResponse import com.craigvg.lichun_android.domain.models.Person import com.craigvg.lichun_android.ui.screens.dating.components.MiniGameContent import com.craigvg.lichun_android.ui.screens.dating.components.MiniGameResults import com.craigvg.lichun_android.ui.theme.AppColors import kotlinx.coroutines.delay import kotlinx.coroutines.launch /** * Date mini-game screen * Ported from iOS DateMiniGameView.swift */ @Composable fun DateMiniGameScreen( partner: Person, onComplete: (Int) -> Unit = {}, onDismiss: () -> Unit = {} ) { var gameState by remember { mutableStateOf( DateMiniGameState( id = "game1", partnerId = partner.id, partnerName = partner.firstname, activityId = "dinner", questions = listOf( DateQuestion( id = "q1", text = "What's your favorite way to spend a weekend?", responses = listOf( DateResponse("r1a", "I love exploring new places!", true, 5), DateResponse("r1b", "Netflix and relaxing at home.", false, 2), DateResponse("r1c", "Catching up on work.", false, 0) ), round = 0 ), DateQuestion( id = "q2", text = "If you could travel anywhere, where would you go?", responses = listOf( DateResponse("r2a", "Paris - the city of love!", true, 5), DateResponse("r2b", "Somewhere tropical and warm.", true, 3), DateResponse("r2c", "I don't really like traveling.", false, 0) ), round = 1 ), DateQuestion( id = "q3", text = "What's most important to you in a relationship?", responses = listOf( DateResponse("r3a", "Trust and communication.", true, 5), DateResponse("r3b", "Having fun together.", true, 3), DateResponse("r3c", "I'm not sure yet.", false, 1) ), round = 2 ) ) ) ) } var showFeedback by remember { mutableStateOf(false) } var lastResponseCorrect by remember { mutableStateOf(false) } val scope = rememberCoroutineScope() Box( modifier = Modifier .fillMaxSize() .background( Brush.linearGradient( colors = listOf( Color(0xFFFFE8F0).copy(alpha = 0.4f), AppColors.background, Color(0xFFF5E8FF).copy(alpha = 0.3f), AppColors.background ) ) ) ) { if (gameState.isComplete) { MiniGameResults( gameState = gameState, partnerName = partner.firstname, onComplete = { onComplete(gameState.totalAffinity) onDismiss() } ) } else { MiniGameContent( gameState = gameState, partner = partner, showFeedback = showFeedback, lastResponseCorrect = lastResponseCorrect, onResponseSelected = { response -> showFeedback = true lastResponseCorrect = response.isCorrect scope.launch { delay(1500) showFeedback = false val newCorrectAnswers = if (response.isCorrect) { gameState.correctAnswers + 1 } else { gameState.correctAnswers } val newTotalAffinity = gameState.totalAffinity + response.affinityImpact val newRound = gameState.currentRound + 1 gameState = gameState.copy( currentRound = newRound, correctAnswers = newCorrectAnswers, totalAffinity = newTotalAffinity, isComplete = newRound >= gameState.totalRounds ) } } ) } } }