import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart' hide BasePage;
import 'package:rasadyar_livestock/presentation/page/map/widget/map_widget/view.dart';
import 'package:rasadyar_livestock/presentation/widgets/base_page/view.dart';

import 'logic.dart';

class MapPage extends GetView<MapLogic> {
  MapPage({super.key});

  @override
  Widget build(BuildContext context) {
    return BasePage(
      hasSearch: true,
      hasFilter: true,
      hasBack: false,
      defaultSearch: false,
      filteringWidget: filterWidget(showIndex: 3.obs, filterIndex: 5.obs),
      widgets: [MapWidget()],
    );
  }

  Widget filterWidget({required RxInt filterIndex, required RxInt showIndex}) {
    return BaseBottomSheet(
      height: Get.height * 0.5,
      child: Container(color: Colors.red),
    );
  }

  BaseBottomSheet searchWidget() {
    return BaseBottomSheet(
      height: Get.height * 0.85,
      rootChild: Column(
        spacing: 8,
        children: [
          Row(
            spacing: 12,
            children: [
    /*          Expanded(
                child: RTextField(
                  height: 40,
                  borderColor: AppColor.blackLight,
                  suffixIcon: ObxValue(
                    (data) => Padding(
                      padding: const EdgeInsets.symmetric(vertical: 8),
                      child: (data.value == null)
                          ? Assets.vec.searchSvg.svg(
                              width: 10,
                              height: 10,
                              colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
                            )
                          : IconButton(
                              onPressed: () {
                              //  controller.baseLogic.searchTextController.clear();
                                controller.baseLogic.searchValue.value = null;
                                controller.baseLogic.isSearchSelected.value = false;
                                //controller.mapLogic.hasFilterOrSearch.value = false;
                                //controller.searchedPoultryLocation.value = Resource.initial();
                              },
                              enableFeedback: true,
                              padding: EdgeInsets.zero,
                              iconSize: 24,
                              splashRadius: 50,
                              icon: Assets.vec.closeCircleSvg.svg(
                                width: 20,
                                height: 20,
                                colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
                              ),
                            ),
                    ),
                    controller.baseLogic.searchValue,
                  ),
                  hintText: 'جستجو کنید ...',
                  hintStyle: AppFonts.yekan16.copyWith(color: AppColor.blueNormal),
                  filledColor: Colors.white,
                  filled: true,
                  controller: controller.baseLogic.searchTextController,
                  onChanged: (val) => controller.baseLogic.searchValue.value = val,
                ),
              ),*/
              GestureDetector(
                onTap: () {
                  Get.back();
                },
                child: Assets.vec.mapSvg.svg(
                  width: 24.w,
                  height: 24.h,
                  colorFilter: ColorFilter.mode(AppColor.blueNormal, BlendMode.srcIn),
                ),
              ),
            ],
          ),
          /*        Expanded(
            child: ObxValue((rxData) {
              final resource = rxData.value;
              final status = resource.status;
              final items = resource.data;
              final message = resource.message ?? 'خطا در بارگذاری';

              if (status == ResourceStatus.initial) {
                return Center(child: Text('ابتدا جستجو کنید'));
              }

              if (status == ResourceStatus.loading) {
                return const Center(child: CircularProgressIndicator());
              }

              if (status == ResourceStatus.error) {
                return Center(child: Text(message));
              }

              if (items == null || items.isEmpty) {
                return Center(child: EmptyWidget());
              }

              return ListView.separated(
                itemCount: items.length,
                separatorBuilder: (context, index) => SizedBox(height: 8),
                itemBuilder: (context, index) {
                  final item = items[index]; // اگر item استفاده نمیشه، می‌تونه حذف بشه
                  return ListItem2(
                    index: index,
                    labelColor: AppColor.blueLight,
                    labelIcon: Assets.vec.cowSvg.path,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              item.unitName ?? 'N/A',
                              style: AppFonts.yekan10.copyWith(color: AppColor.blueNormal),
                            ),
                            Text(
                              item.user?.fullname ?? '',
                              style: AppFonts.yekan12.copyWith(color: AppColor.darkGreyDarkHover),
                            ),
                          ],
                        ),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text(
                              'جوجه ریزی فعال',
                              style: AppFonts.yekan10.copyWith(color: AppColor.blueNormal),
                            ),
                            Text(
                              (item.hatching != null && item.hatching!.isNotEmpty)
                                  ? 'دارد'
                                  : 'ندراد',
                              style: AppFonts.yekan12.copyWith(color: AppColor.darkGreyDarkHover),
                            ),
                          ],
                        ),
                      ],
                    ),
                  );
                },
              );
            }, controller.searchedPoultryLocation),
          ),*/
        ],
      ),
    );
  }
}
