package com.dong.maxhap.demos.test

import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.dong.maxhap.demos.game.Game2048Screen
import com.dong.maxhap.demos.game.SnakeGameScreen
import com.dong.maxhap.demos.game.XiangqiScreen

@Composable
internal fun HapPage() {
    var showGame2048 by remember { mutableStateOf(false) }
    var showSnakeGame by remember { mutableStateOf(false) }
    var showXiangqiGame by remember { mutableStateOf(false) }
    
    // 如果要显示2048游戏，则渲染游戏界面
    if (showGame2048) {
        Game2048Screen(onBack = { showGame2048 = false })
        return
    }
    
    // 如果要显示贪吃蛇游戏，则渲染游戏界面
    if (showSnakeGame) {
        SnakeGameScreen(onBack = { showSnakeGame = false })
        return
    }
    
    // 如果要显示象棋游戏，则渲染游戏界面
    if (showXiangqiGame) {
        XiangqiScreen(onBack = { showXiangqiGame = false })
        return
    }
    
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Top
    ) {
        Text(
            text = "🎮 小游戏中心",
            fontSize = 24.sp,
            fontWeight = FontWeight.Bold,
            modifier = Modifier.padding(bottom = 20.dp)
        )
        
        // 游戏按钮网格
        Column(
            modifier = Modifier.fillMaxWidth(),
            verticalArrangement = Arrangement.spacedBy(12.dp)
        ) {
            GameButton(
                text = "🧩 2048游戏",
                color = Color(0xFF4CAF50),
                onClick = { showGame2048 = true }
            )
            
            GameButton(
                text = "🐍 贪吃蛇",
                color = Color(0xFF4CAF50),
                onClick = { showSnakeGame = true }
            )
            
            GameButton(
                text = "🔵🔴 五子棋",
                color = Color(0xFFFF9800),
                onClick = { /* TODO: 跳转到五子棋游戏 */ }
            )
            
            GameButton(
                text = "🐘🐎 象棋",
                color = Color(0xFFF44336),
                onClick = { showXiangqiGame = true }
            )
        }
    }
}

@Composable
private fun GameButton(
    text: String,
    color: Color,
    onClick: () -> Unit
) {
    Button(
        onClick = onClick,
        modifier = Modifier
            .fillMaxWidth()
            .height(60.dp),
        colors = ButtonDefaults.buttonColors(backgroundColor = color)
    ) {
        Text(
            text = text,
            fontSize = 18.sp,
            fontWeight = FontWeight.Medium,
            color = Color.White
        )
    }
}