import 'package:flutter/material.dart';

import '../../../controllers/localization/localization.dart';
import '../../../models/device/device_transfer.dart';
import '../../../models/subtitle.dart';
import '../../pages/device_transfer/device_transfer_details.dart';
import '../loaders/lazy_loading.dart';
import '../loaders/no_item_found.dart';
import 'device_transfer_item.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 ?? 0) == 0) {
      Subtitle? subtitle = AppLocalization.of(context)?.subtitle;
      return NoItemFound(
        message: subtitle?.noServiceRequestFound ?? "",
      );
    }
    return LazyLoading(
      nextPage: nextPage ?? false,
      onLazyLoad: onLazyLoad ?? () async {},
      onLoadingEnd: () {},
      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) {
                Navigator.of(context).push(MaterialPageRoute(
                    builder: (_) => DeviceTransferDetails(
                          model: model,
                        )));
              },
            );
          }),
    );
  }
}
