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

/// 价格标签组件
///
/// 当前价格（大字）+ 原价删除线 + 折扣标签
/// 使用场景：券详情页、确认订单、我的券
class PriceTag extends StatelessWidget {
  final double currentPrice;
  final double faceValue;
  final PriceTagSize size;
  final bool showDiscount;

  const PriceTag({
    super.key,
    required this.currentPrice,
    required this.faceValue,
    this.size = PriceTagSize.medium,
    this.showDiscount = true,
  });

  double get discountRate => currentPrice / faceValue;
  String get discountText => '${(discountRate * 10).toStringAsFixed(1)}折';
  double get savedAmount => faceValue - currentPrice;

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      mainAxisSize: MainAxisSize.min,
      children: [
        // Dollar sign
        Text(
          '\$',
          style: _priceStyle.copyWith(fontSize: _priceStyle.fontSize! * 0.6),
        ),
        // Current price
        Text(
          currentPrice.toStringAsFixed(2),
          style: _priceStyle,
        ),
        const SizedBox(width: 8),
        // Original price (strikethrough)
        if (currentPrice < faceValue)
          Text(
            '\$${faceValue.toStringAsFixed(0)}',
            style: _originalStyle,
          ),
        if (showDiscount && currentPrice < faceValue) ...[
          const SizedBox(width: 8),
          _buildDiscountChip(),
        ],
      ],
    );
  }

  Widget _buildDiscountChip() {
    return Container(
      padding: EdgeInsets.symmetric(
        horizontal: size == PriceTagSize.large ? 8 : 6,
        vertical: size == PriceTagSize.large ? 3 : 2,
      ),
      decoration: BoxDecoration(
        gradient: AppColors.primaryGradient,
        borderRadius: AppSpacing.borderRadiusFull,
      ),
      child: Text(
        discountText,
        style: AppTypography.discountBadge.copyWith(
          fontSize: size == PriceTagSize.large ? 13 : 11,
        ),
      ),
    );
  }

  TextStyle get _priceStyle {
    switch (size) {
      case PriceTagSize.large:
        return AppTypography.priceLarge;
      case PriceTagSize.medium:
        return AppTypography.priceMedium;
      case PriceTagSize.small:
        return AppTypography.priceSmall;
    }
  }

  TextStyle get _originalStyle {
    switch (size) {
      case PriceTagSize.large:
        return AppTypography.priceOriginal.copyWith(fontSize: 16);
      case PriceTagSize.medium:
        return AppTypography.priceOriginal;
      case PriceTagSize.small:
        return AppTypography.priceOriginal.copyWith(fontSize: 11);
    }
  }
}

enum PriceTagSize { large, medium, small }
