package com.peachpasswords.ui.security import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import com.peachpasswords.ui.theme.LocalPeachAccent import com.peachpasswords.ui.theme.peachColors /** * Amber for the mid-range ("weak"/"fair") fill. PeachColors has no amber token, * and the spec calls for one distinct from breach (low) and health (high), so it * is defined locally rather than hardcoded inline at each call site. */ private val StrengthAmber = Color(0xCCE0A040) /** * Fill color for a given [score], per spec §E1: * 0 → breach, 1–2 → amber, 3 → health, 4 → accent. */ @Composable fun strengthColor(score: Int): Color { val accent = LocalPeachAccent.current return when (score.coerceIn(0, 4)) { 0 -> peachColors.Breach 1, 2 -> StrengthAmber 3 -> peachColors.HealthOk else -> accent } } /** * Four-segment strength bar, 4dp tall, full width. The number of *lit* segments * follows the spec ramp (1/2/3/4/4 for scores 0..4); unlit segments use T3. * * Filled-segment count differs from the raw score so score 0 still shows one lit * (breach-colored) segment as feedback rather than an empty bar. */ @Composable fun StrengthBar(score: Int, modifier: Modifier = Modifier) { val s = score.coerceIn(0, 4) val lit = when (s) { 0 -> 1 1 -> 2 2 -> 3 else -> 4 } val fill = strengthColor(s) Row(modifier = modifier.fillMaxWidth()) { repeat(4) { i -> Box( modifier = Modifier .weight(1f) .height(4.dp) .padding(end = if (i < 3) 4.dp else 0.dp) .clip(RoundedCornerShape(2.dp)) .background(if (i < lit) fill else peachColors.T3), ) } } }