import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dart:math' as math;

import '../../constants/color_constants.dart';
import '../../constants/font_constants.dart';
import '../../widgets/text_widget.dart';

class OrderDetailsPage extends StatefulWidget {
  final String orderId;
  final String gstno;
  final String storeName;
  final String storeLocation;
  final List<Map<String, dynamic>> items;
  final double tax;
  final double fee;

  const OrderDetailsPage({
    super.key,
    required this.orderId,
    required this.gstno,
    required this.storeName,
    required this.storeLocation,
    required this.items,
    required this.tax,
    required this.fee,
  });

  @override
  State<OrderDetailsPage> createState() => _OrderDetailsPageState();
}

class _OrderDetailsPageState extends State<OrderDetailsPage> with TickerProviderStateMixin {
  late AnimationController _pageController;
  late AnimationController _storeCardController;
  late AnimationController _itemsController;
  late AnimationController _billController;
  late AnimationController _statusController;

  late Animation<double> _pageFadeAnimation;
  late Animation<Offset> _pageSlideAnimation;
  late Animation<double> _storeScaleAnimation;
  late Animation<double> _storeRotateAnimation;
  late Animation<double> _itemsFadeAnimation;
  late Animation<Offset> _itemsSlideAnimation;
  late Animation<double> _billFadeAnimation;
  late Animation<Offset> _billSlideAnimation;
  late Animation<double> _statusFadeAnimation;
  late Animation<double> _statusScaleAnimation;

  @override
  void initState() {
    super.initState();

    // Page animation
    _pageController = AnimationController(
      duration: const Duration(milliseconds: 500),
      vsync: this,
    );

    _pageFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(parent: _pageController, curve: Curves.easeOut),
    );

    _pageSlideAnimation = Tween<Offset>(
      begin: const Offset(0, 0.03),
      end: Offset.zero,
    ).animate(CurvedAnimation(parent: _pageController, curve: Curves.easeOutCubic));

    // Store card animation
    _storeCardController = AnimationController(
      duration: const Duration(milliseconds: 800),
      vsync: this,
    );

    _storeScaleAnimation = Tween<double>(begin: 0.9, end: 1.0).animate(
      CurvedAnimation(parent: _storeCardController, curve: Curves.easeOutBack),
    );

    _storeRotateAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(parent: _storeCardController, curve: Curves.easeOut),
    );

    // Items card animation
    _itemsController = AnimationController(
      duration: const Duration(milliseconds: 600),
      vsync: this,
    );

    _itemsFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(parent: _itemsController, curve: Curves.easeOut),
    );

    _itemsSlideAnimation = Tween<Offset>(
      begin: const Offset(0.05, 0),
      end: Offset.zero,
    ).animate(CurvedAnimation(parent: _itemsController, curve: Curves.easeOutCubic));

    // Bill summary animation
    _billController = AnimationController(
      duration: const Duration(milliseconds: 600),
      vsync: this,
    );

    _billFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(parent: _billController, curve: Curves.easeOut),
    );

    _billSlideAnimation = Tween<Offset>(
      begin: const Offset(-0.05, 0),
      end: Offset.zero,
    ).animate(CurvedAnimation(parent: _billController, curve: Curves.easeOutCubic));

    // Status animation
    _statusController = AnimationController(
      duration: const Duration(milliseconds: 700),
      vsync: this,
    );

    _statusFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
      CurvedAnimation(parent: _statusController, curve: Curves.easeOut),
    );

    _statusScaleAnimation = Tween<double>(begin: 0.85, end: 1.0).animate(
      CurvedAnimation(parent: _statusController, curve: Curves.easeOutBack),
    );

    // Start animations in sequence
    _startAnimations();
  }

  void _startAnimations() async {
    _pageController.forward();
    await Future.delayed(const Duration(milliseconds: 100));
    _storeCardController.forward();
    await Future.delayed(const Duration(milliseconds: 200));
    _itemsController.forward();
    await Future.delayed(const Duration(milliseconds: 150));
    _billController.forward();
    await Future.delayed(const Duration(milliseconds: 150));
    _statusController.forward();
  }

  @override
  void dispose() {
    _pageController.dispose();
    _storeCardController.dispose();
    _itemsController.dispose();
    _billController.dispose();
    _statusController.dispose();
    super.dispose();
  }

  double rs(BuildContext context, double size) {
    final width = MediaQuery.of(context).size.width;
    if (width > 600) {
      return size * 1.2; // Scale up for tablets
    }
    return size;
  }

  @override
  Widget build(BuildContext context) {
    final total = widget.items.fold<double>(
      0.0,
          (sum, item) => sum + (double.tryParse(item['productSumPrice'].toString()) ?? 0.0),
    );
    final grandTotal = total + widget.tax + widget.fee;

    return SafeArea(
      top: false,
      child: LayoutBuilder(
        builder: (context, constraints) {
          final isTablet = constraints.maxWidth > 600;
          final padding = isTablet ? 32.0 : 16.0;
          final maxWidth = isTablet ? 800.0 : double.infinity;

          return Scaffold(
            backgroundColor: const Color(0xFFF8F9FA),
            appBar: PreferredSize(
              preferredSize: Size.fromHeight(isTablet ? 70 : kToolbarHeight),
              child: FadeTransition(
                opacity: _pageFadeAnimation,
                child: AppBar(
                  elevation: 0,
                  backgroundColor: Colors.white,
                  leading: Container(
                    margin: EdgeInsets.all(isTablet ? 12 : 8),
                    decoration: BoxDecoration(
                      color: const Color(0xFFF8F9FA),
                      borderRadius: BorderRadius.circular(isTablet ? 16 : 12),
                    ),
                    child: IconButton(
                      onPressed: () => Navigator.of(context).pop(),
                      icon: Icon(
                        Icons.arrow_back_ios_new_rounded,
                        size: isTablet ? 22 : 18,
                        color: ColorConstants.primaryColor,
                      ),
                    ),
                  ),
                  centerTitle: true,
                  title: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      TweenAnimationBuilder<double>(
                        tween: Tween(begin: 0.0, end: 1.0),
                        duration: const Duration(milliseconds: 600),
                        curve: Curves.easeOutBack,
                        builder: (context, value, child) {
                          return Transform.scale(
                            scale: value,
                            child: Container(
                              padding: EdgeInsets.all(isTablet ? 8 : 6),
                              decoration: BoxDecoration(
                                color: ColorConstants.primaryColor.withOpacity(0.1),
                                borderRadius: BorderRadius.circular(isTablet ? 12 : 8),
                              ),
                              child: Icon(
                                Icons.receipt_long_rounded,
                                color: ColorConstants.primaryColor,
                                size: isTablet ? 24 : 18,
                              ),
                            ),
                          );
                        },
                      ),
                      SizedBox(width: isTablet ? 14 : 10),
                      ReusableTextWidget(
                        text: 'Order #${widget.orderId}',
                        color: const Color(0xFF1A1A1A),
                        fontFamily: FontConstants.fontFamily,
                        fontSize: rs(context, isTablet ? 20 : 16),
                        fontWeight: FontWeight.w600,
                        textAlign: TextAlign.center,
                      ),
                    ],
                  ),
                ),
              ),
            ),
            body: FadeTransition(
              opacity: _pageFadeAnimation,
              child: SlideTransition(
                position: _pageSlideAnimation,
                child: Center(
                  child: ConstrainedBox(
                    constraints: BoxConstraints(maxWidth: maxWidth),
                    child: SingleChildScrollView(
                      padding: EdgeInsets.all(padding),
                      physics: const BouncingScrollPhysics(),
                      child: Column(
                        children: [
                          // Store Information Card
                          _buildStoreCard(isTablet),

                          SizedBox(height: isTablet ? 28 : 20),

                          // Order Items Card
                          _buildItemsCard(isTablet),

                          SizedBox(height: isTablet ? 28 : 20),

                          // Bill Summary Card
                          _buildBillSummary(isTablet, total, grandTotal),

                          SizedBox(height: isTablet ? 24 : 16),

                          // Order Status
                          _buildOrderStatus(isTablet),

                          SizedBox(height: isTablet ? 32 : 20),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ),
          );
        },
      ),
    );
  }

  Widget _buildStoreCard(bool isTablet) {
    return ScaleTransition(
      scale: _storeScaleAnimation,
      child: FadeTransition(
        opacity: _storeScaleAnimation,
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(isTablet ? 20 : 16),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.04),
                blurRadius: isTablet ? 15 : 10,
                offset: Offset(0, isTablet ? 3 : 2),
              ),
            ],
          ),
          child: Column(
            children: [
              // Store Header
              Container(
                padding: EdgeInsets.all(isTablet ? 28 : 20),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(isTablet ? 20 : 16),
                    topRight: Radius.circular(isTablet ? 20 : 16),
                  ),
                ),
                child: Row(
                  children: [
                    TweenAnimationBuilder<double>(
                      tween: Tween(begin: 0.0, end: 2 * math.pi),
                      duration: const Duration(milliseconds: 1000),
                      curve: Curves.easeOut,
                      builder: (context, value, child) {
                        return Transform.rotate(
                          angle: value,
                          child: Container(
                            padding: EdgeInsets.all(isTablet ? 16 : 12),
                            decoration: BoxDecoration(
                              color: ColorConstants.primaryColor,
                              borderRadius: BorderRadius.circular(isTablet ? 16 : 12),
                              boxShadow: [
                                BoxShadow(
                                  color: ColorConstants.primaryColor.withOpacity(0.2),
                                  blurRadius: isTablet ? 12 : 8,
                                  offset: Offset(0, isTablet ? 6 : 4),
                                ),
                              ],
                            ),
                            child: Icon(
                              Icons.storefront_rounded,
                              color: Colors.white,
                              size: isTablet ? 28 : 20,
                            ),
                          ),
                        );
                      },
                    ),
                    SizedBox(width: isTablet ? 20 : 16),
                    Expanded(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          TweenAnimationBuilder<double>(
                            tween: Tween(begin: 0.0, end: 1.0),
                            duration: const Duration(milliseconds: 800),
                            curve: Curves.easeOut,
                            builder: (context, value, child) {
                              return Opacity(
                                opacity: value,
                                child: ReusableTextWidget(
                                  text: widget.storeName,
                                  color: const Color(0xFF1A1A1A),
                                  fontFamily: FontConstants.fontFamily,
                                  fontSize: rs(context, isTablet ? 20 : 16),
                                  fontWeight: FontWeight.w600,
                                  textAlign: TextAlign.start,
                                ),
                              );
                            },
                          ),
                          SizedBox(height: isTablet ? 6 : 4),
                          TweenAnimationBuilder<double>(
                            tween: Tween(begin: 0.0, end: 1.0),
                            duration: const Duration(milliseconds: 1000),
                            curve: Curves.easeOut,
                            builder: (context, value, child) {
                              return Opacity(
                                opacity: value,
                                child: Row(
                                  children: [
                                    Icon(
                                      Icons.location_on_outlined,
                                      size: isTablet ? 16 : 12,
                                      color: const Color(0xFF6B7280),
                                    ),
                                    SizedBox(width: isTablet ? 6 : 4),
                                    Flexible(
                                      child: ReusableTextWidget(
                                        text: widget.storeLocation,
                                        color: const Color(0xFF6B7280),
                                        fontFamily: FontConstants.fontFamily,
                                        fontSize: rs(context, isTablet ? 14 : 12),
                                        fontWeight: FontWeight.w400,
                                        textAlign: TextAlign.start,
                                        overflow: TextOverflow.ellipsis,
                                      ),
                                    ),
                                  ],
                                ),
                              );
                            },
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),

              // GST Information with slide animation
              TweenAnimationBuilder<Offset>(
                tween: Tween(begin: const Offset(-0.1, 0), end: Offset.zero),
                duration: const Duration(milliseconds: 800),
                curve: Curves.easeOutCubic,
                builder: (context, offset, child) {
                  return Transform.translate(
                    offset: Offset(offset.dx * 100, 0),
                    child: Container(
                      padding: EdgeInsets.symmetric(
                        horizontal: isTablet ? 28 : 20,
                        vertical: isTablet ? 20 : 16,
                      ),
                      child: Row(
                        children: [
                          TweenAnimationBuilder<double>(
                            tween: Tween(begin: 0.0, end: 1.0),
                            duration: const Duration(milliseconds: 600),
                            curve: Curves.easeOutBack,
                            builder: (context, value, child) {
                              return Transform.scale(
                                scale: value,
                                child: Icon(
                                  Icons.verified_user_outlined,
                                  size: isTablet ? 22 : 16,
                                  color: ColorConstants.primaryColor,
                                ),
                              );
                            },
                          ),
                          SizedBox(width: isTablet ? 16 : 12),
                          ReusableTextWidget(
                            text: 'GST Number',
                            color: const Color(0xFF6B7280),
                            fontFamily: FontConstants.fontFamily,
                            fontSize: rs(context, isTablet ? 14 : 12),
                            fontWeight: FontWeight.w500,
                            textAlign: TextAlign.start,
                          ),
                          const Spacer(),
                          ReusableTextWidget(
                            text: widget.gstno,
                            color: const Color(0xFF1A1A1A),
                            fontFamily: FontConstants.fontFamily,
                            fontSize: rs(context, isTablet ? 15 : 13),
                            fontWeight: FontWeight.w600,
                            textAlign: TextAlign.start,
                          ),
                        ],
                      ),
                    ),
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildItemsCard(bool isTablet) {
    return FadeTransition(
      opacity: _itemsFadeAnimation,
      child: SlideTransition(
        position: _itemsSlideAnimation,
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(isTablet ? 20 : 16),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.04),
                blurRadius: isTablet ? 15 : 10,
                offset: Offset(0, isTablet ? 3 : 2),
              ),
            ],
          ),
          child: Column(
            children: [
              // Header
              Container(
                padding: EdgeInsets.all(isTablet ? 28 : 20),
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(color: const Color(0xFFE5E7EB), width: 1),
                  ),
                ),
                child: Row(
                  children: [
                    TweenAnimationBuilder<double>(
                      tween: Tween(begin: 0.0, end: 1.0),
                      duration: const Duration(milliseconds: 600),
                      curve: Curves.easeOutBack,
                      builder: (context, value, child) {
                        return Transform.scale(
                          scale: value,
                          child: Icon(
                            Icons.shopping_bag_outlined,
                            color: ColorConstants.primaryColor,
                            size: isTablet ? 24 : 18,
                          ),
                        );
                      },
                    ),
                    SizedBox(width: isTablet ? 16 : 12),
                    ReusableTextWidget(
                      text: 'Order Items',
                      color: const Color(0xFF1A1A1A),
                      fontFamily: FontConstants.fontFamily,
                      fontSize: rs(context, isTablet ? 18 : 15),
                      fontWeight: FontWeight.w600,
                      textAlign: TextAlign.start,
                    ),
                    const Spacer(),
                    TweenAnimationBuilder<double>(
                      tween: Tween(begin: 0.0, end: 1.0),
                      duration: const Duration(milliseconds: 800),
                      curve: Curves.easeOutBack,
                      builder: (context, value, child) {
                        return Transform.scale(
                          scale: value,
                          child: Container(
                            padding: EdgeInsets.symmetric(
                              horizontal: isTablet ? 14 : 10,
                              vertical: isTablet ? 6 : 4,
                            ),
                            decoration: BoxDecoration(
                              color: ColorConstants.primaryColor.withOpacity(0.1),
                              borderRadius: BorderRadius.circular(isTablet ? 10 : 8),
                            ),
                            child: ReusableTextWidget(
                              text: '${widget.items.length} ${widget.items.length == 1 ? 'item' : 'items'}',
                              color: ColorConstants.primaryColor,
                              fontFamily: FontConstants.fontFamily,
                              fontSize: rs(context, isTablet ? 14 : 12),
                              fontWeight: FontWeight.w600,
                              textAlign: TextAlign.center,
                            ),
                          ),
                        );
                      },
                    ),
                  ],
                ),
              ),

              // Items List with staggered animation
              ListView.separated(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                itemCount: widget.items.length,
                separatorBuilder: (context, index) => Divider(
                  height: 1,
                  color: const Color(0xFFE5E7EB),
                  indent: isTablet ? 28 : 20,
                  endIndent: isTablet ? 28 : 20,
                ),
                itemBuilder: (context, index) {
                  final item = widget.items[index];
                  return TweenAnimationBuilder<double>(
                    tween: Tween(begin: 0.0, end: 1.0),
                    duration: Duration(milliseconds: 400 + (index * 100)),
                    curve: Curves.easeOutCubic,
                    builder: (context, value, child) {
                      return Transform.translate(
                        offset: Offset(30 * (1 - value), 0),
                        child: Opacity(
                          opacity: value,
                          child: Padding(
                            padding: EdgeInsets.symmetric(
                              horizontal: isTablet ? 28 : 20,
                              vertical: isTablet ? 20 : 16,
                            ),
                            child: Row(
                              children: [
                                Expanded(
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      ReusableTextWidget(
                                        text: item['name'] ?? '',
                                        color: const Color(0xFF1A1A1A),
                                        fontFamily: FontConstants.fontFamily,
                                        fontSize: rs(context, isTablet ? 16 : 14),
                                        fontWeight: FontWeight.w500,
                                        textAlign: TextAlign.start,
                                      ),
                                      SizedBox(height: isTablet ? 6 : 4),
                                      ReusableTextWidget(
                                        text: 'Qty: ${item['quantity']}',
                                        color: const Color(0xFF6B7280),
                                        fontFamily: FontConstants.fontFamily,
                                        fontSize: rs(context, isTablet ? 14 : 12),
                                        fontWeight: FontWeight.w400,
                                        textAlign: TextAlign.start,
                                      ),
                                    ],
                                  ),
                                ),
                                TweenAnimationBuilder<double>(
                                  tween: Tween(begin: 0.0, end: 1.0),
                                  duration: Duration(milliseconds: 600 + (index * 100)),
                                  curve: Curves.easeOut,
                                  builder: (context, priceValue, child) {
                                    return Opacity(
                                      opacity: priceValue,
                                      child: ReusableTextWidget(
                                        text: '₹${(item['price'] ?? 0).toStringAsFixed(2)}',
                                        color: const Color(0xFF1A1A1A),
                                        fontFamily: FontConstants.fontFamily,
                                        fontSize: rs(context, isTablet ? 18 : 15),
                                        fontWeight: FontWeight.w600,
                                        textAlign: TextAlign.start,
                                      ),
                                    );
                                  },
                                ),
                              ],
                            ),
                          ),
                        ),
                      );
                    },
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildBillSummary(bool isTablet, double total, double grandTotal) {
    return FadeTransition(
      opacity: _billFadeAnimation,
      child: SlideTransition(
        position: _billSlideAnimation,
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(isTablet ? 20 : 16),
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.04),
                blurRadius: isTablet ? 15 : 10,
                offset: Offset(0, isTablet ? 3 : 2),
              ),
            ],
          ),
          child: Column(
            children: [
              // Header
              Container(
                padding: EdgeInsets.all(isTablet ? 28 : 20),
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(color: const Color(0xFFE5E7EB), width: 1),
                  ),
                ),
                child: Row(
                  children: [
                    TweenAnimationBuilder<double>(
                      tween: Tween(begin: 0.0, end: 1.0),
                      duration: const Duration(milliseconds: 600),
                      curve: Curves.easeOutBack,
                      builder: (context, value, child) {
                        return Transform.scale(
                          scale: value,
                          child: Icon(
                            Icons.receipt_outlined,
                            color: ColorConstants.primaryColor,
                            size: isTablet ? 24 : 18,
                          ),
                        );
                      },
                    ),
                    SizedBox(width: isTablet ? 16 : 12),
                    ReusableTextWidget(
                      text: 'Bill Summary',
                      color: const Color(0xFF1A1A1A),
                      fontFamily: FontConstants.fontFamily,
                      fontSize: rs(context, isTablet ? 18 : 15),
                      fontWeight: FontWeight.w600,
                      textAlign: TextAlign.start,
                    ),
                  ],
                ),
              ),

              Padding(
                padding: EdgeInsets.all(isTablet ? 28 : 20),
                child: Column(
                  children: [
                    _buildAnimatedBillRow('Subtotal', total, isTablet, 0),
                    SizedBox(height: isTablet ? 16 : 12),
                    _buildAnimatedBillRow('GST', widget.tax, isTablet, 100),
                    SizedBox(height: isTablet ? 16 : 12),
                    _buildAnimatedBillRow('Delivery Fee', widget.fee, isTablet, 200),

                    SizedBox(height: isTablet ? 20 : 16),

                    TweenAnimationBuilder<double>(
                      tween: Tween(begin: 0.0, end: 1.0),
                      duration: const Duration(milliseconds: 600),
                      curve: Curves.easeOut,
                      builder: (context, value, child) {
                        return Opacity(
                          opacity: value,
                          child: Divider(height: 1, color: const Color(0xFFE5E7EB)),
                        );
                      },
                    ),

                    SizedBox(height: isTablet ? 20 : 16),

                    // Grand Total with pulse animation
                    TweenAnimationBuilder<double>(
                      tween: Tween(begin: 0.92, end: 1.0),
                      duration: const Duration(milliseconds: 800),
                      curve: Curves.easeOutBack,
                      builder: (context, value, child) {
                        return Transform.scale(
                          scale: value,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              ReusableTextWidget(
                                text: 'Grand Total',
                                color: const Color(0xFF1A1A1A),
                                fontFamily: FontConstants.fontFamily,
                                fontSize: rs(context, isTablet ? 19 : 16),
                                fontWeight: FontWeight.w700,
                                textAlign: TextAlign.start,
                              ),
                              TweenAnimationBuilder<double>(
                                tween: Tween(begin: 0.0, end: grandTotal),
                                duration: const Duration(milliseconds: 1200),
                                curve: Curves.easeOut,
                                builder: (context, animatedValue, child) {
                                  return ReusableTextWidget(
                                    text: '₹${animatedValue.toStringAsFixed(2)}',
                                    color: ColorConstants.primaryColor,
                                    fontFamily: FontConstants.fontFamily,
                                    fontSize: rs(context, isTablet ? 22 : 18),
                                    fontWeight: FontWeight.w700,
                                    textAlign: TextAlign.start,
                                  );
                                },
                              ),
                            ],
                          ),
                        );
                      },
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildAnimatedBillRow(String label, double amount, bool isTablet, int delay) {
    return TweenAnimationBuilder<double>(
      tween: Tween(begin: 0.0, end: 1.0),
      duration: Duration(milliseconds: 500 + delay),
      curve: Curves.easeOut,
      builder: (context, value, child) {
        return Transform.translate(
          offset: Offset(-20 * (1 - value), 0),
          child: Opacity(
            opacity: value,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                ReusableTextWidget(
                  text: label,
                  color: const Color(0xFF6B7280),
                  fontFamily: FontConstants.fontFamily,
                  fontSize: rs(context, isTablet ? 15 : 13),
                  fontWeight: FontWeight.w400,
                  textAlign: TextAlign.start,
                ),
                ReusableTextWidget(
                  text: '₹${amount.toStringAsFixed(2)}',
                  color: const Color(0xFF1A1A1A),
                  fontFamily: FontConstants.fontFamily,
                  fontSize: rs(context, isTablet ? 16 : 14),
                  fontWeight: FontWeight.w500,
                  textAlign: TextAlign.start,
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  Widget _buildOrderStatus(bool isTablet) {
    return FadeTransition(
      opacity: _statusFadeAnimation,
      child: ScaleTransition(
        scale: _statusScaleAnimation,
        child: Container(
          padding: EdgeInsets.all(isTablet ? 28 : 20),
          decoration: BoxDecoration(
            color: const Color(0xFFECFDF5),
            borderRadius: BorderRadius.circular(isTablet ? 20 : 16),
            border: Border.all(
              color: const Color(0xFF10B981),
              width: 1,
            ),
          ),
          child: Row(
            children: [
              TweenAnimationBuilder<double>(
                tween: Tween(begin: 0.0, end: 1.0),
                duration: const Duration(milliseconds: 800),
                curve: Curves.easeOutBack,
                builder: (context, value, child) {
                  return Transform.scale(
                    scale: value,
                    child: Container(
                      padding: EdgeInsets.all(isTablet ? 14 : 10),
                      decoration: BoxDecoration(
                        color: const Color(0xFF10B981),
                        borderRadius: BorderRadius.circular(isTablet ? 14 : 10),
                      ),
                      child: Icon(
                        Icons.check_rounded,
                        color: Colors.white,
                        size: isTablet ? 24 : 20,
                      ),
                    ),
                  );
                },
              ),
              SizedBox(width: isTablet ? 20 : 16),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ReusableTextWidget(
                      text: 'We appreciate your order!',
                      color: const Color(0xFF1F2937),
                      fontFamily: FontConstants.fontFamily,
                      fontSize: rs(context, isTablet ? 18 : 15),
                      fontWeight: FontWeight.w600,
                      textAlign: TextAlign.start,
                    ),
                    SizedBox(height: isTablet ? 6 : 4),
                    ReusableTextWidget(
                      text: 'Our team is taking care of it.',
                      color: const Color(0xFF6B7280),
                      fontFamily: FontConstants.fontFamily,
                      fontSize: rs(context, isTablet ? 14 : 12),
                      fontWeight: FontWeight.w400,
                      textAlign: TextAlign.start,
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}