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/tm_module/tasks_wo/task_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) {
    bool isServiceRequest = request.transactionNo == 1;
    bool isGasRefill = request.transactionNo == 2;
    bool isAssetTransfer = request.transactionNo == 3;
    bool isPPMs = request.transactionNo == 4;
    bool isRecurrentTask = request.transactionNo == 5;
    bool isTask = request.transactionNo == 6;

    if (isServiceRequest) {
      return ServiceRequestItemView(requestData: request, refreshData: false);
    } else if (isGasRefill) {
      return GasRefillItemView(requestData: request);
    } else if (isPPMs) {
      return PpmItemView(requestData: request);
    } else if (isAssetTransfer) {
      return DeviceItemView(requestData: request);
    } else if (isRecurrentTask) {
      return RecurrentWoItemView(requestData: request);
    } else if (isTask) {
      return TaskRequestItemView(requestData: request);
    } else {
      return Container(
        height: 100,
        width: double.infinity,
        color: Colors.grey,
      );
    }
  }
}

// return  Column(
//       mainAxisSize: MainAxisSize.min,
//       children: List.generate(isLoading ? 6 : list.length, (index) {
//         // if (isLoading) {
//         //  return const SizedBox().toRequestShimmer(context, isLoading);
//         // }
//         // else {
//           return Padding(
//             padding: EdgeInsets.symmetric(vertical: 10.toScreenHeight),
//               child: _buildRequestItem(list[index]));
//         // }
//       }));
