import 'package:flutter/material.dart';
import '../../app/theme/app_colors.dart';
import '../../app/theme/app_typography.dart';
import '../../app/theme/app_spacing.dart';

/// 状态标签组件
///
/// 处理中/已完成/已取消/退款中 颜色标签
/// 使用场景：订单列表、我的券、交易记录
class StatusTag extends StatelessWidget {
  final String label;
  final StatusType type;

  const StatusTag({
    super.key,
    required this.label,
    required this.type,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
      decoration: BoxDecoration(
        color: _bgColor,
        borderRadius: AppSpacing.borderRadiusFull,
      ),
      child: Text(
        label,
        style: AppTypography.caption.copyWith(
          color: _textColor,
          fontWeight: FontWeight.w500,
          fontSize: 11,
        ),
      ),
    );
  }

  Color get _bgColor {
    switch (type) {
      case StatusType.success:
        return AppColors.successLight;
      case StatusType.pending:
        return AppColors.warningLight;
      case StatusType.error:
        return AppColors.errorLight;
      case StatusType.info:
        return AppColors.infoLight;
      case StatusType.neutral:
        return AppColors.gray100;
    }
  }

  Color get _textColor {
    switch (type) {
      case StatusType.success:
        return AppColors.success;
      case StatusType.pending:
        return AppColors.warning;
      case StatusType.error:
        return AppColors.error;
      case StatusType.info:
        return AppColors.info;
      case StatusType.neutral:
        return AppColors.textSecondary;
    }
  }
}

enum StatusType { success, pending, error, info, neutral }

/// 快捷构造
class StatusTags {
  StatusTags._();

  static StatusTag active() => const StatusTag(label: '可使用', type: StatusType.success);
  static StatusTag pending() => const StatusTag(label: '待核销', type: StatusType.pending);
  static StatusTag expired() => const StatusTag(label: '已过期', type: StatusType.neutral);
  static StatusTag used() => const StatusTag(label: '已使用', type: StatusType.neutral);
  static StatusTag processing() => const StatusTag(label: '处理中', type: StatusType.info);
  static StatusTag completed() => const StatusTag(label: '已完成', type: StatusType.success);
  static StatusTag cancelled() => const StatusTag(label: '已取消', type: StatusType.neutral);
  static StatusTag refunding() => const StatusTag(label: '退款中', type: StatusType.pending);
  static StatusTag onSale() => const StatusTag(label: '出售中', type: StatusType.info);
}
