import 'package:flutter/material.dart';

class StatusChip extends StatelessWidget {
  final String status;

  const StatusChip({super.key, required this.status});

  static const _successStatuses = {'SUCCESS', 'COMPLETE', 'COMPLETED'};
  static const _processingStatuses = {'PROCESSING', 'REQUESTED', 'CONFIRMING'};
  static const _pendingStatuses = {'CREATED', 'CONFIRMED_ALL'};

  Map<String, dynamic> _getStatusColors() {
    final upper = status.toUpperCase();
    final bool isSuccess = _successStatuses.contains(upper);
    final bool isProcessing = _processingStatuses.contains(upper);
    final bool isPending = _pendingStatuses.contains(upper);

    final Color bgColor = isSuccess
        ? const Color(0xFFD1FAE5)
        : isProcessing
        ? const Color(0xFFDBEAFE)
        : isPending
        ? const Color(0xFFFEF3C7)
        : const Color(0xFFFEE2E2);

    final Color textColor = isSuccess
        ? const Color(0xFF065F46)
        : isProcessing
        ? const Color(0xFF1E40AF)
        : isPending
        ? const Color(0xFF92400E)
        : const Color(0xFF991B1B);

    final Color dotColor = isSuccess
        ? const Color(0xFF10B981)
        : isProcessing
        ? const Color(0xFF3B82F6)
        : isPending
        ? const Color(0xFFF59E0B)
        : const Color(0xFFEF4444);

    return {'bgColor': bgColor, 'textColor': textColor, 'dotColor': dotColor};
  }

  @override
  Widget build(BuildContext context) {
    final colors = _getStatusColors();
    final bgColor = colors['bgColor'] as Color;
    final textColor = colors['textColor'] as Color;
    final dotColor = colors['dotColor'] as Color;

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
      decoration: BoxDecoration(
        color: bgColor,
        borderRadius: BorderRadius.circular(20),
      ),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: 8,
            height: 8,
            decoration: BoxDecoration(color: dotColor, shape: BoxShape.circle),
          ),
          const SizedBox(width: 6),
          Text(
            status,
            style: TextStyle(
              fontSize: 13,
              fontWeight: FontWeight.w600,
              color: textColor,
            ),
          ),
        ],
      ),
    );
  }
}
