import 'package:flutter/material.dart';

import '../../../controllers/localization/localization.dart';
import '../../../models/gas_refill/gas_refill_model.dart';
import '../../../models/subtitle.dart';
import '../../pages/user/gas_refill/gas_refill_details.dart';
import '../loaders/lazy_loading.dart';
import '../loaders/no_item_found.dart';
import 'gas_refill_item.dart';

class GasRefillList extends StatelessWidget {
  final List<GasRefillModel> items;
  final bool nextPage;
  final Future<void> Function() onLazyLoad;

  const GasRefillList({Key? key, required this.items, required this.nextPage, required this.onLazyLoad}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (items.length == 0) {
      Subtitle? subtitle = AppLocalization.of(context)?.subtitle;
      return NoItemFound(
        message: subtitle?.noServiceRequestFound ?? "",
      );
    }
    return LazyLoading(
      nextPage: nextPage,
      onLazyLoad: onLazyLoad,
      onLoadingEnd: () {},
      child: ListView.builder(
          //physics: const BouncingScrollPhysics(),
          itemCount: items.length,
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
          itemBuilder: (context, itemIndex) {
            return GasRefillItem(
              index: itemIndex,
              item: items[itemIndex],
              onPressed: (model) {
                Navigator.of(context).push(MaterialPageRoute(
                    builder: (_) => GasRefillDetails(
                          model: model,
                        )));
              },
            );
          }),
    );
  }
}
