import 'package:flutter/material.dart';

import '../../app/theme.dart';

/// Pill rossa con dot pulsante e timer diretta.
class LiveBadge extends StatelessWidget {
  const LiveBadge({
    super.key,
    required this.elapsed,
    this.compact = false,
  });

  final Duration elapsed;
  final bool compact;

  String _format(Duration d) {
    final h = d.inHours;
    final m = d.inMinutes.remainder(60).toString().padLeft(2, '0');
    final s = d.inSeconds.remainder(60).toString().padLeft(2, '0');
    if (h > 0) return '$h:$m:$s';
    return '$m:$s';
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Container(
      padding: EdgeInsets.symmetric(
        horizontal: compact ? 10 : 14,
        vertical: compact ? 4 : 6,
      ),
      decoration: BoxDecoration(
        color: AppTheme.primaryRed,
        borderRadius: BorderRadius.circular(20),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: compact ? 6 : 8,
            height: compact ? 6 : 8,
            decoration: const BoxDecoration(
              color: Colors.white,
              shape: BoxShape.circle,
            ),
          ),
          SizedBox(width: compact ? 6 : 8),
          Text(
            compact ? 'LIVE ${_format(elapsed)}' : 'IN DIRETTA ${_format(elapsed)}',
            style: theme.textTheme.labelLarge?.copyWith(
              color: Colors.white,
              fontSize: compact ? 11 : 13,
            ),
          ),
        ],
      ),
    );
  }
}
