import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart' hide BasePage;
import 'package:rasadyar_livestock/presentation/widgets/base_page/view.dart';

import 'logic.dart';

class RequestTaggingPage extends GetView<RequestTaggingLogic> {
  const RequestTaggingPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: 'درخواست پلاک کوبی',
      hasSearch: false,
      hasFilter: false,
      hasBack: true,
      avoidBottomInset: false,
      widgets: [
        ObxValue((index) {
          return Expanded(
            child: Padding(padding: const EdgeInsets.all(8.0), child: _buildStep(index.value)),
          );
        }, controller.currentIndex),

        nextOrPreviousWidget(),
        SizedBox(height: 10.h),
      ],
    );
  }

  Widget nextOrPreviousWidget() {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        spacing: 10,
        children: [
          ObxValue(
            (data) => Expanded(
              flex: 2,
              child: RElevated(
                height: 40.h,
                enabled: data.value,
                onPressed: controller.onNext,
                isLoading: controller.isLoading.value,
                child: Text(controller.currentIndex.value == 2 ? 'ثبت' : 'بعدی'),
                backgroundColor: AppColor.blueNormal,
              ),
            ),
            controller.nextButtonEnabled,
          ),
          Expanded(
            child: ObxValue((data) {
              return ROutlinedElevated(
                enabled: data.value > 0,
                onPressed: controller.onPrevious,
                child: Text('قبلی'),
                borderColor: AppColor.error,
              );
            }, controller.currentIndex),
          ),
        ],
      ),
    );
  }

  Widget _buildStep(int index) {
    switch (index) {
      case 0:
        return firstStepWidget();
      case 1:
        return secondStepWidget();
      case 2:
        return thirdStepWidget();
      default:
        return Center(
          child: Text(
            'مرحله $index در دست توسعه است',
            style: AppFonts.yekan16.copyWith(color: AppColor.redNormal),
            textDirection: TextDirection.rtl,
          ),
        );
    }
  }

  //TODO
  Future<void> showCropDialog() async {
    await Get.dialog(
      Dialog(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Text(
              'آیا نیازی به برش تصویر دارید؟',
              style: AppFonts.yekan16Bold,
              textAlign: TextAlign.center,
            ),

            const SizedBox(height: 24),

            Row(
              spacing: 12.w,
              children: [
                RElevated(
                  width: 150.w,
                  height: 40.h,
                  onPressed: () async {
                    Get.back();
                    await controller.cropImage();
                  },
                  child: const Text('بله'),
                ),
                ROutlinedElevated(
                  width: 150.w,
                  onPressed: () => Get.back(),
                  child: const Text('خیر'),
                  borderColor: AppColor.error,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  //region First Step Widget
  Widget firstStepWidget() {
    return Form(
      child: Column(
        spacing: 16,
        children: [
          Container(
            padding: EdgeInsets.all(8),
            decoration: BoxDecoration(
              border: Border.all(color: AppColor.lightGreyNormal, width: 1),
              borderRadius: BorderRadius.circular(8),
            ),
            child: Column(
              spacing: 10,
              children: [
                Row(children: [Text('اطلاعات دامدار', style: AppFonts.yekan16Bold)]),
                RTextField(controller: controller.fullNameController, label: 'نام ونام خانوادگی'),
                RTextField(controller: controller.phoneController, label: 'تلفن'),
                RTextField(controller: controller.addressController, label: 'ادرس'),
              ],
            ),
          ),

          SizedBox(
            width: Get.width,
            height: 356.h,
            child: Container(
              padding: EdgeInsets.all(8.r),
              decoration: BoxDecoration(
                border: Border.all(color: AppColor.lightGreyNormal, width: 1.w),
                borderRadius: BorderRadius.circular(8.r),
              ),
              child: Column(
                spacing: 8,
                children: [
                  Row(children: [Text('تصویر دامدار', style: AppFonts.yekan16Bold)]),
                  Expanded(
                    child: Container(
                      width: Get.width,
                      decoration: BoxDecoration(
                        color: AppColor.lightGreyNormal,
                        borderRadius: BorderRadius.circular(8.r),
                      ),
                      child: Center(
                        child: ObxValue((tmpImage) {
                          if (tmpImage.value == null) {
                            return Assets.vec.placeHolderSvg.svg(height: 150.h, width: 200.w);
                          } else {
                            return Image.file(File(tmpImage.value!.path), fit: BoxFit.cover);
                          }
                        }, controller.rancherImage),
                      ),
                    ),
                  ),
                  GestureDetector(
                    onTap: () async {
                      await controller.pickImage(controller.rancherImage);
                      await showCropDialog();
                    },
                    child: Container(
                      width: Get.width,
                      height: 40.h,
                      clipBehavior: Clip.antiAlias,
                      decoration: ShapeDecoration(
                        color: AppColor.blueNormal,
                        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
                      ),
                      child: Padding(
                        padding: EdgeInsets.all(10.r),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(' دوربین', style: AppFonts.yekan14.copyWith(color: Colors.white)),
                            Icon(CupertinoIcons.arrow_up_doc, color: Colors.white),
                          ],
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),

          /* RElevated(
            text: 'ارسال تصویر گله',
            onPressed: () {
              Get.toNamed(LiveStockRoutes.tagging);
            },
            height: 40,
            isFullWidth: true,
            backgroundColor: AppColor.greenNormal,
            textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
          ),*/
        ],
      ),
    );
  }

  //endregion

  //region Second Step Widget
  Widget secondStepWidget() {
    return Column(
      spacing: 12.h,
      children: [
        SizedBox(height: 20),

        Container(
          padding: EdgeInsets.all(8.r),
          decoration: BoxDecoration(
            border: Border.all(color: AppColor.borderColor, width: 1.w),
            borderRadius: BorderRadius.circular(8.r),
          ),
          child: Column(
            spacing: 12.h,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(children: [Text('مشخصات موقعیت', style: AppFonts.yekan16Bold)]),
              ObxValue((data) {
                if (data.value.status == ResourceStatus.loading ||
                    data.value.status == ResourceStatus.initial) {
                  return Center(child: CupertinoActivityIndicator());
                } else if (data.value.status == ResourceStatus.error) {
                  return Center(
                    child: Column(
                      children: [
                        Text(
                          'خطا در دریافت اطلاعات',
                          style: AppFonts.yekan16.copyWith(color: AppColor.redNormal),
                        ),
                        ROutlinedElevated(
                          onPressed: () async {
                            await controller.determineCurrentPosition();
                          },
                          child: Text('تلاش مجدد'),
                          borderColor: AppColor.error,
                        ),
                      ],
                    ),
                  );
                } else if (data.value.status == ResourceStatus.success) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    spacing: 8.h,
                    children: [
                      RichText(
                        text: TextSpan(
                          children: [
                            TextSpan(
                              text: 'موقعیت مکانی: ',
                              style: AppFonts.yekan16Bold.copyWith(color: AppColor.textColor),
                            ),
                            TextSpan(
                              text:
                                  '${controller.addressLocationValue.value?.latitude} , ${controller.addressLocationValue.value?.longitude}',
                              style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
                            ),
                          ],
                        ),
                      ),
                      Text(
                        controller.addressDetailsValue.string ?? 'N/A',
                        style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
                      ),
                    ],
                  );
                } else {
                  return SizedBox.shrink();
                }
              }, controller.addressDetails),
            ],
          ),
        ),

        SizedBox(
          width: Get.width,
          height: 356.h,
          child: Container(
            padding: EdgeInsets.all(8.r),
            decoration: BoxDecoration(
              border: Border.all(color: AppColor.borderColor, width: 1.w),
              borderRadius: BorderRadius.circular(8.r),
            ),
            child: Column(
              spacing: 12.h,
              children: [
                Row(children: [Text('تصویر گله', style: AppFonts.yekan16Bold)]),
                Expanded(
                  child: Container(
                    width: Get.width,
                    decoration: BoxDecoration(
                      color: AppColor.lightGreyNormal,
                      borderRadius: BorderRadius.circular(8.r),
                    ),
                    child: Center(
                      child: ObxValue((tmpImage) {
                        if (tmpImage.value == null) {
                          return Assets.vec.placeHolderSvg.svg(height: 150.h, width: 200.w);
                        } else {
                          return Image.file(File(tmpImage.value!.path), fit: BoxFit.cover);
                        }
                      }, controller.herdImage),
                    ),
                  ),
                ),
                GestureDetector(
                  onTap: () async {
                    await controller.pickImage(controller.herdImage);
                    await showCropDialog();
                  },
                  child: Container(
                    width: Get.width,
                    height: 40.h,
                    clipBehavior: Clip.antiAlias,
                    decoration: ShapeDecoration(
                      color: AppColor.blueNormal,
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
                    ),
                    child: Padding(
                      padding: EdgeInsets.all(10.r),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(' دوربین', style: AppFonts.yekan14.copyWith(color: Colors.white)),
                          Icon(CupertinoIcons.arrow_up_doc, color: Colors.white),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),

        Spacer(),

        RElevated(
          text: 'ارسال تصویر گله',
          onPressed: () {},
          height: 40,
          isFullWidth: true,
          backgroundColor: AppColor.greenNormal,
          textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
        ),
      ],
    );
  }

  //endregion

  //region Third Step Widget

  Widget thirdStepWidget() {
    return Stack(
      children: [
        Column(
          children: [
            _buildFilterWidget(),
            _buildSearchWidget(),
            _buildInfoDetails(),
            _buildListContent(),
          ],
        ),
        Positioned(
          right: 10,
          bottom: 5,
          child: RFab.add(
            onPressed: () {
              Get.bottomSheet(_buildBottomSheet(), isScrollControlled: true);
            },
          ),
        ),
      ],
    );
  }

  Container _buildInfoDetails() {
    return Container(
      height: 40.h,
      margin: EdgeInsets.symmetric(vertical: 8.h),
      decoration: BoxDecoration(
        color: AppColor.greenLightHover,
        borderRadius: BorderRadius.circular(8.r),
        border: Border.all(color: AppColor.darkGreyLight),
      ),
      alignment: Alignment.center,
      child: Text('پلاک شده : سبک 5 و سنگین 8 راس'),
    );
  }

  Expanded _buildListContent() {
    return Expanded(
      child: ObxValue((data) {
        return RListView.separated(
          itemCount: data.length,
          padding: EdgeInsets.symmetric(horizontal: 8.w),
          itemBuilder: (BuildContext context, int index) {
            return ObxValue((val) {
              return ExpandableListItem2(
                isTag: true,
                selected: val.contains(index),
                onTap: () => controller.isExpandedList.toggle(index),
                index: index,
                child: itemListWidget(index),
                secondChild: itemListExpandedWidget(index),
                labelColor: AppColor.blueLight,
                labelIcon: Assets.vec.virtualSvg.path,
              );
            }, controller.isExpandedList);
          },
          resource: Resource.success(List.generate(data.length, (i) => i)),
          separatorBuilder: (BuildContext context, int index) => SizedBox(height: 8.h),
        );
      }, controller.livestockList),
    );
  }

  Stack _buildItemList(int index) {
    return Stack(
      clipBehavior: Clip.none,
      children: [
        Positioned(
          right: -12,
          top: 0,
          bottom: 0,
          child: Container(
            width: 30,
            height: 30,
            child: Stack(
              alignment: Alignment.center,
              children: [
                Assets.vec.tagLabelSvg.svg(width: 30, height: 30),
                Positioned(
                  bottom: 25,
                  right: 2,
                  left: 2,
                  child: Text(
                    (index > 10 ? index * 1000 : index + 1).toString(),
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan10.copyWith(
                      fontSize: ((index > 10 ? index * 1000 : index + 1).toString()).length > 3
                          ? 6
                          : 8,
                      color: AppColor.blueDarkActive,
                    ),
                    textScaler: TextScaler.linear(1.5),
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  Widget _buildBottomSheet() {
    return BaseBottomSheet(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        spacing: 8,
        children: [
          _buildLiveStockSpecies(),
          _buildLivestockBirthday(),
          _buildLivestockGender(),

          _buildLivestockBreed(),

          _buildMotherTagNumber(),
          _buildFatherTagNumber(),
          _buildTagNumber(),
          _buildTagType(),

          _buildLiveStockImage(),

          Padding(
            padding: const EdgeInsets.only(top: 8.0),
            child: RElevated(
              text: 'افزودن دام به گله',
              textStyle: AppFonts.yekan18.copyWith(color: Colors.white),
              width: Get.width,
              backgroundColor: AppColor.greenNormal,
              height: 40,
              onPressed: () {
                controller.addLiveStock();
                Get.back();
              },
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildInfoBottomSheet() {
    return BaseBottomSheet(
      height: Get.height * 0.5,
      bgColor: const Color(0xFFF5F5F5),
      child: Card(
        color: Colors.white,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.center,
            spacing: 15,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Assets.vec.editSvg.svg(
                    width: 16,
                    height: 16,
                    colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
                  ),
                  Text('محمد احمدی', style: AppFonts.yekan14),

                  GestureDetector(
                    onTap: () {
                      _buildDeleteDialog(onConfirm: () {});
                    },
                    child: Assets.vec.trashSvg.svg(
                      width: 16,
                      height: 16,
                      colorFilter: ColorFilter.mode(AppColor.error, BlendMode.srcIn),
                    ),
                  ),
                ],
              ),
              Container(
                height: 32,
                padding: EdgeInsets.all(8),
                decoration: BoxDecoration(color: AppColor.blueLightHover),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      'تاریخ ثبت',
                      textAlign: TextAlign.center,
                      style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                    ),
                    Text(
                      '1404/2/2',
                      textAlign: TextAlign.center,
                      style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                    ),
                  ],
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'شماره پلاک',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                  Text(
                    '123456789012346',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'جنسیت ',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                  Text(
                    'ماده',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'نوع نژاد',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                  Text(
                    'افشاری',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'نوع گله',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                  Text(
                    'روستایی',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'شهر',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                  Text(
                    'کرج',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    'سن',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                  Text(
                    '18 ماه',
                    textAlign: TextAlign.center,
                    style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _buildDeleteDialog({required VoidCallback onConfirm}) {
    Get.defaultDialog(
      title: 'حذف دام',
      middleText: 'آیا از حذف این دام مطمئن هستید؟',
      confirm: ElevatedButton(
        style: ElevatedButton.styleFrom(
          backgroundColor: AppColor.error,
          foregroundColor: Colors.white,
        ),
        onPressed: onConfirm,
        child: Text('بله'),
      ),
      cancel: ElevatedButton(
        onPressed: () {
          Get.back();
        },
        child: Text('خیر'),
      ),
    );
  }

  SizedBox _buildLiveStockImage() {
    return SizedBox(
      width: Get.width,
      height: 356.h,
      child: Container(
        padding: EdgeInsets.all(8.r),
        decoration: BoxDecoration(
          border: Border.all(color: AppColor.lightGreyNormal, width: 1.w),
          borderRadius: BorderRadius.circular(8.r),
        ),
        child: Column(
          spacing: 8,
          children: [
            Row(children: [Text('تصویر دام', style: AppFonts.yekan16Bold)]),
            Expanded(
              child: Container(
                width: Get.width,
                decoration: BoxDecoration(
                  color: AppColor.lightGreyNormal,
                  borderRadius: BorderRadius.circular(8.r),
                ),
                child: Center(
                  child: ObxValue((tmpImage) {
                    if (tmpImage.value == null) {
                      return Assets.vec.placeHolderSvg.svg(height: 150.h, width: 200.w);
                    } else {
                      return Image.file(File(tmpImage.value!.path), fit: BoxFit.cover);
                    }
                  }, controller.taggingImage),
                ),
              ),
            ),
            GestureDetector(
              onTap: () async {
                await controller.pickImage(controller.taggingImage);
                await showCropDialog();
              },
              child: Container(
                width: Get.width,
                height: 40.h,
                clipBehavior: Clip.antiAlias,
                decoration: ShapeDecoration(
                  color: AppColor.blueNormal,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
                ),
                child: Padding(
                  padding: EdgeInsets.all(10.r),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(' دوربین', style: AppFonts.yekan14.copyWith(color: Colors.white)),
                      Icon(CupertinoIcons.arrow_up_doc, color: Colors.white),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  OverlayDropdownWidget<String> _buildTagType() {
    return OverlayDropdownWidget(
      items: ['نوع پلاک 1', 'نوع پلاک 2', 'نوع پلاک 3'],
      onChanged: (value) {
        controller.tagType.value = value;
      },
      itemBuilder: (item) => Text(item),
      labelBuilder: (item) => Text(item ?? 'نوع پلاک'),
    );
  }

  TextFiledFixedHint _buildTagNumber() {
    return TextFiledFixedHint(
      controller: controller.herdTagController,
      inputType: InputType.number,
      hintText: 'پلاک دام',
      onChanged: (String value) {
        eLog('father Tag: $value');
      },
    );
  }

  TextFiledFixedHint _buildFatherTagNumber() {
    return TextFiledFixedHint(
      controller: controller.fatherTagNumberController,
      inputType: InputType.number,
      hintText: 'پلاک پدر ',
      onChanged: (String value) {},
    );
  }

  TextFiledFixedHint _buildMotherTagNumber() {
    return TextFiledFixedHint(
      controller: controller.motherTagNumberController,
      inputType: InputType.number,
      hintText: 'پلاک مادر ',
      onChanged: (value) {},
    );
  }

  OverlayDropdownWidget<String> _buildLivestockBreed() {
    return OverlayDropdownWidget(
      items: ['نوع نژاد 1', 'نوع نژاد 2', 'نوع نژاد 3'],
      onChanged: (value) {
        controller.breed.value = value;
        eLog('Selected Breed: $value');
      },
      itemBuilder: (item) => Text(item),
      labelBuilder: (item) => Text(item ?? 'نژاد'),
    );
  }

  ObxValue<RxInt> _buildLivestockGender() {
    return ObxValue(
      (data) => CupertinoSlidingSegmentedControl<int>(
        children: {
          0: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 12),
            child: Text(
              'نر',
              style: AppFonts.yekan14.copyWith(
                color: data.value == 0 ? AppColor.whiteGreyLight : AppColor.darkGreyNormalActive,
              ),
            ),
          ),
          1: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 10),
            child: Text(
              'ماده',
              style: AppFonts.yekan14.copyWith(
                color: data.value == 1 ? AppColor.whiteGreyLight : AppColor.darkGreyNormalActive,
              ),
            ),
          ),
        },
        onValueChanged: (int? value) {
          if (value != null) {
            controller.selectedSegment.value = value;
          }
        },

        proportionalWidth: true,
        groupValue: data.value,
        thumbColor: AppColor.blueNormal,
        backgroundColor: CupertinoColors.systemGrey6,
      ),
      controller.selectedSegment,
    );
  }

  Widget _buildLivestockBirthday() {
    return GestureDetector(
      onTap: () {
        Get.bottomSheet(
          modalDatePicker(onDateSelected:  (value) {
            controller.dateOfBirth.value = value;
          }),
          isScrollControlled: true,
          isDismissible: true,
          ignoreSafeArea: false,
        );
      },
      child: Container(
        height: 40,
        width: Get.width,
        padding: const EdgeInsets.symmetric(horizontal: 12),
        decoration: BoxDecoration(
          border: Border.all(color: AppColor.darkGreyLight),
          borderRadius: BorderRadius.circular(8),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              'تاریخ تولد',
              style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyNormalActive),
            ),
            Text(
              '1404/5/5',
              style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyNormalActive),
            ),
          ],
        ),
      ),
    );
  }

  OverlayDropdownWidget<String> _buildLiveStockSpecies() {
    return OverlayDropdownWidget(
      items: ['گوسفند ماده', 'گوسفند نر', 'بز ماده', 'بز نر', 'گوساله ماده', 'گوساله نر'],
      onChanged: (value) {
        controller.species.value = value;
      },
      itemBuilder: (item) => Text(item),
      labelBuilder: (item) => Text(item ?? 'گونه دام'),
    );
  }

  ObxValue<RxBool> _buildFilterWidget() {
    return ObxValue((data) {
      return AnimatedContainer(
        duration: Duration(milliseconds: 300),
        padding: EdgeInsets.only(top: 5),
        curve: Curves.easeInOut,
        height: data.value ? 50 : 0,
        child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          padding: EdgeInsets.symmetric(horizontal: 12),
          child: ObxValue((data) {
            return Row(
              spacing: 12,
              children: [
                CustomChip(
                  title: 'انتخاب فیلتر',
                  index: 0,
                  isSelected: true,
                  selectedColor: AppColor.blueNormal,
                  onTap: (index) {},
                ),

                RFilterChips(
                  title: 'درخواست‌های من',
                  index: 1,
                  isSelected: data.contains(1),
                  selectedColor: AppColor.yellowNormal,
                  onTap: (index) {
                    if (data.contains(1)) {
                      data.remove(1);
                    } else {
                      data.add(1);
                    }
                  },
                ),

                RFilterChips(
                  title: 'در انتظار ثبت ',
                  index: 2,
                  selectedColor: AppColor.greenLightActive,
                  isSelected: data.contains(2),
                  onTap: (index) {
                    if (data.contains(2)) {
                      data.remove(2);
                    } else {
                      data.add(2);
                    }
                  },
                ),

                RFilterChips(
                  title: 'ارجاع به تعاونی',
                  index: 3,
                  selectedColor: AppColor.blueLightHover,
                  isSelected: data.contains(3),
                  onTap: (index) {
                    if (data.contains(3)) {
                      data.remove(3);
                    } else {
                      data.add(3);
                    }
                  },
                ),
              ],
            );
          }, controller.filterSelected),
        ),
      );
    }, controller.filterIsSelected);
  }

  ObxValue<RxBool> _buildSearchWidget() {
    return ObxValue((data) {
      return AnimatedContainer(
        duration: Duration(milliseconds: 300),
        padding: EdgeInsets.only(top: 5),
        curve: Curves.easeInOut,
        height: data.value ? 50 : 0,
        child: Visibility(
          visible: data.value,
          child: Padding(
            padding: const EdgeInsets.only(right: 8.0, left: 20.0),
            child: RTextField(
              suffixIcon: Padding(
                padding: const EdgeInsets.all(12.0),
                child: Assets.vec.searchSvg.svg(
                  width: 10,
                  height: 10,
                  colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
                ),
              ),
              hintText: 'جستجو',
              onChanged: (value) {
                //controller.search(value);
              },
              controller: TextEditingController(),
            ),
          ),
        ),
      );
    }, controller.searchIsSelected);
  }

  Row itemListWidget(int index) {
    return Row(
      children: [
        SizedBox(width: 30),
        Text('123456789012346', style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal)),
        Spacer(),
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('گوسفند ماده', style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal)),
            SizedBox(height: 4),
            Text('نوع نژاد', style: AppFonts.yekan14.copyWith(color: AppColor.bgDark)),
          ],
        ),
        Spacer(),
        Text('18 ماه', style: AppFonts.yekan14.copyWith(color: AppColor.darkGreyDark)),
        Spacer(),
        Assets.vec.scanSvg.svg(
          width: 32.w,
          height: 32.h,
          colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
        ),
        SizedBox(width: 12),
      ],
    );
  }

  Container itemListExpandedWidget(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(
                'fullname' ?? 'N/A',
                textAlign: TextAlign.center,
                style: AppFonts.yekan16.copyWith(color: AppColor.greenDark),
              ),
              Spacer(),
              Text(
                'در انتظار',
                textAlign: TextAlign.center,
                style: AppFonts.yekan10.copyWith(color: AppColor.darkGreyDark),
              ),
              SizedBox(width: 7),
              Assets.vec.clockSvg.svg(width: 16.w, height: 16.h),
            ],
          ),
          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(
                      Jalali.now().formatter.wN ?? 'N/A',
                      style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
                    ),

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

                Text(
                  '${Jalali.now().formatter.y}',
                  style: AppFonts.yekan20.copyWith(color: AppColor.textColor),
                ),

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

          buildRow(title: 'مشخصات دام', value: 'مشخصات دام'),

          buildRow(title: 'نژاد', value: 'نژاد'),
          buildRow(title: 'وزن خریداری شده', value: ' 10 کیلوگرم'),
          buildRow(title: 'قیمت کل', value: '10000'),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            spacing: 16.w,
            children: [
              ObxValue((data) {
                return RElevated(
                  text: 'تایید',
                  width: 150.w,
                  height: 40.h,
                  isLoading: data.value,
                  onPressed: () async {},
                  textStyle: AppFonts.yekan20.copyWith(color: Colors.white),
                  backgroundColor: AppColor.greenNormal,
                );
              }, controller.tst1),
              ROutlinedElevated(
                text: 'رد',
                textStyle: AppFonts.yekan20.copyWith(color: AppColor.redNormal),
                width: 150.w,
                height: 40.h,
                onPressed: () {
                  buildWarningDialog(
                    title: 'اخطار',
                    middleText: 'آیا از رد شدن این مورد اطمینان دارید؟',
                    onConfirm: () async {},
                    onRefresh: () async {},
                  );
                },
                borderColor: AppColor.redNormal,
              ),
            ],
          ),
        ],
      ),
    );
  }

  //endregion
}
