import 'package:flutter/material.dart';

import '../../theme/autopilot_theme.dart';

/// Connection / data-source status indicator — coloured dot + label.
///
/// Used in the [CockpitScreen] top-bar to show NMEA and GPS link state.
enum StatusLevel {
  /// Data valid and link active.
  ok,

  /// Data stale, link degraded, or GPS fix lost.
  warn,

  /// Link absent (serial port not open, concentrador not connected).
  off,
}

class StatusChip extends StatelessWidget {
  const StatusChip({
    super.key,
    required this.theme,
    required this.label,
    required this.status,
  });

  final AutopilotTheme theme;
  final String label;
  final StatusLevel status;

  Color get _dotColor => switch (status) {
        StatusLevel.ok => theme.okColor,
        StatusLevel.warn => theme.warnColor,
        StatusLevel.off => theme.textDisabled,
      };

  @override
  Widget build(BuildContext context) {
    final dot = _dotColor;
    final glowing = status == StatusLevel.ok && theme.accentGlowRadius > 0;

    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          width: 7,
          height: 7,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: dot,
            boxShadow: glowing
                ? [BoxShadow(color: dot.withValues(alpha: 0.6), blurRadius: 6)]
                : null,
          ),
        ),
        const SizedBox(width: 5),
        Text(
          label,
          style: TextStyle(
            color:
                status == StatusLevel.off ? theme.textDisabled : theme.textMuted,
            fontSize: 10,
            letterSpacing: 0.5,
            fontWeight: FontWeight.w500,
          ),
        ),
      ],
    );
  }
}
