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/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/service_request_item_view.dart';
import 'package:test_sa/views/widgets/loaders/no_item_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)
        ? NoItemFound(message: context.translation.noDataFound)
        : ListView.separated(
            padding: const EdgeInsets.all(16),
            itemBuilder: (cxt, index) {
              if (isLoading) return const SizedBox().toRequestShimmer(cxt, isLoading);
              bool isServiceRequest = list[index].nameOfType == "ServiceRequest";
              bool isGasRefill = list[index].nameOfType == "GasRefill";
              bool isAssetTransfer = list[index].nameOfType == "AssetTransfer";
              bool isPPMs = list[index].nameOfType == "PPMs";

              return isServiceRequest
                  ? ServiceRequestItemView(list[index])
                  : isGasRefill
                      ? GasRefillItemView(list[index])
                      : isPPMs
                          ? PpmItemView(list[index])
                          : isAssetTransfer
                              ? AssetItemView(list[index])
                              : Container(
                                  height: 100,
                                  width: double.infinity,
                                  color: Colors.grey,
                                );
            },
            separatorBuilder: (cxt, index) => 8.height,
            itemCount: isLoading ? 6 : list.length);
  }
}
