import 'package:flutter/material.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/new_models/dashboard_detail.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/pages/land_page/requests/asset_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 RequestCategoryList extends StatelessWidget {
  final List<Data> list;
  final int totalCount;
  final bool isLoading;

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

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemCount: list.length < totalCount ? list.length + 1 : list.length,
      shrinkWrap: true,
      padding: const EdgeInsets.all(16),
      physics: const NeverScrollableScrollPhysics(),
      separatorBuilder: (cxt, index) => 16.height,
      itemBuilder: (context, index) {
        if (index == list.length) {
          return const CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 1).center;
        }
        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;

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