import 'package:flutter/material.dart';

import '../../../../common/extension/extension.dart';
import '../../../../common/theme/theme.dart';
import '../../../../domain/analytic/analytic.dart';
import '../../../components/spacer/spacer.dart';
import 'title.dart';
import 'top_product_tile.dart';

class HomeTopProduct extends StatelessWidget {
  final List<DashboardTopProduct> products;
  const HomeTopProduct({super.key, required this.products});

  @override
  Widget build(BuildContext context) {
    if (products.isEmpty) {
      return const SizedBox.shrink();
    }

    return Padding(
      padding: const EdgeInsets.symmetric(
        vertical: 24,
        horizontal: AppValue.padding,
      ).copyWith(bottom: 0),
      child: Column(
        children: [
          HomeTitle(title: context.lang.today_top_product),
          SpaceHeight(20),
          ListView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: products.length,
            padding: EdgeInsets.zero,
            itemBuilder: (context, index) {
              return HomeTopProductTile(
                product: products[index],
                ranking: index + 1,
              );
            },
          ),
        ],
      ),
    );
  }
}
