import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

enum AppTagTone { neutral, success, warning, danger, info }

class AppTag extends StatelessWidget {
  const AppTag({
    super.key,
    required this.label,
    this.tone = AppTagTone.neutral,
    this.icon,
  });

  final String label;
  final AppTagTone tone;
  final IconData? icon;

  @override
  Widget build(BuildContext context) {
    final (foreground, background) = _colors(context);
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8.r, vertical: 4.r),
      decoration: BoxDecoration(
        color: background,
        borderRadius: BorderRadius.circular(999.r),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          if (icon != null) ...[
            Icon(icon, size: 14.r, color: foreground),
            SizedBox(width: 4.w),
          ],
          Text(
            label,
            style: Theme.of(context).textTheme.labelSmall?.copyWith(
              color: foreground,
              fontWeight: FontWeight.w600,
            ),
          ),
        ],
      ),
    );
  }

  (Color, Color) _colors(BuildContext context) {
    final colors = Theme.of(context).colorScheme;
    return switch (tone) {
      AppTagTone.neutral => (
        colors.onSurfaceVariant,
        colors.surfaceContainerHighest,
      ),
      AppTagTone.success => (const Color(0xFF166534), const Color(0xFFDCFCE7)),
      AppTagTone.warning => (const Color(0xFF92400E), const Color(0xFFFEF3C7)),
      AppTagTone.danger => (colors.error, colors.errorContainer),
      AppTagTone.info => (colors.primary, colors.primaryContainer),
    };
  }
}
