package club.clubk.ktag.apps.koth.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import club.clubk.ktag.apps.koth.KothEvent
import club.clubk.ktag.apps.koth.KothState
import club.clubk.ktag.apps.koth.R
import club.clubk.ktag.apps.koth.ui.theme.KothBlack
import club.clubk.ktag.apps.koth.ui.theme.KothGreen
import club.clubk.ktag.apps.koth.ui.theme.KothRed
import club.clubk.ktag.apps.koth.ui.theme.KothWhite

@Composable
fun GameControlFabs(
    gameState: KothState,
    onEvent: (KothEvent) -> Unit,
    modifier: Modifier = Modifier
) {
    Box(
        modifier = modifier.padding(16.dp),
        contentAlignment = Alignment.BottomEnd
    ) {
        // Play button - visible in Idle state
        AnimatedVisibility(
            visible = gameState is KothState.Idle,
            enter = fadeIn() + scaleIn(),
            exit = fadeOut() + scaleOut()
        ) {
            FloatingActionButton(
                onClick = { onEvent(KothEvent.Start) },
                containerColor = KothBlack
            ) {
                Icon(
                    painter = painterResource(id = R.drawable.ic_play),
                    contentDescription = "Play",
                    tint = KothGreen
                )
            }
        }

        // Stop button - visible in CountingDown and Playing states
        AnimatedVisibility(
            visible = gameState is KothState.CountingDown || gameState is KothState.Playing,
            enter = fadeIn() + scaleIn(),
            exit = fadeOut() + scaleOut()
        ) {
            FloatingActionButton(
                onClick = { onEvent(KothEvent.Stop) },
                containerColor = KothBlack
            ) {
                Icon(
                    painter = painterResource(id = R.drawable.ic_stop),
                    contentDescription = "Stop",
                    tint = KothRed
                )
            }
        }

        // Reset button - visible in Finished state
        AnimatedVisibility(
            visible = gameState is KothState.Finished,
            enter = fadeIn() + scaleIn(),
            exit = fadeOut() + scaleOut()
        ) {
            FloatingActionButton(
                onClick = { onEvent(KothEvent.Reset) },
                containerColor = KothBlack
            ) {
                Icon(
                    painter = painterResource(id = R.drawable.ic_reset),
                    contentDescription = "Reset",
                    tint = KothWhite
                )
            }
        }
    }
}
