import 'package:flutter/material.dart';

import '../../../../common/extension/extension.dart';
import '../../../../common/theme/theme.dart';
import '../../../../domain/analytic/analytic.dart';
import 'stat_tile.dart';

class ReportQuickStats extends StatelessWidget {
  final DashboardOverview overview;

  const ReportQuickStats({super.key, required this.overview});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          children: [
            Expanded(
              child: TweenAnimationBuilder<double>(
                tween: Tween<double>(begin: 0, end: 1),
                duration: const Duration(milliseconds: 800),
                builder: (context, value, child) {
                  return Transform.scale(
                    scale: value,
                    child: ReportStatTile(
                      title: context.lang.total_orders,
                      value: overview.totalOrders.toString(),
                      icon: Icons.receipt_long,
                      color: AppColor.info,
                      animatedValue: overview.totalOrders * value,
                    ),
                  );
                },
              ),
            ),
            const SizedBox(width: 16),
            Expanded(
              child: TweenAnimationBuilder<double>(
                tween: Tween<double>(begin: 0, end: 1),
                duration: const Duration(milliseconds: 1000),
                builder: (context, value, child) {
                  return Transform.scale(
                    scale: value,
                    child: ReportStatTile(
                      title: context.lang.average_price,
                      value: overview.averageOrderValue
                          .round()
                          .currencyFormatRp,
                      icon: Icons.trending_up,
                      color: AppColor.warning,
                      animatedValue: overview.averageOrderValue * value,
                    ),
                  );
                },
              ),
            ),
          ],
        ),

        const SizedBox(height: 16),

        Row(
          children: [
            Expanded(
              child: TweenAnimationBuilder<double>(
                tween: Tween<double>(begin: 0, end: 1),
                duration: const Duration(milliseconds: 1200),
                builder: (context, value, child) {
                  return Transform.scale(
                    scale: value,
                    child: ReportStatTile(
                      title: context.lang.customer,
                      value: overview.totalCustomers.toString(),
                      icon: Icons.people,
                      color: AppColor.success,
                      animatedValue: overview.totalCustomers * value,
                    ),
                  );
                },
              ),
            ),
            const SizedBox(width: 16),
            Expanded(
              child: TweenAnimationBuilder<double>(
                tween: Tween<double>(begin: 0, end: 1),
                duration: const Duration(milliseconds: 1400),
                builder: (context, value, child) {
                  return Transform.scale(
                    scale: value,
                    child: ReportStatTile(
                      title:
                          '${context.lang.void_text} + ${context.lang.refund}',
                      value: (overview.voidedOrders + overview.refundedOrders)
                          .toString(),

                      icon: Icons.cancel,
                      color: AppColor.error,
                      animatedValue:
                          (overview.voidedOrders + overview.refundedOrders) *
                          value,
                    ),
                  );
                },
              ),
            ),
          ],
        ),
      ],
    );
  }
}
