import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rasadyar_chicken/data/models/response/allocated_made/allocated_made.dart';
import 'package:rasadyar_chicken/data/models/response/guild/guild_model.dart';
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
import 'package:rasadyar_chicken/presentation/utils/string_utils.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_chicken/presentation/widget/steward/inventory_widget.dart';
import 'package:rasadyar_core/core.dart';

import 'logic.dart';

class SalesInProvincePage extends GetView<SalesInProvinceLogic> {
  SalesInProvincePage({super.key});

  @override
  Widget build(BuildContext context) {
    return ChickenBasePage(
      routes: controller.routesName,
      backId: stewardSecondKey,
      onSearchChanged: (data) => controller.setSearchValue(data),
      onRefresh: controller.onRefresh,
      onFilterTap: () {
        Get.bottomSheet(filterBottomSheet());
      },
      child: Stack(
        children: [
          Positioned.fill(
            child: Column(
              children: [
                inventoryWidget(controller.rootLogic),
                Expanded(
                  child: ObxValue((data) {
                    return RPaginatedListView(
                      listType: ListType.separated,
                      resource: data.value,
                      hasMore: data.value.data?.next != null,
                      isPaginating: controller.isLoadingMoreAllocationsMade.value,
                      onLoadMore: () async {
                        controller.currentPage.value++;
                        iLog(controller.currentPage.value);
                        await controller.getAllocatedMade(true);
                      },
                      padding: EdgeInsets.fromLTRB(8, 8, 8, 80),
                      itemBuilder: (context, index) {
                        var item = data.value.data!.results![index];
                        return ObxValue((val) {
                          return ExpandableListItem2(
                            selected: val.value == index,
                            onTap: () => controller.toggleExpansion(index: index),
                            index: index,
                            child: itemListWidget(item),
                            secondChild: itemListExpandedWidget(item, index),
                            labelColor: AppColor.blueLight,
                            labelIcon: Assets.vec.timerSvg.path,
                            labelIconColor: item.registrationCode == null
                                ? AppColor.darkGreyDark
                                : AppColor.error,
                          );
                        }, controller.expandedListIndex);
                      },
                      itemCount: data.value.data?.results?.length ?? 0,
                      separatorBuilder: (context, index) => SizedBox(height: 8.h),
                    );
                  }, controller.allocatedList),
                ),
              ],
            ),
          ),
          Positioned(
            right: 5,
            bottom: 95,
            child: SizedBox(
              width: Get.width - 30,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RFab.add(
                    onPressed: () {
                      Get.bottomSheet(
                        addOrEditBottomSheet(),
                        isScrollControlled: true,
                        backgroundColor: Colors.transparent,
                      ).whenComplete(() {
                        controller.clearForm();
                      });
                    },
                  ),

                  ObxValue((data) {
                    return Visibility(
                      visible: (data.value.data?.results?.length ?? 0) > 1,
                      child: AnimatedFab(
                        onPressed: () async {
                          Get.defaultDialog(
                            title: 'تایید یکجا',
                            middleText: 'آیا از تایید تمامی تخصیص ها اطمینان دارید؟',
                            confirm: ElevatedButton(
                              onPressed: () async {
                                await controller.confirmAllAllocations();
                                controller.getAllocatedMade();
                                controller.rootLogic.getInventory();
                                Get.back();
                              },
                              child: Text('تایید'),
                              style: ElevatedButton.styleFrom(
                                backgroundColor: AppColor.blueNormal,
                                foregroundColor: Colors.white,
                                shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(8),
                                ),
                              ),
                            ),
                            cancel: OutlinedButton(
                              style: OutlinedButton.styleFrom(
                                foregroundColor: AppColor.error,
                                enableFeedback: true,
                                side: BorderSide(color: AppColor.error, width: 1),
                                shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(8),
                                ),
                              ),
                              onPressed: () {
                                Get.back();
                              },
                              child: Text('لغو'),
                            ),
                          );
                        },
                        message: 'تایید یکجا',
                        icon: Assets.vec.clipboardTaskSvg.svg(width: 40.w, height: 40.h),
                        backgroundColor: controller.bgConfirmAllColor.value,
                      ),
                    );
                  }, controller.allocatedList),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Row itemListWidget(AllocatedMadeModel item) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        SizedBox(width: 20),
        Expanded(
          flex: 2,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            spacing: 4,
            children: [
              Text(
                controller.getBuyerInformation(item)?.user?.fullname ?? 'N/Aشششش',
                textAlign: TextAlign.center,
                style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
              ),

              SizedBox(height: 2),
              Text(
                item.createDate?.formattedJalaliDate ?? 'N/A',
                textAlign: TextAlign.center,
                style: AppFonts.yekan14.copyWith(color: AppColor.bgDark),
              ),
            ],
          ),
        ),
        Expanded(
          flex: 3,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                spacing: 6,
                children: [
                  Visibility(
                    visible: item.product?.name?.contains('مرغ گرم') ?? false,
                    child: Assets.vec.hotChickenSvg.svg(
                      width: 24,
                      height: 24,
                      colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
                    ),
                  ),
                  Text(
                    '${item.weightOfCarcasses?.separatedByCommaFa}kg',
                    textAlign: TextAlign.left,
                    style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
                  ),
                ],
              ),
              SizedBox(height: 2),
              Text(
                '${item.amount.separatedByCommaFa} ریال',
                textAlign: TextAlign.center,
                style: AppFonts.yekan12.copyWith(color: AppColor.darkGreyDark),
              ),
            ],
          ),
        ),

        SizedBox(width: 8),

        Expanded(
          flex: 1,
          child: Assets.vec.scanSvg.svg(
            width: 32.w,
            height: 32.h,
            colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
          ),
        ),
      ],
    );
  }

  Container itemListExpandedWidget(AllocatedMadeModel item, int index) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
      child: Column(
        spacing: 8,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text(
                controller.getBuyerInformation(item)?.user?.fullname ?? 'N/A',
                textAlign: TextAlign.center,
                style: AppFonts.yekan16.copyWith(color: AppColor.greenDark),
              ),
              Spacer(),
              Text(
                item.registrationCode == null ? 'در انتظار' : 'در انتظار تایید خریدار',
                textAlign: TextAlign.center,
                style: AppFonts.yekan10.copyWith(
                  color: item.registrationCode == null ? AppColor.darkGreyDark : AppColor.error,
                ),
              ),
              SizedBox(width: 7),
              Assets.vec.clockSvg.svg(
                width: 16.w,
                height: 16.h,
                colorFilter: ColorFilter.mode(
                  item.registrationCode == null ? AppColor.darkGreyDark : AppColor.error,
                  BlendMode.srcIn,
                ),
              ),
            ],
          ),
          Container(
            height: 32,
            padding: EdgeInsets.symmetric(horizontal: 8),
            decoration: ShapeDecoration(
              color: AppColor.blueLight,
              shape: RoundedRectangleBorder(
                side: BorderSide(width: 1, color: AppColor.blueLightHover),
                borderRadius: BorderRadius.circular(8),
              ),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  spacing: 3,
                  children: [
                    Text(
                      item.date?.toJalali.formatter.wN ?? 'N/A',
                      style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
                    ),

                    Text(
                      '${item.date?.toJalali.formatter.d} ${item.date?.toJalali.formatter.mN ?? 'N/A'}',
                      style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
                    ),
                  ],
                ),

                Text(
                  '${item.date?.toJalali.formatter.y}',
                  style: AppFonts.yekan20.copyWith(color: AppColor.textColor),
                ),

                Text(
                  '${item.date?.toJalali.formatter.tHH}:${item.date?.toJalali.formatter.tMM ?? 'N/A'}',
                  style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
                ),
              ],
            ),
          ),

          /*     buildRow(
            title: 'مشخصات خریدار',
            value: controller.getBuyerInformation(item)?.user?.fullname ?? 'N/A',
          ),*/
          buildRow(
            title: 'تلفن خریدار',
            value: controller.getBuyerInformation(item)?.user?.mobile ?? 'N/A',
            valueStyle: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
          ),
          buildRow(title: 'نوع فروش', value: item.sellType?.faItem ?? 'N/A'),
          buildRow(title: 'محصول', value: item.product?.name ?? 'N/A'),
          buildRow(title: 'نوع تخصیص', value: item.allocationType?.faAllocationType ?? 'N/A'),
          buildRow(
            title: 'وزن خریداری شده',
            value: '${item.weightOfCarcasses?.separatedByCommaFa} کیلوگرم',
          ),
          buildRow(
            title: 'افت وزن(کیلوگرم)',
            value: item.weightLossOfCarcasses?.toInt().toString() ?? 'N/A',
          ),
          buildRow(title: 'قیمت کل', value: '${item.totalAmount?.separatedByCommaFa} ریال'),

          buildRow(title: 'کداحراز', value: item.registrationCode?.toString() ?? 'ندارد'),
          buildRow(
            title: 'وضعیت کد احراز',
            value: item.systemRegistrationCode == true ? "ارسال شده" : "ارسال نشده",
          ),

          Visibility(
            visible: item.registrationCode == null,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              spacing: 16.w,
              children: [
                RElevated(
                  text: 'ویرایش',
                  width: 150.w,
                  height: 40.h,
                  onPressed: () {
                    controller.setEditData(item);
                    Get.bottomSheet(
                      addOrEditBottomSheet(true),
                      isScrollControlled: true,
                      backgroundColor: Colors.transparent,
                    ).whenComplete(() {
                      controller.clearForm();
                    });
                  },
                  textStyle: AppFonts.yekan20.copyWith(color: Colors.white),
                  backgroundColor: AppColor.greenNormal,
                ),
                ROutlinedElevated(
                  text: 'حذف',
                  textStyle: AppFonts.yekan20.copyWith(color: AppColor.redNormal),
                  width: 150.w,
                  height: 40.h,
                  onPressed: () {
                    buildDeleteDialog(
                      onConfirm: () async {
                        controller.toggleExpansion(index: index);

                        await controller.deleteAllocation(item);
                      },
                      onRefresh: controller.onRefresh,
                    );
                  },
                  borderColor: AppColor.redNormal,
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget addOrEditBottomSheet([bool isEditMode = false]) {
    return BaseBottomSheet(
      height: Get.height * (isEditMode ? 0.55 : 0.75),
      child: Form(
        key: controller.formKey,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              '${isEditMode ? 'ویرایش' : 'ثبت'} توزیع/ فروش',
              style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
            ),
            const SizedBox(height: 12),
            productDropDown(),
            const SizedBox(height: 12),
            Visibility(
              visible: isEditMode == false,
              child: Container(
                padding: EdgeInsets.all(8),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8),
                  border: Border.all(color: AppColor.darkGreyLight, width: 1),
                ),

                child: Column(
                  children: [
                    const SizedBox(height: 8),
                    SizedBox(
                      height: 40,
                      child: ObxValue((data) {
                        return RadioGroup(
                          groupValue: controller.saleType.value,
                          onChanged: (value) {
                            controller.saleType.value = value!;
                            controller.selectedGuildModel.value = null;
                            controller.selectedGuildModel.refresh();
                          },
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Radio(value: 1),
                              Text('فروش اختصاصی', style: AppFonts.yekan14),
                              SizedBox(width: 30.w),
                              Radio(value: 2),
                              Text('فروش آزاد', style: AppFonts.yekan14),
                            ],
                          ),
                        );
                      }, controller.saleType),
                    ),
                    const SizedBox(height: 12),

                    guildsDropDown(),
                  ],
                ),
              ),
            ),
            const SizedBox(height: 12),
            Container(
              padding: EdgeInsets.all(8),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(8),
                border: Border.all(color: AppColor.darkGreyLight, width: 1),
              ),
              child: Column(
                spacing: 12,
                children: [
                  Visibility(
                    visible: isEditMode == false,
                    child: Column(
                      children: [
                        const SizedBox(height: 8),
                        ObxValue((data) {
                          return RTextField(
                            controller: TextEditingController(),
                            filledColor: AppColor.bgLight,
                            filled: true,
                            label: 'تاریخ',
                            onTap: () {
                              Get.bottomSheet(
                                modalDatePicker((value) {
                                  controller.fromDateFilter.value = value;
                                  controller.fromDateFilter.refresh();
                                }),
                              );
                            },
                            borderColor: AppColor.darkGreyLight,
                            initText: (data.value ?? Jalali.now()).formatCompactDate(),
                          );
                        }, controller.fromDateFilter),
                      ],
                    ),
                  ),

                  RTextField(
                    controller: controller.weightController,
                    keyboardType: TextInputType.number,
                    borderColor: AppColor.darkGreyLight,
                    filledColor: AppColor.bgLight,
                    filled: true,
                    inputFormatters: [
                      FilteringTextInputFormatter.digitsOnly,
                      SeparatorInputFormatter(),
                    ],
                    validator: (value) {
                      if (int.parse(value!.clearComma) >
                          (controller.rootLogic.inventoryModel.value?.totalRemainWeight?.toInt() ??
                              100)) {
                        return 'وزن تخصیصی بیشتر از موجودی انبار است';
                      }
                      return null;
                    },
                    onChanged: (p0) {
                      controller.weight.value = int.tryParse(p0.clearComma) ?? 0;
                    },
                    label: 'وزن لاشه (کیلوگرم)',
                  ),

                  Obx(() {
                    return RadioGroup(
                      groupValue: controller.priceType.value,
                      onChanged: (value) {
                        controller.priceType.value = value!;
                      },
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Radio(value: 1),
                          Text('قیمت مصوب', style: AppFonts.yekan14),

                          SizedBox(width: 30.w),

                          Radio(value: 2),
                          Text('قیمت آزاد', style: AppFonts.yekan14),
                        ],
                      ),
                    );
                  }),

                  Obx(() {
                    return RadioGroup(
                      groupValue: controller.quotaType.value,
                      onChanged: (value) {
                        controller.quotaType.value = value!;
                      },
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Radio(value: 1),
                          Text('انبار دولتی', style: AppFonts.yekan14),

                          SizedBox(width: 30.w),

                          Radio(value: 2),
                          Text('انبار آزاد', style: AppFonts.yekan14),
                        ],
                      ),
                    );
                  }),

                  Obx(() {
                    return Visibility(
                      visible: controller.broadcastPrice.value?.active == true,
                      child: RTextField(
                        variant: RTextFieldVariant.noBorder,
                        controller: controller.pricePerKiloController,
                        borderColor: AppColor.darkGreyLight,
                        inputFormatters: [
                          FilteringTextInputFormatter.digitsOnly,
                          SeparatorInputFormatter(),
                        ],
                        filledColor: AppColor.bgLight,
                        filled: true,
                        enabled: (controller.priceType.value == 2),
                        onChanged: (p0) {
                          controller.pricePerKilo.value = int.tryParse(p0.clearComma) ?? 0;
                        },
                        keyboardType: TextInputType.number,
                        label: 'قیمت هر کیلو (ريال)',
                      ),
                    );
                  }),

                  RTextField(
                    variant: RTextFieldVariant.noBorder,
                    enabled: false,
                    keyboardType: TextInputType.number,
                    filledColor: AppColor.bgLight,
                    filled: true,
                    inputFormatters: [
                      FilteringTextInputFormatter.digitsOnly,
                      SeparatorInputFormatter(),
                    ],
                    controller: controller.totalCostController,
                    label: 'هزینه کل (ريال)',
                  ),

                  ObxValue((data) {
                    return RElevated(
                      text: isEditMode ? 'ویرایش' : 'ثبت',
                      isFullWidth: true,
                      textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
                      backgroundColor: AppColor.greenNormal,
                      height: 40,
                      enabled: data.value,
                      onPressed: isEditMode
                          ? () async {
                              await controller.updateAllocation();
                              Get.back();
                            }
                          : () async {
                              await controller.submitAllocation();
                              Get.back();
                            },
                    );
                  }, controller.isValid),
                ],
              ),
            ),
            const SizedBox(height: 20),
          ],
        ),
      ),
    );
  }

  Widget guildsDropDown() {
    return Obx(() {
      final item = controller.selectedGuildModel.value;
      return OverlayDropdownWidget<GuildModel>(
        key: ValueKey(item?.user?.fullname ?? ''),
        items: controller.guildsModel,
        onChanged: (value) {
          controller.selectedGuildModel.value = value;
        },
        selectedItem: item,
        itemBuilder: (item) => Text(
          item.user != null
              ? '${item.steward == true ? 'مباشر' : 'صنف'} ${item.user!.fullname} (${item.user!.mobile})'
              : 'بدون نام',
        ),
        labelBuilder: (item) => Text(
          item?.user != null
              ? '${item?.steward == true ? 'مباشر' : 'صنف'} ${item?.user!.fullname} (${item?.user!.mobile})'
              : 'انتخاب مباشر/صنف',
        ),
      );
    });
  }

  Widget productDropDown() {
    return Obx(() {
      return OverlayDropdownWidget<ProductModel>(
        items: controller.rolesProductsModel,
        height: 56,
        hasDropIcon: false,
        background: Colors.white,
        onChanged: (value) {
          controller.selectedProductModel.value = value;
        },
        selectedItem: controller.selectedProductModel.value,
        itemBuilder: (item) => Text(item.name ?? 'بدون نام'),
        labelBuilder: (item) => Row(
          spacing: 8,
          children: [
            (item?.name?.contains('مرغ گرم') ?? false)
                ? Assets.images.chicken.image(width: 40, height: 40)
                : Assets.vec.placeHolderSvg.svg(width: 40, height: 40),

            Text(item?.name ?? 'انتخاب محصول'),
            Spacer(),
            Text(
              'موجودی:${controller.rootLogic.inventoryModel.value?.totalRemainWeight.separatedByCommaFa ?? 0}',
            ),
          ],
        ),
      );
    });
  }

  Widget filterBottomSheet() {
    return BaseBottomSheet(
      height: 200,
      child: Column(
        spacing: 16,
        children: [
          Text('فیلترها', style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal)),
          Row(
            spacing: 8,
            children: [
              Expanded(
                child: timeFilterWidget(
                  date: controller.fromDateFilter,
                  onChanged: (jalali) => controller.fromDateFilter.value = jalali,
                ),
              ),
              Expanded(
                child: timeFilterWidget(
                  isFrom: false,
                  date: controller.toDateFilter,
                  onChanged: (jalali) => controller.toDateFilter.value = jalali,
                ),
              ),
            ],
          ),
          RElevated(
            text: 'اعمال فیلتر',
            isFullWidth: true,
            backgroundColor: AppColor.greenNormal,
            onPressed: () {
              controller.getAllocatedMade();
              Get.back();
            },
            height: 40,
          ),
        ],
      ),
    );
  }

  GestureDetector timeFilterWidget({
    isFrom = true,
    required Rx<Jalali> date,
    required Function(Jalali jalali) onChanged,
  }) {
    return GestureDetector(
      onTap: () {
        Get.bottomSheet(modalDatePicker((value) => onChanged(value)));
      },
      child: Container(
        height: 35,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          border: Border.all(width: 1, color: AppColor.blueNormal),
        ),
        padding: EdgeInsets.symmetric(horizontal: 11, vertical: 4),
        child: Row(
          spacing: 8,
          children: [
            Assets.vec.calendarSvg.svg(
              width: 24,
              height: 24,
              colorFilter: const ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
            ),
            Text(
              isFrom ? 'از' : 'تا',
              style: AppFonts.yekan16.copyWith(color: AppColor.blueNormal),
            ),
            Expanded(
              child: ObxValue((data) {
                return Text(
                  date.value?.formatCompactDate() ?? Jalali.now().formatCompactDate(),
                  textAlign: TextAlign.center,
                  style: AppFonts.yekan16.copyWith(color: AppColor.lightGreyNormalActive),
                );
              }, date),
            ),
          ],
        ),
      ),
    );
  }

  Container modalDatePicker(ValueChanged<Jalali> onDateSelected) {
    Jalali? tempPickedDate;
    return Container(
      height: 250,
      color: Colors.white,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Container(
            child: Row(
              children: [
                SizedBox(width: 20),
                RElevated(
                  height: 35,
                  width: 70,
                  textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
                  onPressed: () {
                    onDateSelected(tempPickedDate ?? Jalali.now());
                    Get.back();
                  },
                  text: 'تایید',
                ),
                Spacer(),
                RElevated(
                  height: 35,
                  width: 70,
                  backgroundColor: AppColor.error,
                  textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
                  onPressed: () {
                    onDateSelected(tempPickedDate ?? Jalali.now());
                    Get.back();
                  },
                  text: 'لغو',
                ),
                SizedBox(width: 20),
              ],
            ),
          ),
          Divider(height: 0, thickness: 1),
          Expanded(
            child: Container(
              child: PersianCupertinoDatePicker(
                initialDateTime: Jalali.now(),
                mode: PersianCupertinoDatePickerMode.date,
                onDateTimeChanged: (dateTime) {
                  tempPickedDate = dateTime;
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget show2StepAddBottomSheet() {
    return BaseBottomSheet(
      height: Get.height * .39,
      child: Column(
        spacing: 8,
        children: [
          buildRow(
            title: 'تاریخ ثبت',
            value: controller.tmpStewardAllocation?.date?.formattedJalaliDate ?? 'N/A',
          ),
          buildRow(
            title: 'نام و نام خانوادگی خریدار',
            value:
                controller.guildsModel
                    .firstWhere((p0) => p0.key == controller.tmpStewardAllocation?.guildKey)
                    .user
                    ?.fullname ??
                'N/A',
          ),
          buildRow(
            title: 'شماره خریدار',
            value:
                controller.guildsModel
                    .firstWhere((p0) => p0.key == controller.tmpStewardAllocation?.guildKey)
                    .user
                    ?.mobile ??
                'N/A',
          ),

          buildRow(
            title: 'قیمت هر کیلو',
            value: '${controller.tmpStewardAllocation?.amount.separatedByCommaFa ?? 0} ریال ',
          ),
          buildRow(
            title: 'وزن تخصیصی',
            value:
                '${controller.tmpStewardAllocation?.weightOfCarcasses?.toInt().separatedByCommaFa ?? 0} کیلوگرم',
          ),
          buildRow(
            title: 'قیمت کل',
            value: '${controller.tmpStewardAllocation?.totalAmount.separatedByCommaFa ?? 0} ریال',
          ),

          Row(
            spacing: 10,
            children: [
              Expanded(
                child: RElevated(
                  backgroundColor: AppColor.greenNormal,
                  height: 40,
                  text: 'ثبت',
                  textStyle: AppFonts.yekan18.copyWith(color: Colors.white),
                  onPressed: () async {
                    await controller.submitAllocation();
                    Get
                      ..back()
                      ..back();
                  },
                ),
              ),
              Expanded(
                child: ROutlinedElevated(
                  height: 40,
                  borderColor: AppColor.error,
                  text: ' بازگشت',
                  textStyle: AppFonts.yekan18.copyWith(color: AppColor.error),
                  onPressed: () {
                    Get
                      ..back()
                      ..back();
                  },
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
