package solutions.tretter.githugandroid

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun LevelsPane(
    levels: List<Level>,
    currentLevelIndex: Int,
    completedLevels: Set<String>,
    onSelect: (Int) -> Unit,
) {
    Column(
        modifier = Modifier.fillMaxWidth(),
        verticalArrangement = Arrangement.spacedBy(6.dp),
    ) {
        levels.forEachIndexed { index, level ->
            Card(
                colors = CardDefaults.cardColors(
                    containerColor = if (index == currentLevelIndex) PanelTertiary else PanelPrimary,
                ),
                shape = RoundedCornerShape(10.dp),
            ) {
                TextButton(
                    onClick = { onSelect(index) },
                    modifier = Modifier.fillMaxWidth(),
                    colors = ButtonDefaults.textButtonColors(
                        contentColor = if (index == currentLevelIndex) Accent else TextSecondary,
                    ),
                ) {
                    Text(
                        text = buildString {
                            append(if (level.id in completedLevels) "✓ " else "• ")
                            append(level.title)
                        },
                        modifier = Modifier.fillMaxWidth(),
                    )
                }
            }
        }
    }
}