import 'package:flutter/material.dart';
import '../../app/i18n/app_localizations.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({required BuildContext context}) => StatusTag(label: context.t('status.active'), type: StatusType.success);
  static StatusTag pending({required BuildContext context}) => StatusTag(label: context.t('status.pending'), type: StatusType.pending);
  static StatusTag expired({required BuildContext context}) => StatusTag(label: context.t('status.expired'), type: StatusType.neutral);
  static StatusTag used({required BuildContext context}) => StatusTag(label: context.t('status.used'), type: StatusType.neutral);
  static StatusTag processing({required BuildContext context}) => StatusTag(label: context.t('status.processing'), type: StatusType.info);
  static StatusTag completed({required BuildContext context}) => StatusTag(label: context.t('status.completed'), type: StatusType.success);
  static StatusTag cancelled({required BuildContext context}) => StatusTag(label: context.t('status.cancelled'), type: StatusType.neutral);
  static StatusTag refunding({required BuildContext context}) => StatusTag(label: context.t('status.refunding'), type: StatusType.pending);
  static StatusTag onSale({required BuildContext context}) => StatusTag(label: context.t('status.onSale'), type: StatusType.info);
}
