import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/models/device/device_transfer.dart';
import 'package:test_sa/models/subtitle.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_item_found.dart';

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

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

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