
import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/models/service_request/service_request.dart';
import 'package:test_sa/views/pages/user/requests/service_request_details.dart';
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
import 'package:test_sa/views/widgets/requests/service_request_item.dart';

class ServiceRequestsList extends StatelessWidget {
  final List<ServiceRequest> requests;
  final bool nextPage;
  final Future<void> Function() onLazyLoad;

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

  @override
  Widget build(BuildContext context) {
    print('servies request page');
    if (requests.isEmpty) {
      return NoDataFound(
        message: context.translation.noServiceRequestFound,
      );
    }
    return LazyLoading(
      nextPage: nextPage,
      onLazyLoad: onLazyLoad,
      child: ListView.separated(
          //physics: BouncingScrollPhysics(),
          itemCount: requests.length,
          padding: const EdgeInsets.all(16),
          separatorBuilder: (cxt, index) => 8.height,
          itemBuilder: (context, itemIndex) {
            return ServiceRequestItem(
              index: itemIndex,
              request: requests[itemIndex],
              onPressed: (request) {
                Navigator.of(context).push(MaterialPageRoute(
                    builder: (_) => ServiceRequestDetailsPage(
                          serviceRequest: request,
                        )));
              },
            );
          }),
    );
  }
}
