package com.example.gameofmoon.presentation.ui.components

import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
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 androidx.compose.ui.window.Dialog

@Composable
fun GameControlMenu(
    isVisible: Boolean,
    onDismiss: () -> Unit,
    onSaveGame: () -> Unit,
    onLoadGame: () -> Unit,
    onNewLoop: () -> Unit,
    onAiAssist: () -> Unit,
    onShowHistory: () -> Unit,
    onSettings: () -> Unit
) {
    if (isVisible) {
        Dialog(onDismissRequest = onDismiss) {
            TerminalWindow(
                title = "🎮 游戏控制中心",
                modifier = Modifier.width(320.dp)
            ) {
                Column(
                    verticalArrangement = Arrangement.spacedBy(12.dp)
                ) {
                    // 保存/读取组
                    Text(
                        text = "数据管理",
                        style = CyberTextStyles.Choice.copy(fontSize = 14.sp),
                        color = Color(0xFF00DDFF),
                        fontWeight = FontWeight.Bold
                    )
                    
                    Row(
                        modifier = Modifier.fillMaxWidth(),
                        horizontalArrangement = Arrangement.spacedBy(8.dp)
                    ) {
                        NeonButton(
                            onClick = {
                                onSaveGame()
                                onDismiss()
                            },
                            modifier = Modifier.weight(1f)
                        ) {
                            Column(
                                horizontalAlignment = Alignment.CenterHorizontally
                            ) {
                                Text("💾", fontSize = 20.sp)
                                Text("保存", fontSize = 12.sp)
                            }
                        }
                        
                        NeonButton(
                            onClick = {
                                onLoadGame()
                                onDismiss()
                            },
                            modifier = Modifier.weight(1f)
                        ) {
                            Column(
                                horizontalAlignment = Alignment.CenterHorizontally
                            ) {
                                Text("📁", fontSize = 20.sp)
                                Text("读取", fontSize = 12.sp)
                            }
                        }
                    }
                    
                    CyberDivider()
                    
                    // 游戏控制组
                    Text(
                        text = "游戏控制",
                        style = CyberTextStyles.Choice.copy(fontSize = 14.sp),
                        color = Color(0xFF00DDFF),
                        fontWeight = FontWeight.Bold
                    )
                    
                    NeonButton(
                        onClick = {
                            onNewLoop()
                            onDismiss()
                        },
                        modifier = Modifier.fillMaxWidth()
                    ) {
                        Row(
                            modifier = Modifier.fillMaxWidth(),
                            horizontalArrangement = Arrangement.spacedBy(8.dp),
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Text("🔄", fontSize = 18.sp)
                            Column {
                                Text("开始新循环", fontSize = 12.sp, fontWeight = FontWeight.Bold)
                                Text("重置进度，保留记忆", fontSize = 10.sp, color = Color(0xFFAAAA88))
                            }
                        }
                    }
                    
                    NeonButton(
                        onClick = {
                            onShowHistory()
                            onDismiss()
                        },
                        modifier = Modifier.fillMaxWidth()
                    ) {
                        Row(
                            modifier = Modifier.fillMaxWidth(),
                            horizontalArrangement = Arrangement.spacedBy(8.dp),
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Text("📖", fontSize = 18.sp)
                            Column {
                                Text("对话历史", fontSize = 12.sp, fontWeight = FontWeight.Bold)
                                Text("查看完整对话记录", fontSize = 10.sp, color = Color(0xFFAAAA88))
                            }
                        }
                    }
                    
                    CyberDivider()
                    
                    // AI助手组
                    Text(
                        text = "AI助手",
                        style = CyberTextStyles.Choice.copy(fontSize = 14.sp),
                        color = Color(0xFF00DDFF),
                        fontWeight = FontWeight.Bold
                    )
                    
                    NeonButton(
                        onClick = {
                            onAiAssist()
                            onDismiss()
                        },
                        modifier = Modifier.fillMaxWidth()
                    ) {
                        Row(
                            modifier = Modifier.fillMaxWidth(),
                            horizontalArrangement = Arrangement.spacedBy(8.dp),
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Text("🤖", fontSize = 18.sp)
                            Column {
                                Text("请求AI协助", fontSize = 12.sp, fontWeight = FontWeight.Bold)
                                Text("生成新的故事内容", fontSize = 10.sp, color = Color(0xFFAAAA88))
                            }
                        }
                    }
                    
                    CyberDivider()
                    
                    // 设置组
                    Row(
                        modifier = Modifier.fillMaxWidth(),
                        horizontalArrangement = Arrangement.spacedBy(8.dp)
                    ) {
                        NeonButton(
                            onClick = {
                                onSettings()
                                onDismiss()
                            },
                            modifier = Modifier.weight(1f)
                        ) {
                            Column(
                                horizontalAlignment = Alignment.CenterHorizontally
                            ) {
                                Text("⚙️", fontSize = 20.sp)
                                Text("设置", fontSize = 12.sp)
                            }
                        }
                        
                        NeonButton(
                            onClick = onDismiss,
                            modifier = Modifier.weight(1f)
                        ) {
                            Column(
                                horizontalAlignment = Alignment.CenterHorizontally
                            ) {
                                Text("❌", fontSize = 20.sp)
                                Text("关闭", fontSize = 12.sp)
                            }
                        }
                    }
                }
            }
        }
    }
}
