import 'package:easy_localization/src/public_ext.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/date_uitl.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/get_absence_collection_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_item_creation_ntf_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_po_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_pr_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_stamp_ms_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/get_stamp_ns_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/eit_otification_body_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_address_notification_body_list.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_basic_det_ntf_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_contact_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist/hr/get_phones_notification_body_list_model.dart';
import 'package:mohem_flutter_app/models/worklist_response_model.dart';
import 'package:mohem_flutter_app/widgets/item_detail_view_widget.dart';
import 'package:mohem_flutter_app/models/termination/termination_notification_body.dart';
import 'package:mohem_flutter_app/models/worklist/payment_details_list.dart';

class InfoFragment extends StatelessWidget {
  WorkListResponseModel? workListData;
  List<POHeader> poHeaderList;
  List<GetStampMsNotificationBodyList>? getStampMsNotifications;
  List<GetStampNsNotificationBodyList>? getStampNsNotifications;
  List<ItemCreationHeader> itemCreationHeader;
  List<GetEitCollectionNotificationBodyList>?
  getEitCollectionNotificationBodyList;
  List<GetPhonesNotificationBodyList>? getPhonesNotificationBodyList;
  List<GetBasicDetNtfBodyList>? getBasicDetNtfBodyList;
  List<GetAbsenceCollectionNotificationBodyList>?
  getAbsenceCollectionNotificationBodyList;
  GetContactNotificationBodyList? getContactNotificationBodyList;
  GetPrNotificationBodyList? getPrNotificationBodyList;
  List<GetAddressNotificationBodyList>? getAddressNotificationBodyList = [];
  List<TerminationNotificationBody>? getTerminationNotificationBodyList = [];
  GetPaymentNotificationBodyList? getPaymentNotificationBodyList;

  InfoFragment(
      {this.workListData,
        this.poHeaderList = const <POHeader>[],
        this.itemCreationHeader = const <ItemCreationHeader>[],
        this.getStampMsNotifications,
        this.getStampNsNotifications,
        this.getEitCollectionNotificationBodyList,
        this.getPhonesNotificationBodyList,
        this.getBasicDetNtfBodyList,
        this.getAbsenceCollectionNotificationBodyList,
        this.getContactNotificationBodyList,
        this.getPrNotificationBodyList,
        this.getAddressNotificationBodyList,
        this.getTerminationNotificationBodyList,
        this.getPaymentNotificationBodyList});

  double itemHeight = 0;
  double itemWidth = 0;




  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    itemHeight = (size.height - kToolbarHeight - 24) / 9;
    itemWidth = size.width / 2;

    List<Widget> uiList = [
      if ((workListData?.iTEMTYPE ?? "") == "INVMOA")
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            ItemDetailGrid(
              ItemDetailViewCol(
                  LocaleKeys.from.tr(), workListData!.fROMUSER ?? ""),
              ItemDetailViewCol(LocaleKeys.to.tr(), workListData!.tOUSER ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(
                  LocaleKeys.sent.tr(), workListData!.bEGINDATE ?? ""),
              ItemDetailViewCol(
                  LocaleKeys.closed.tr(), workListData!.eNDDATE ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.id.tr(),
                  workListData!.nOTIFICATIONID?.toString() ?? ""),
              ItemDetailViewCol(
                  LocaleKeys.responder.tr(), workListData!.rESPONDER ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(
                  LocaleKeys.subject.tr(), workListData!.sUBJECT ?? ""),
              Container(),
              isItLast: true,
            ),
          ],
        ).objectContainerView(),
      if (getPrNotificationBodyList != null)
        getPRNotificationBodyListWidget(getPrNotificationBodyList!),
      if (getStampMsNotifications?.isNotEmpty ?? false)
        getStampMsNotificationsListView(getStampMsNotifications ?? []),
      if (getStampNsNotifications?.isNotEmpty ?? false)
        getStampNsNotificationsListView(getStampNsNotifications ?? []),
      if (poHeaderList.isNotEmpty) getPoNotificationsListView(),
      if (itemCreationHeader.isNotEmpty) getItemCreationHeaderView(),
      if (getEitCollectionNotificationBodyList?.isNotEmpty ?? false)
        getEitNotificationsListView(getEitCollectionNotificationBodyList ?? []),
      if (getPhonesNotificationBodyList?.isNotEmpty ?? false)
        getPhonesNotificationBodyListWidget(getPhonesNotificationBodyList ?? [])
            .objectContainerView(title: "Mobile Numbers"),
      if (getBasicDetNtfBodyList?.isNotEmpty ?? false)
        getBasicDetNtfBodyListWidget(getBasicDetNtfBodyList ?? [])
            .objectContainerView(title: "Basic Information"),
      if (getAbsenceCollectionNotificationBodyList?.isNotEmpty ?? false)
        getAbsenceCollectionNotificationBodyListWidget(
            getAbsenceCollectionNotificationBodyList ?? []),
      if (getContactNotificationBodyList != null)
        getContactNotificationBodyListWidget(getContactNotificationBodyList ??
            GetContactNotificationBodyList())
            .objectContainerView(),
      if (getAddressNotificationBodyList?.isNotEmpty ?? false)
        getAddressNotificationBodyListWidget(getAddressNotificationBodyList!),
      if (getTerminationNotificationBodyList?.isNotEmpty ?? false)
        getTerminationNotificationBodyListWidget(
            getTerminationNotificationBodyList!),
      if (getPaymentNotificationBodyList != null)
        getPaymentNotificationBodyListWidget(getPaymentNotificationBodyList ??
            GetPaymentNotificationBodyList())
            .objectContainerView(),
    ];
    return Container(
      width: double.infinity,
      height: double.infinity,
      child: uiList.isEmpty
          ? LocaleKeys.noDataAvailable.tr().toText16().center
          : ListView(
        padding: const EdgeInsets.all(21),
        children: uiList,
      ),
    );
  }

  Widget getPoNotificationsListView() {
    return ListView.separated(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext cxt, int index) => Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            Column(
              children: [
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.description.tr(),
                      workListData!.fROMUSER ?? ""),
                  ItemDetailViewCol(
                      LocaleKeys.from.tr(), workListData!.fROMUSER ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(
                      LocaleKeys.to.tr(), workListData!.tOUSER ?? ""),
                  ItemDetailViewCol(
                      LocaleKeys.sent.tr(), workListData!.bEGINDATE ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(
                      LocaleKeys.closed.tr(), workListData!.eNDDATE ?? ""),
                  ItemDetailViewCol(LocaleKeys.id.tr(),
                      workListData!.nOTIFICATIONID?.toString() ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.supplier.tr(),
                      poHeaderList[index].vENDORNAME ?? ""),
                  ItemDetailViewCol(LocaleKeys.site.tr(),
                      poHeaderList[index].vENDORSITECODE ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.buyer.tr(),
                      poHeaderList[index].bUYER ?? ""),
                  ItemDetailViewCol(LocaleKeys.preparer.tr(),
                      poHeaderList[index].pREPARER ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.creationDate.tr(),
                      poHeaderList[index].cREATIONDATE ?? ""),
                  ItemDetailViewCol(LocaleKeys.shipToLocation.tr(),
                      poHeaderList[index].sHIPTOLOCATIONNAME ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.quotationNumber.tr(),
                      poHeaderList[index].qUOTATIONNUMBER ?? ""),
                  ItemDetailViewCol(LocaleKeys.quotationDate.tr(),
                      poHeaderList[index].qUOTATIONDATE ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.paymentTerms.tr(),
                      poHeaderList[index].pAYMENTTERMS ?? ""),
                  ItemDetailViewCol(LocaleKeys.currency.tr(),
                      poHeaderList[index].cURRENCYNAME ?? ""),
                  isItLast: true,
                ),
              ],
            ).objectContainerView(title: LocaleKeys.infoDetail.tr()),
            12.height,
            Column(
              children: [
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.grossAmount.tr(),
                      poHeaderList[index].gROSSAMOUNT?.toString() ?? ""),
                  ItemDetailViewCol(LocaleKeys.discountAmount.tr(),
                      poHeaderList[index].dISCOUNTAMOUNT?.toString() ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.customDuty.tr(),
                      poHeaderList[index].cUSTOMDUTY?.toString() ?? ""),
                  ItemDetailViewCol(LocaleKeys.shipHandle.tr(),
                      poHeaderList[index].sHIPHANDLE?.toString() ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.otherCharges.tr(),
                      poHeaderList[index].oTHERCHARGES?.toString() ?? ""),
                  ItemDetailViewCol(LocaleKeys.totalPOAmountWithVAT.tr(),
                      poHeaderList[index].lOCCURTOTPOAMT.toString() ?? ""),
                ),
                ItemDetailGrid(
                  ItemDetailViewCol(LocaleKeys.totalPOAmountInWords.tr(),
                      poHeaderList[index].tOTPOAMTWORD ?? ""),
                  Container(),
                  isItLast: true,
                ),
              ],
            ).objectContainerView(title: LocaleKeys.amount_detail.tr()),
          ],
        ),
        separatorBuilder: (BuildContext cxt, int index) => 4.height,
        itemCount: poHeaderList.length);
  }

  // Widget getAbsenceCollectionNotificationsListView(List<GetAbsenceCollectionNotificationBodyList> list) {
  //   List<CollectionNotificationAbsence> dataList = list.isEmpty ? [] : (list.first.collectionNotification ?? []);
  //   return ListView.separated(
  //       shrinkWrap: true,
  //       physics: const NeverScrollableScrollPhysics(),
  //       itemBuilder: (cxt, index) => ItemDetailView(dataList[index].sEGMENTPROMPT!, dataList[index].sEGMENTVALUEDSP!),
  //       separatorBuilder: (cxt, index) => 4.height,
  //       itemCount: dataList.length);
  // }

  Widget getStampMsNotificationsListView(
      List<GetStampMsNotificationBodyList> list) {
    return ListView.separated(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext cxt, int index) => Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.employeeNumber.tr(),
                  list[index].eMPLOYEENUMBER.toString()),
              ItemDetailViewCol(LocaleKeys.assignmentNumber.tr(),
                  list[index].aSSIGNMENTNUMBER.toString()),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.employeeName.tr(),
                  list[index].eMPLOYEENAME.toString()),
              ItemDetailViewCol(
                  LocaleKeys.scheduleDate.tr(),
                  DateUtil.formatDateToDate(
                      DateUtil.convertStringToDate(
                          list[index].sCHEDULEDATE.toString()),
                      false)),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.shiftType.tr(),
                  list[index].sHTTYPEDESC.toString()),
              ItemDetailViewCol(
                  LocaleKeys.shift.tr(), list[index].sHTNAME.toString()),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.breakText.tr(),
                  list[index].bREAKNAME.toString()),
              ItemDetailViewCol(LocaleKeys.actualSwipeStart.tr(),
                  list[index].sHTACTUALSTARTTIME.toString()),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.actualSwipeEnd.tr(),
                  list[index].sHTACTUALENDTIME.toString()),
              ItemDetailViewCol(LocaleKeys.approvedSwipeStart.tr(),
                  list[index].aPPROVEDSTARTTIME.toString()),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.approvedSwipeStartReason.tr(),
                  list[index].aPPROVEDSTARTREASON.toString()),
              ItemDetailViewCol(LocaleKeys.approvedSwipeEnd.tr(), ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.approvedSwipeEndReason.tr(),
                  list[index].aPPROVEDENDREASONDESC.toString()),
              Container(),
              isItLast: true,
            ),
          ],
        ).objectContainerView(),
        separatorBuilder: (BuildContext cxt, int index) =>
            1.height.paddingOnly(top: 8, bottom: 8),
        itemCount: list.length);
  }

  Widget getStampNsNotificationsListView(
      List<GetStampNsNotificationBodyList> list) {
    return ListView.separated(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext cxt, int index) => Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.employeeNumber.tr(),
                  list[index].eMPLOYEENUMBER.toString()),
              ItemDetailViewCol(LocaleKeys.assignmentNumber.tr(),
                  list[index].aSSIGNMENTNUMBER.toString()),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.employeeName.tr(),
                  list[index].eMPLOYEENAME.toString()),
              ItemDetailViewCol(
                  LocaleKeys.scheduleDate.tr(),
                  DateUtil.formatDateToDate(
                      DateUtil.convertStringToDate(
                          list[index].sCHEDULEDATE.toString()),
                      false)),
              isItLast: true,
            ),
          ],
        ).objectContainerView(),
        separatorBuilder: (BuildContext cxt, int index) =>
            1.height.paddingOnly(top: 8, bottom: 8),
        itemCount: list.length);
  }

  Widget getItemCreationHeaderView() {
    return ListView.separated(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext cxt, int index) => Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ItemDetailGrid(
              ItemDetailViewCol(
                  LocaleKeys.operatingUnit.tr(),
                  itemCreationHeader[index].oPERATINGUNIT?.toString() ??
                      ""),
              ItemDetailViewCol(LocaleKeys.category.tr(),
                  itemCreationHeader[index].cATEGORY?.toString() ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.requester.tr(),
                  itemCreationHeader[index].rEQUESTER?.toString() ?? ""),
              ItemDetailViewCol(LocaleKeys.analyzedBy.tr(),
                  itemCreationHeader[index].aNALYZEDBY?.toString() ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.approvedDate.tr(),
                  itemCreationHeader[index].aPPROVEDDATE?.toString() ?? ""),
              ItemDetailViewCol(LocaleKeys.itemType.tr(),
                  itemCreationHeader[index].iTEMTYPE?.toString() ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.relatedTo.tr(),
                  itemCreationHeader[index].rELATEDTO?.toString() ?? ""),
              ItemDetailViewCol(
                  LocaleKeys.requestDate.tr(),
                  DateUtil.formatDateToDate(
                      DateUtil.convertStringToDate(
                          itemCreationHeader[index].rEQUESTDATE.toString()),
                      false)),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.analyzedDate.tr(),
                  itemCreationHeader[index].aNALYZEDDATE?.toString() ?? ""),
              ItemDetailViewCol(
                  LocaleKeys.urgent.tr(),
                  itemCreationHeader[index].uRGENTFLAGDISP?.toString() ??
                      ""),
            ),
          ],
        ).objectContainerView(),
        separatorBuilder: (BuildContext cxt, int index) => 18.height,
        itemCount: itemCreationHeader.length);
  }

  //HR multiple type requests
  Widget getEitNotificationsListView(
      List<GetEitCollectionNotificationBodyList> list) {
    return ListView.separated(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext cxt, int index) {
        List<CollectionNotificationEit> dataList =
        list.isEmpty ? [] : (list[index].collectionNotification ?? []);
        dataList = dataList
            .where((CollectionNotificationEit o) => o.displayFlag == "Y")
            .toList();
        bool isOdd = false;
        if (dataList.length % 2 != 0) {
          isOdd = true;
          dataList.add(new CollectionNotificationEit());
        }
        return GridView.builder(
          itemCount: dataList.length,
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (BuildContext context, int index) =>
              ItemDetailViewGridItem(
                index,
                dataList[index].segmentPrompt,
                dataList[index].segmentValueDsp,
                isNeedToShowEmptyDivider: (dataList.length == index + 1)
                    ? isOdd
                    ? true
                    : false
                    : false,
              ),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: (itemWidth / itemHeight),
          ),
        ).objectContainerView();
      },
      separatorBuilder: (BuildContext cxt, int index) => 12.height,
      itemCount: list.length,
    );
  }

  Widget getPhonesNotificationBodyListWidget(
      List<GetPhonesNotificationBodyList> list) {
    bool isOdd = false;
    if (list.length % 2 != 0) {
      isOdd = true;
      list.add(new GetPhonesNotificationBodyList());
    }
    return GridView.builder(
      itemCount: list.length,
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) => ItemDetailViewGridItem(
        index,
        LocaleKeys.subject.tr(),
        list[index].proposedPhoneNumber ?? "",
        isNeedToShowEmptyDivider: (list.length == index + 1)
            ? isOdd
            ? true
            : false
            : false,
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: (itemWidth / itemHeight),
      ),
    );
    return Container(
      color: Colors.yellow,
      child: ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (BuildContext cxt, int index) => ItemDetailViewCol(
              LocaleKeys.subject.tr(), list[index].proposedPhoneNumber ?? ""),
          separatorBuilder: (BuildContext cxt, int index) => 4.height,
          itemCount: list.length),
    );
  }

  Widget getBasicDetNtfBodyListWidget(List<GetBasicDetNtfBodyList> list) {
    bool isOdd = false;
    if (list.length % 2 != 0) {
      isOdd = true;
      list.add(new GetBasicDetNtfBodyList());
    }
    return GridView.builder(
      itemCount: list.length,
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) => ItemDetailViewGridItem(
        index,
        list[index].segmentPrompt,
        list[index].segmentValueDsp,
        isNeedToShowEmptyDivider: (list.length == index + 1)
            ? isOdd
            ? true
            : false
            : false,
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: (itemWidth / itemHeight),
      ),
    );
    return Container(
      color: Colors.pink,
      child: ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (BuildContext cxt, int index) => ItemDetailViewCol(
              list[index].segmentPrompt!, list[index].segmentValueDsp!),
          separatorBuilder: (BuildContext cxt, int index) => 4.height,
          itemCount: list.length),
    );
  }

  Widget getAbsenceCollectionNotificationBodyListWidget(
      List<GetAbsenceCollectionNotificationBodyList> list) {
    return ListView.separated(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext cxt, int index) {
        List<CollectionNotificationAbsence> dataList =
        list.isEmpty ? [] : (list[index].collectionNotification ?? []);
        dataList = dataList
            .where((CollectionNotificationAbsence o) => o.dISPLAYFLAG == "Y")
            .toList();
        bool isOdd = false;
        if (dataList.length % 2 != 0) {
          isOdd = true;
          dataList.add(new CollectionNotificationAbsence());
        }

        return GridView.builder(
          itemCount: dataList.length,
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (BuildContext context, int index) =>
              ItemDetailViewGridItem(
                index,
                dataList[index].sEGMENTPROMPT,
                dataList[index].sEGMENTVALUEDSP,
                isNeedToShowEmptyDivider: (dataList.length == index + 1)
                    ? isOdd
                    ? true
                    : false
                    : false,
              ),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: (itemWidth / itemHeight),
          ),
        ).objectContainerView();
        return ListView.separated(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemBuilder: (BuildContext cxt, int index) =>
            dataList[index].dISPLAYFLAG == "Y"
                ? ItemDetailViewCol(dataList[index].sEGMENTPROMPT!,
                dataList[index].sEGMENTVALUEDSP!)
                : Container(),
            separatorBuilder: (BuildContext cxt, int index) =>
            dataList[index].dISPLAYFLAG == "Y" ? 4.height : 0.height,
            itemCount: dataList.length)
            .objectContainerView();
      },
      separatorBuilder: (BuildContext cxt, int index) => 12.height,
      itemCount: list.length,
    );
  }

  Widget getPRNotificationBodyListWidget(
      GetPrNotificationBodyList getPrNotificationBodyList) {
    return Column(
      children: [
        getPrNotificationBodyList.pINFORMATION != null
            ? getPrNotificationBodyList.pINFORMATION
            .toString()
            .toText14(color: MyColors.textMixColor)
            .objectContainerView()
            : Container(),
        12.height,
        Column(
          children: [
            ItemDetailGrid(
              ItemDetailViewCol(
                  LocaleKeys.from.tr(), workListData!.fROMUSER ?? ""),
              ItemDetailViewCol(LocaleKeys.to.tr(), workListData!.tOUSER ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(
                  LocaleKeys.sent.tr(), workListData!.bEGINDATE ?? ""),
              ItemDetailViewCol(
                  LocaleKeys.closed.tr(), workListData!.eNDDATE ?? ""),
            ),
            ItemDetailGrid(
              ItemDetailViewCol(LocaleKeys.id.tr(),
                  workListData!.nOTIFICATIONID?.toString() ?? ""),
              ItemDetailViewCol(
                  LocaleKeys.responder.tr(), workListData!.rESPONDER ?? ""),
            ),
            Column(
              children: getPRHeaderValues(),
            )
          ],
        ).objectContainerView(),
      ],
    );
  }

  Widget getAddressNotificationBodyListWidget(
      List<GetAddressNotificationBodyList> getAddressNotificationBodyList) {
    bool isOdd = false;
    try {
      if (getAddressNotificationBodyList.length % 2 != 0) {
        isOdd = true;
        getAddressNotificationBodyList.add(GetAddressNotificationBodyList(
            sEGMENTPROMPT: "--", sEGMENTVALUEDSP: "--"));
      }
    } catch (e) {}

    return GridView.builder(
      itemCount: getAddressNotificationBodyList!.length,
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) => ItemDetailViewGridItem(
        index,
        getAddressNotificationBodyList[index].sEGMENTPROMPT,
        getAddressNotificationBodyList[index].sEGMENTVALUEDSP,
        isNeedToShowEmptyDivider:
        (getAddressNotificationBodyList.length == index + 1)
            ? isOdd
            ? true
            : false
            : false,
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: (itemWidth / itemHeight),
      ),
    ).objectContainerView();
  }

  Widget getTerminationNotificationBodyListWidget(
      List<TerminationNotificationBody> getterminationNotificationBodyList) {
    bool isOdd = false;
    try {
      if (getterminationNotificationBodyList.length % 2 != 0) {
        isOdd = true;
        getterminationNotificationBodyList.add(TerminationNotificationBody(
            sEGMENTPROMPT: "--", sEGMENTVALUEDSP: "--"));
      }
    } catch (e) {}

    return GridView.builder(
      itemCount: getterminationNotificationBodyList!.length,
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) => ItemDetailViewGridItem(
        index,
        getterminationNotificationBodyList[index].sEGMENTPROMPT,
        getterminationNotificationBodyList[index].sEGMENTVALUEDSP,
        isNeedToShowEmptyDivider:
        (getterminationNotificationBodyList.length == index + 1)
            ? isOdd
            ? true
            : false
            : false,
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: (itemWidth / itemHeight),
      ),
    ).objectContainerView();
  }

  List<Widget> getPRHeaderValues() {
    List<Widget> pRHeaders = [];
    getPrNotificationBodyList!.pRHeader!.forEach((PRHeader element) {
      pRHeaders.add(ItemDetailGrid(
          ItemDetailViewCol(
              element.hDRATTRIBUTENAME!, element.hDRATTRIBUTEVALUE!),
          Container()));
    });
    return pRHeaders;
  }

  Widget getContactNotificationBodyListWidget(
      GetContactNotificationBodyList data) {
    bool isOdd = false;
    try {
      if (data.contactNotificationBody!.length % 2 != 0) {
        isOdd = true;
        data.contactNotificationBody!.add(ContactNotificationBody(
            segmentPrompt: "--", segmentValueDsp: "--"));
      }
    } catch (e) {}

    return GridView.builder(
      itemCount: data.contactNotificationBody!.length,
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) => ItemDetailViewGridItem(
        index,
        data.contactNotificationBody![index].segmentPrompt,
        data.contactNotificationBody![index].segmentValueDsp,
        isNeedToShowEmptyDivider:
        (data.contactNotificationBody!.length == index + 1)
            ? isOdd
            ? true
            : false
            : false,
      ),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: (itemWidth / itemHeight),
      ),
    ).objectContainerView();
    return Container(
      color: Colors.orange,
      child: ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (BuildContext cxt, int index) => ItemDetailViewCol(
              data.contactNotificationBody![index].segmentPrompt!,
              data.contactNotificationBody![index].segmentValueDsp!),
          separatorBuilder: (BuildContext cxt, int index) => 4.height,
          itemCount: data.contactNotificationBody!.length),
    );
  }

  Widget getPaymentNotificationBodyListWidget(
      GetPaymentNotificationBodyList? data) {
    return Column(
      children: [
        12.height,
        if (data!.paymentDetailsList!.isNotEmpty)
          Column(
            children: [
              LocaleKeys.paymentDetails.tr().toText14(color: MyColors.textMixColor),
              ItemDetailGrid(
                ItemDetailViewCol(
                    LocaleKeys.requestNumber.tr(), data.paymentDetailsList![0].requestNumber ?? ""),
                ItemDetailViewCol( LocaleKeys.requesterEmpNum.tr(),
                    data.paymentDetailsList![0].requesterEmployeeNumber ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol( LocaleKeys.requestDate.tr(),
                    DateUtil.formatDateToDate(
                        DateUtil.convertStringToDate(data.paymentDetailsList![0].requestDate!), false) ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.requesterEmpName.tr(),  data.paymentDetailsList![0].requesterEmployeeName ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol( LocaleKeys.prepareEmpNum.tr(),
                    data.paymentDetailsList![0].prepareEmployeeNumber ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.requesterPositionName.tr(), data.paymentDetailsList![0].requesterPositionName ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol( LocaleKeys.prepareEmpName.tr(),
                    data.paymentDetailsList![0].prepareEmployeeName ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.requesterPayrollName.tr(), data.paymentDetailsList![0].requesterPayrollName ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol( LocaleKeys.preparePositionName.tr(),
                    data.paymentDetailsList![0].preparePositionName ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.requesterPositionName.tr(), data.paymentDetailsList![0].requesterPositionName ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol( LocaleKeys.prepareEmpName.tr(),
                    data.paymentDetailsList![0].prepareEmployeeName ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.requesterPayrollName.tr(), data.paymentDetailsList![0].requesterPayrollName ?? ""),
              ),
              ItemDetailGrid(
                  ItemDetailViewCol( LocaleKeys.preparePositionName.tr(),
                      data.paymentDetailsList![0].preparePositionName ?? ""),
                  ItemDetailViewCol( LocaleKeys.requesterOperatingUnit.tr(),
                      data.paymentDetailsList![0].requesterOperatingUnits ?? "")
              ),

            ],
          ).objectContainerView(),
        if (data!.paymentDetailsList!.isNotEmpty)
          Column(
            children: [
              LocaleKeys.general.tr().toText14(color: MyColors.textMixColor),
              ItemDetailGrid(
                ItemDetailViewCol(
                    LocaleKeys.payingORGName.tr(), data.paymentDetailsList![0].payingOrganizationName ?? ""),
                ItemDetailViewCol(LocaleKeys.requestAmount.tr(),
                    data.paymentDetailsList![0].requestAmount ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.paymentMethodName.tr(),
                    data.paymentDetailsList![0].paymentMethodName   ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.currency.tr(),  data.paymentDetailsList![0].currency ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.typeofPayment.tr(),
                    data.paymentDetailsList![0].typeOfPayment ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.paymentDetails.tr(), data.paymentDetailsList![0].paymentDetails ?? ""),
              ),

            ],
          ).objectContainerView(),

        if (data!.beneficieryList!.isNotEmpty)
          Column(
            children: [
              LocaleKeys.beneficiaryDetails.tr().toText14(color: MyColors.textMixColor),
              ItemDetailGrid(
                ItemDetailViewCol(
                    LocaleKeys.beneficiaryName.tr(), data.beneficieryList![0].beneficiaryName ?? ""),
                ItemDetailViewCol(LocaleKeys.idIqama.tr(),
                    data.beneficieryList![0].iqamaNumber ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.beneficiaryBankName.tr(),
                    data.beneficieryList![0] .beneficiaryBankName  ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.sadadNumber.tr(),  data.beneficieryList![0].saddadNumber ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.beneficiaryIBAN.tr(),
                    data.beneficieryList![0].beneficiaryIban ?? ""),
                Container(),
              ),

            ],
          ).objectContainerView(),

        if (data!.purchaseOrdersList!.isNotEmpty &&  data.purchaseOrdersList![0].poAmount !=null)
          Column(
            children: [
              LocaleKeys.purchaseOrders.tr().toText14(color: MyColors.textMixColor),
              ItemDetailGrid(
                ItemDetailViewCol(
                    LocaleKeys.poNumber.tr(), data.purchaseOrdersList![0].poNumber ?? ""),
                ItemDetailViewCol(LocaleKeys.pOAmount.tr(),
                    data.purchaseOrdersList![0].poAmount.toString() ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.supplierName.tr(),
                    data.purchaseOrdersList![0].supplierName  ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.approvalDate.tr(), data.purchaseOrdersList![0].poApprovalDate!=null ?  DateUtil.formatDateToDate(
                    DateUtil.convertStringToDate(data.purchaseOrdersList![0].poApprovalDate), false) :"" ),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.requestNumber.tr(),
                    data.purchaseOrdersList![0].prNumber?? ""),
                ItemDetailViewCol(LocaleKeys.versionStatus.tr(),
                    data.purchaseOrdersList![0].versionStatus?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.supplierNo.tr(),
                    data.purchaseOrdersList![0].supplierNumber?? ""),
                Container(),
              ),
            ],
          ).objectContainerView(),

        if (data!.supplierInformationList!.isNotEmpty &&  data.supplierInformationList![0].supplierNumber !="")
          Column(
            children: [
              LocaleKeys.supplierInfo.tr().toText14(color: MyColors.textMixColor),
              ItemDetailGrid(
                ItemDetailViewCol(
                    LocaleKeys.supplierNo.tr(), data.supplierInformationList![0].supplierNumber ?? ""),
                ItemDetailViewCol(LocaleKeys.supplierName.tr(),
                    data.supplierInformationList![0].supplierName.toString() ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.supplierAcNo.tr(),
                    data.supplierInformationList![0].supplierBankAccountNumber  ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.supplierAcName.tr(), data.supplierInformationList![0].supplierBankAccountName ??
                    "" ),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.supplierCRNo.tr(),
                    data.supplierInformationList![0].crNumber?? ""),
                ItemDetailViewCol(  LocaleKeys.supplierIBAN.tr(), data.supplierInformationList![0].supplierBankIban ??
                    "" ),
              ),

            ],
          ).objectContainerView(),
        //
        if (data!.refundInvoiceList!.isNotEmpty &&  data.refundInvoiceList![0].patientNumber !="" )
          Column(
            children: [
              LocaleKeys.patientRefundInvoice.tr().toText14(color: MyColors.textMixColor),
              ItemDetailGrid(
                ItemDetailViewCol(
                    LocaleKeys.patientNumber.tr(), data.refundInvoiceList![0].patientNumber?? ""),
                ItemDetailViewCol(LocaleKeys.hospitalClinic.tr(),
                    data.refundInvoiceList![0].hospitalClinic.toString() ?? ""),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.patientName.tr(),
                    data.refundInvoiceList![0].patientName  ?? ""),
                ItemDetailViewCol(
                    LocaleKeys.amount.tr(), data.refundInvoiceList![0].amount.toString() ??
                    "" ),
              ),
              ItemDetailGrid(
                ItemDetailViewCol(LocaleKeys.invoiceDate.tr(),
    DateUtil.formatDateToDate(
    DateUtil.convertStringToDate( data.refundInvoiceList![0].invoicedDate), false)?? ""),

                ItemDetailViewCol(  LocaleKeys.refundInvoice.tr(), data.refundInvoiceList![0].invoiceNumber ??
                    "" ),
              ),

            ],
          ).objectContainerView(),

       ],

    );
  }
}
