import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/models/service_request/service_request.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/pages/user/requests/request_details.dart';
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
import 'package:test_sa/views/widgets/loaders/no_item_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, this.requests, this.nextPage, this.onLazyLoad}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    Subtitle _subtitle = AppLocalization.of(context).subtitle;
    if(requests.length == 0){
      return NoItemFound(message: _subtitle.noServiceRequestFound,);
    }
    return LazyLoading(
      nextPage: nextPage,
      onLazyLoad: onLazyLoad,
      child: ListView.builder(
        //physics: BouncingScrollPhysics(),
        itemCount: requests.length,
        padding: EdgeInsets.symmetric(horizontal: 16,vertical: 8),
          itemBuilder: (context,itemIndex){
            return ServiceRequestItem(
              index: itemIndex,
              request: requests[itemIndex],
              onPressed: (request){
                Navigator.of(context).push(
                  MaterialPageRoute(
                      builder: (_)=> RequestDetailsPage(serviceRequest: request,)
                  )
                );
              },
            );
          }
      ),
    );
  }
}
