package com.pixelized.desktop.lwa.ui.composable.button

import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import com.pixelized.desktop.lwa.ui.theme.lwa
import kotlinx.coroutines.flow.StateFlow
import lwacharactersheet.composeapp.generated.resources.Res
import lwacharactersheet.composeapp.generated.resources.ic_remove_24dp
import org.jetbrains.compose.resources.painterResource

@Composable
fun SignButton(
    modifier: Modifier = Modifier,
    interactionSource: MutableInteractionSource? = null,
    enabled: Boolean = true,
    add: StateFlow<Boolean>,
    onClick: () -> Unit,
) {
    IconButton(
        onClick = onClick,
        modifier = modifier,
        enabled = enabled,
        interactionSource = interactionSource,
    ) {
        val rotation = animateFloatAsState(
            animationSpec = spring(stiffness = Spring.StiffnessMediumLow),
            targetValue = when (add.collectAsState().value) {
                true -> 90f
                else -> 0f
            }
        )
        Icon(
            modifier = Modifier.graphicsLayer {
                this.rotationZ = rotation.value * 2f
            },
            painter = painterResource(Res.drawable.ic_remove_24dp),
            tint = MaterialTheme.lwa.colorScheme.base.primary,
            contentDescription = null
        )
        Icon(
            modifier = Modifier.graphicsLayer {
                this.rotationZ = rotation.value * 3f
            },
            painter = painterResource(Res.drawable.ic_remove_24dp),
            tint = MaterialTheme.lwa.colorScheme.base.primary,
            contentDescription = null
        )
    }
}