import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/models/gas_refill/gas_refill_model.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/pages/user/gas_refill/gas_refill_details.dart';
import 'package:test_sa/views/widgets/gas_refill/gas_refill_item.dart';
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
import 'package:test_sa/views/widgets/loaders/no_item_found.dart';
class GasRefillList extends StatelessWidget {
  final List<GasRefillModel> items;
  final bool nextPage;
  final Future<void> Function() onLazyLoad;

  const GasRefillList({Key key, this.items, this.nextPage, 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,
      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,)
                  )
                );
              },
            );
          }
      ),
    );
  }
}
