package com.gmplayer.app

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

enum class MobileMainControllerState {
    Pause,
    Play,
    Replay
}

@Composable
fun MobileMainControllerButton(
    state: MobileMainControllerState,
    modifier: Modifier = Modifier,
    onClick: () -> Unit = {}
) {
    val imageResource = when (state) {
        MobileMainControllerState.Pause -> R.drawable.player_button_pause
        MobileMainControllerState.Play -> R.drawable.player_button_play
        MobileMainControllerState.Replay -> R.drawable.player_button_replay
    }
    val description = when (state) {
        MobileMainControllerState.Pause -> "Pause"
        MobileMainControllerState.Play -> "Play"
        MobileMainControllerState.Replay -> "Replay"
    }

    Box(
        modifier = modifier
            .size(98.dp)
            .clip(CircleShape)
            .background(Color.Black.copy(alpha = 0.25f))
            .clickable(role = Role.Button, onClick = onClick)
    ) {
        Image(
            painter = painterResource(id = imageResource),
            contentDescription = description,
            modifier = Modifier.size(98.dp)
        )
    }
}

@Preview(showBackground = true, backgroundColor = 0xFF20242C)
@Composable
private fun MobileMainControllerButtonPreview() {
    MobileMainControllerButton(state = MobileMainControllerState.Play)
}
