// country_code.dart — 国家码方块 + 信号条
import 'package:flutter/material.dart';
import '../pangolin_theme.dart';

class CountryCode extends StatelessWidget {
  const CountryCode({super.key, required this.code, this.active = false, this.size = 38});
  final String code;
  final bool active;
  final double size;

  @override
  Widget build(BuildContext context) {
    final c = context.pangolin;
    return Container(
      width: size,
      height: size,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        color: active ? c.accent : c.bgSubtle,
        borderRadius: BorderRadius.circular(PangolinRadius.md),
      ),
      child: Text(
        code,
        style: PangolinText.mono.copyWith(
          fontSize: size * 0.31,
          fontWeight: FontWeight.w600,
          color: active ? PangolinColors.white : c.fg2,
        ),
      ),
    );
  }
}

/// 三格信号条,依据延迟 ping 显示强度。
class SignalBars extends StatelessWidget {
  const SignalBars({super.key, required this.ping});
  final int ping;

  @override
  Widget build(BuildContext context) {
    final c = context.pangolin;
    final level = ping < 40 ? 3 : ping < 90 ? 2 : 1;
    const heights = [4.0, 8.0, 13.0];
    return Row(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.end,
      children: List.generate(3, (i) {
        return Container(
          width: 3,
          height: heights[i],
          margin: EdgeInsets.only(left: i == 0 ? 0 : 2),
          decoration: BoxDecoration(
            color: i < level ? c.success : c.borderStrong,
            borderRadius: BorderRadius.circular(1),
          ),
        );
      }),
    );
  }
}
