import 'package:flutter/material.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/models/new_models/dashboard_detail.dart';
import 'package:test_sa/modules/asset_delivery_module/pages/asset_delivery_item_view.dart';
import 'package:test_sa/modules/cleaner_module/widgets/one_time_task_item_view.dart';
import 'package:test_sa/modules/demo_module/demo_request_item_view.dart';
import 'package:test_sa/modules/incident_module/incident_item_view.dart';
import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/equipment_internal_audit_item_view.dart';
import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_item_view.dart';
import 'package:test_sa/modules/asset_inventory_module/pages/inventory_session_item_view.dart';
import 'package:test_sa/modules/loan_module/pages/loan_equipment_item_view.dart';
import 'package:test_sa/modules/medical_gas_inspection/medical_gas_inspection_item_view.dart';
import 'package:test_sa/modules/tm_module/tasks/task_request_item_view.dart';
import 'package:test_sa/modules/traf_module/traf_request_item_view.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/pages/land_page/requests/device_item_view.dart';
import 'package:test_sa/new_views/pages/land_page/requests/gas_refill_item_view.dart';
import 'package:test_sa/new_views/pages/land_page/requests/ppm_item_view.dart';
import 'package:test_sa/new_views/pages/land_page/requests/recurrent_wo_item_view.dart';
import 'package:test_sa/new_views/pages/land_page/requests/service_request_item_view.dart';

class RequestPaginatedListview extends StatelessWidget {
  final List<Data> list;
  final int totalCount;
  final bool isLoading;
  ScrollController scrollController;

  RequestPaginatedListview(this.list, this.isLoading, this.totalCount, this.scrollController, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemCount: list.length < totalCount ? list.length + 1 : list.length,
      controller: scrollController,
      shrinkWrap: true,
      padding: const EdgeInsets.all(16),
      separatorBuilder: (cxt, index) => 16.height,
      itemBuilder: (context, index) {
        if (index == list.length) {
          return const ListTile(
            title: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                CircularProgressIndicator(
                  color: AppColor.primary10,
                  strokeWidth: 1,
                ),
              ],
            ),
          );
        }
        return _buildRequestItem(list[index]);
      },
    );
  }

  Widget _buildRequestItem(Data request) {
    switch (request.transactionNo) {
      case 1:
        return ServiceRequestItemView(requestData: request);
      case 2:
        return GasRefillItemView(requestData: request);
      case 3:
        return DeviceItemView(requestData: request);
      case 4:
        return PpmItemView(requestData: request);
      case 5:
        return RecurrentWoItemView(requestData: request);
      case 6:
        return TaskRequestItemView(requestData: request);
      case 7:
        return TaskRequestItemView(requestData: request);
      case 8:
        return InventorySessionItemView(requestData: request);
      case 9:
        return TrafRequestItemView(requestData: request);
      case 10:
        return EquipmentInternalAuditItemView(requestData: request);
      case 11:
        return SystemInternalAuditItemView(requestData: request);
      case 12:
        return LoanEquipmentItemView(requestData: request);
      case 13:
        return AssetDeliveryItemView(requestData: request);
      case 14:
        return MedicalGasInspectionItemView(requestData: request);
      case 15:
        return DemoRequestItemView(requestData: request);
      case 16:
        return IncidentItemView(requestData: request);
      case 17:
        return OneTimeTaskItemView(requestData: request);
      default:
        return Container(
          height: 100,
          width: double.infinity,
          color: Colors.grey,
        );
    }
  }
}
