package com.craigvg.lichun_android.ui.components.stats import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp import com.craigvg.lichun_android.ui.theme.AppColors import com.craigvg.lichun_android.ui.theme.AppSpacing import com.craigvg.lichun_android.ui.theme.AppTypography @Composable fun CozyStatBar( label: String, value: Float, color: Color, modifier: Modifier = Modifier, icon: (@Composable () -> Unit)? = null ) { val animatedValue by animateFloatAsState( targetValue = value.coerceIn(0f, 1f), animationSpec = tween(durationMillis = 500), label = "statBar" ) val percentage = (animatedValue * 100).toInt() Column(modifier = modifier.semantics { contentDescription = "$label $percentage%" }) { Row(verticalAlignment = Alignment.CenterVertically) { icon?.let { it() Spacer(Modifier.width(AppSpacing.xs)) } Text(text = label, style = AppTypography.caption, color = AppColors.primaryText) Spacer(Modifier.weight(1f)) Text(text = "$percentage%", style = AppTypography.captionBold, color = AppColors.secondaryText) } Spacer(Modifier.height(4.dp)) Box( modifier = Modifier .fillMaxWidth() .height(AppSpacing.progressBarHeight) .clip(RoundedCornerShape(AppSpacing.progressBarHeight / 2)) .background(color.copy(alpha = 0.2f)) ) { Box( modifier = Modifier .fillMaxHeight() .fillMaxWidth(fraction = animatedValue) .clip(RoundedCornerShape(AppSpacing.progressBarHeight / 2)) .background(color) ) } } }