import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.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_data_found.dart';

import '../../../models/new_models/gas_refill_model.dart';

class GasRefillList extends StatefulWidget {
  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
  State<GasRefillList> createState() => _GasRefillListState();
}

class _GasRefillListState extends State<GasRefillList> {
  @override
  Widget build(BuildContext context) {
    if (widget.items.isEmpty) {
      return NoDataFound(
        message: context.translation.noServiceRequestFound,
      );
    }
    return LazyLoading(
      nextPage: widget.nextPage,
      onLazyLoad: widget.onLazyLoad,
      child: ListView.builder(
          //physics: const BouncingScrollPhysics(),
          itemCount: widget.items.length,
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
          itemBuilder: (context, itemIndex) {
            return GasRefillItem(
              index: itemIndex,
              item: widget.items[itemIndex],
              onPressed: (model) {
                Navigator.of(context).push(MaterialPageRoute(builder: (_) => GasRefillDetailsPage(model: model))).then((value) {
                  model = value;
                  setState(() {});
                });
              },
            );
          }),
    );
  }
}
