//request tab page
import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/all_requests_and_count_model.dart';
import 'package:test_sa/modules/tm_module/tasks_wo/task_request_item_view.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';
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';

class RequestItemViewList extends StatelessWidget {
  List<RequestsDetails> list;
  bool isLoading;

  RequestItemViewList(this.list, this.isLoading, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return (list.isEmpty && !isLoading)
        ? NoDataFound(message: context.translation.noDataFound).center
        : ListView.separated(
            padding: const EdgeInsets.all(16),
            shrinkWrap: true,
            itemBuilder: (cxt, index) {
              if (isLoading) return const SizedBox().toRequestShimmer(cxt, isLoading);
              switch (list[index].transactionType) {
                case 1:
                  return ServiceRequestItemView(requestDetails: list[index]);
                case 2:
                  return GasRefillItemView(requestDetails: list[index]);
                case 3:
                  return DeviceItemView(requestDetails: list[index]);
                case 4:
                  return PpmItemView(requestDetails: list[index]);
                case 5:
                  return RecurrentWoItemView(requestDetails: list[index]);
                case 6:
                  return TaskRequestItemView(requestDetails: list[index]);
                default:
                  Container(
                    height: 100,
                    width: double.infinity,
                    color: Colors.grey,
                  );
              }
            },
            separatorBuilder: (cxt, index) => 16.height,
            itemCount: isLoading ? 6 : list.length);
  }
}
