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

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

@Stable
class Layout(
    val texture: ImageBitmap,
    val offset: IntOffset = IntOffset.Zero,
    val size: IntSize = IntSize(texture.width, texture.height),
    private val initialAlpha: Float = 1f,
) {
    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)
        }
    }
}