package com.example.smarthome.ui

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.Canvas
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.unit.dp
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size

@Composable
fun LiquidIndicator(visible: Boolean) {
    val t by animateFloatAsState(targetValue = if (visible) 1f else 0f, animationSpec = spring(stiffness = Spring.StiffnessMediumLow), label = "t")
    if (t <= 0f) return
    Canvas(modifier = Modifier) {
        val w = size.width
        val h = size.height
        val p = Path()
        val r = h.coerceAtMost(w) / 2f
        p.addOval(androidx.compose.ui.geometry.Rect(Offset(w / 2f - r / 2f, h / 2f - r / 2f), Size(r, r)))
        drawIntoCanvas {
            drawPath(p, Color(0x55FFFFFF))
        }
    }
}
