import 'package:flutter/material.dart';

import '../theme/app_theme.dart';

/// نشانِ رتبه (برنز/نقره/طلا/الماس/پادشاه) با رنگ و برچسبِ فارسی.
class RankBadge extends StatelessWidget {
  final String tier; // bronze..king
  final int? points; // در صورت نمایش امتیاز
  final double size;
  const RankBadge({super.key, required this.tier, this.points, this.size = 16});

  static const _tiers = {
    'bronze': ('برنز', [Color(0xFFCD7F32), Color(0xFF8C5A2B)]),
    'silver': ('نقره', [Color(0xFFBFC6CC), Color(0xFF8A949B)]),
    'gold': ('طلا', [Color(0xFFFFD54F), AppColors.goldDark]),
    'diamond': ('الماس', [Color(0xFF5BE0E6), Color(0xFF1E8A99)]),
    'king': ('پادشاه', [Color(0xFFB388FF), Color(0xFF6A1B9A)]),
  };

  @override
  Widget build(BuildContext context) {
    final t = _tiers[tier] ?? _tiers['bronze']!;
    final label = t.$1;
    final colors = t.$2;
    return Container(
      padding: EdgeInsets.symmetric(horizontal: size * 0.6, vertical: size * 0.25),
      decoration: BoxDecoration(
        gradient: LinearGradient(colors: colors),
        borderRadius: BorderRadius.circular(size),
        boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 4)],
      ),
      child: Row(mainAxisSize: MainAxisSize.min, children: [
        Image.asset(
          'assets/images/badge/$tier.png',
          width: size * 1.5,
          height: size * 1.5,
          errorBuilder: (_, __, ___) =>
              Icon(Icons.military_tech, color: Colors.white, size: size * 1.1),
        ),
        SizedBox(width: size * 0.3),
        Text(
          points == null ? label : '$label · $points',
          style: TextStyle(
            color: Colors.white,
            fontSize: size * 0.85,
            fontWeight: FontWeight.bold,
          ),
        ),
      ]),
    );
  }
}
