package com.pixelized.desktop.lwa.ui.composable.scene.drawables

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.VectorConverter
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize

open class SceneDrawable(
    val id: String,
    val name: String,
    val texture: ImageBitmap,
    val offset: IntOffset,
    val size: IntSize,
    private val initialAlpha: Float,
) {
    private val _alpha = Animatable(
        initialValue = initialAlpha,
        typeConverter = Float.VectorConverter,
    )
    val alpha get() = _alpha.value

    suspend fun alpha(
        alpha: Float,
        snap: Boolean = false,
    ) {
        when (snap) {
            true -> _alpha.snapTo(targetValue = alpha)
            else -> _alpha.animateTo(targetValue = alpha)
        }
    }

    suspend fun resetAlpha(
        snap: Boolean = false,
    ) {
        when (snap) {
            true -> _alpha.snapTo(targetValue = initialAlpha)
            else -> _alpha.animateTo(targetValue = initialAlpha)
        }
    }
}