import 'package:flutter/material.dart'; import '../data/models.dart'; import '../theme/reclaim_tokens.dart'; /// Freshness badge — flags when a norm version is stale relative to /// the published source (amended upstream) or hasn't been reconciled. /// By design it renders NOTHING for [Freshness.current] (the common /// case shouldn't add noise) unless [alwaysShow] is set. Same chip /// shape as the scope/tier badges. class FreshnessBadge extends StatelessWidget { const FreshnessBadge({ super.key, required this.freshness, this.note, this.compact = false, this.alwaysShow = false, }); final Freshness freshness; /// Optional plain-text hint of what changed (from Norm.supersededNote). final String? note; final bool compact; final bool alwaysShow; @override Widget build(BuildContext context) { if (!freshness.needsBadge && !alwaysShow) { return const SizedBox.shrink(); } final t = Theme.of(context).textTheme; final color = switch (freshness) { Freshness.current => ReclaimColors.signal, Freshness.superseded => ReclaimColors.freshSuperseded, Freshness.unknown => ReclaimColors.freshUnknown, }; final icon = switch (freshness) { Freshness.current => Icons.check_circle_outline, Freshness.superseded => Icons.history_toggle_off, Freshness.unknown => Icons.help_outline, }; final label = compact ? freshness.label : 'Stand: ${freshness.label}'; return Tooltip( message: '${freshness.description}' '${note != null && note!.isNotEmpty ? '\n$note' : ''}', child: Container( padding: EdgeInsets.symmetric( horizontal: compact ? 6 : ReclaimSpace.sm, vertical: compact ? 2 : 4, ), decoration: BoxDecoration( color: color.withValues(alpha: 0.18), border: Border.all(color: color.withValues(alpha: 0.55)), borderRadius: const BorderRadius.all(ReclaimRadius.sm), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(icon, size: compact ? 12 : 14, color: color), const SizedBox(width: 6), Text( label, style: (compact ? t.labelSmall : t.labelLarge)?.copyWith( color: color, fontWeight: FontWeight.w600, ), ), ], ), ), ); } }