import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/device/asset_transfer.dart';
import 'package:test_sa/views/pages/device_transfer/device_transfer_details.dart';
import 'package:test_sa/views/widgets/device_trancfer/device_transfer_item.dart';
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';

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

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

  @override
  Widget build(BuildContext context) {
    if (items.isEmpty) {
      return NoDataFound(
        message: context.translation.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 DeviceTransferItem(
              index: itemIndex,
              item: items[itemIndex],
              onPressed: (model) async {
                Navigator.of(context).push(MaterialPageRoute(builder: (_) => DeviceTransferDetails(model: model)));
              },
            );
          }),
    );
  }
}
