|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | +// SPDX-FileCopyrightText: 2025-2026 gotnull (developer@socialmesh.app) |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | + |
| 5 | +import '../../../core/health/node_health.dart'; |
| 6 | +import '../../../core/l10n/l10n_extension.dart'; |
| 7 | +import '../../../core/theme.dart'; |
| 8 | + |
| 9 | +/// Small, visually-secondary operational health badge for SiteOps node |
| 10 | +/// visibility (fresh / stale / offline / unknown). Coexists with — and does |
| 11 | +/// not replace — the social presence label. |
| 12 | +class NodeHealthBadge extends StatelessWidget { |
| 13 | + const NodeHealthBadge({super.key, required this.state}); |
| 14 | + |
| 15 | + final NodeHealthState state; |
| 16 | + |
| 17 | + @override |
| 18 | + Widget build(BuildContext context) { |
| 19 | + final color = colorFor(state); |
| 20 | + return Container( |
| 21 | + padding: const EdgeInsets.symmetric( |
| 22 | + horizontal: AppTheme.spacing8, |
| 23 | + vertical: AppTheme.spacing2, |
| 24 | + ), |
| 25 | + decoration: BoxDecoration( |
| 26 | + color: color.withValues(alpha: 0.12), |
| 27 | + borderRadius: BorderRadius.circular(AppTheme.radius6), |
| 28 | + border: Border.all(color: color.withValues(alpha: 0.5)), |
| 29 | + ), |
| 30 | + child: Text( |
| 31 | + labelFor(context, state), |
| 32 | + style: Theme.of(context).textTheme.labelSmall?.copyWith( |
| 33 | + color: color, |
| 34 | + fontWeight: FontWeight.w600, |
| 35 | + letterSpacing: 0.3, |
| 36 | + ), |
| 37 | + ), |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + /// Canonical state -> color mapping, shared with other health surfaces |
| 42 | + /// (e.g. the node-detail badges row) so the mapping has one home. |
| 43 | + static Color colorFor(NodeHealthState state) { |
| 44 | + switch (state) { |
| 45 | + case NodeHealthState.fresh: |
| 46 | + return SemanticColors.success; |
| 47 | + case NodeHealthState.stale: |
| 48 | + return SemanticColors.warning; |
| 49 | + case NodeHealthState.offline: |
| 50 | + return SemanticColors.error; |
| 51 | + case NodeHealthState.unknown: |
| 52 | + return SemanticColors.muted; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /// Canonical state -> operational label mapping (localized). |
| 57 | + static String labelFor(BuildContext context, NodeHealthState state) { |
| 58 | + switch (state) { |
| 59 | + case NodeHealthState.fresh: |
| 60 | + return context.l10n.nodeHealthFresh; |
| 61 | + case NodeHealthState.stale: |
| 62 | + return context.l10n.nodeHealthStale; |
| 63 | + case NodeHealthState.offline: |
| 64 | + return context.l10n.nodeHealthOffline; |
| 65 | + case NodeHealthState.unknown: |
| 66 | + return context.l10n.nodeHealthUnknown; |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments