package com.omixlab.lckcontrol.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.SportsEsports
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.omixlab.lckcontrol.util.GameInfoProvider

@Composable
fun GameInfoRow(
    packageName: String,
    gameInfoProvider: GameInfoProvider,
    iconSize: Dp = 24.dp,
    showPackageName: Boolean = false,
) {
    val gameInfo = remember(packageName) { gameInfoProvider.resolve(packageName) }

    Row(verticalAlignment = Alignment.CenterVertically) {
        if (gameInfo != null) {
            Image(
                bitmap = gameInfo.icon,
                contentDescription = gameInfo.label,
                modifier = Modifier.size(iconSize),
            )
            Spacer(Modifier.width(8.dp))
            Text(gameInfo.label, style = MaterialTheme.typography.bodyMedium)
            if (showPackageName) {
                Spacer(Modifier.width(4.dp))
                Text(
                    "(${gameInfo.packageName})",
                    style = MaterialTheme.typography.bodySmall,
                    color = MaterialTheme.colorScheme.onSurfaceVariant,
                )
            }
        } else {
            Icon(
                Icons.Default.SportsEsports,
                contentDescription = "Game",
                modifier = Modifier.size(iconSize),
                tint = MaterialTheme.colorScheme.onSurfaceVariant,
            )
            Spacer(Modifier.width(8.dp))
            Text(
                packageName,
                style = MaterialTheme.typography.bodyMedium,
                color = MaterialTheme.colorScheme.onSurfaceVariant,
            )
        }
    }
}
