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/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 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) {
    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);
      default:
        return Container(
          height: 100,
          width: double.infinity,
          color: Colors.grey,
        );
    }
  }
}
