package com.zaneschepke.wireguardautotunnel.desktop.ui.common.animation

import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.*
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.vector.ImageVector

@Composable
fun AnimatedFloatIcon(
    inactiveIcon: ImageVector,
    activeIcon: ImageVector,
    isSelected: Boolean,
    modifier: Modifier,
) {

    val transition = updateTransition(isSelected, label = null)
    val scale by
        transition.animateFloat(transitionSpec = { tween(250, easing = FastOutSlowInEasing) }) {
            selected ->
            if (selected) 1.2f else 1f
        }

    val rotation by
        animateFloatAsState(targetValue = 0f, animationSpec = tween(400, easing = LinearEasing))

    Crossfade(targetState = isSelected, animationSpec = tween(250, easing = FastOutSlowInEasing)) {
        selected ->
        Icon(
            imageVector = if (selected) activeIcon else inactiveIcon,
            contentDescription = null,
            modifier = modifier.scale(scale).rotate(rotation),
        )
    }
}
