import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart' hide BaseLogic;
import 'package:rasadyar_livestock/presentation/widgets/base_page/logic.dart';

RAppBar2 liveStockAppBar({
  bool hasBack = true,
  bool hasFilter = true,
  bool hasSearch = true,
  bool isBase = false,
  VoidCallback? onBackPressed,
  GestureTapCallback? onFilterTap,
  GestureTapCallback? onSearchTap,
  String? title,
}) {
  return RAppBar2(
    hasBack: isBase == true ? false : hasBack,
    onBackPressed: onBackPressed,
    leadingWidth: 180.w,
    leading: Row(
      mainAxisSize: MainAxisSize.min,
      spacing: 6,
      children: [
        Text(title ?? 'رصددام', style: AppFonts.yekan16Bold.copyWith(color: Colors.white)),
        Assets.vec.appBarInspectionSvg.svg(width: 24, height: 24),
      ],
    ),
    additionalActions: [
      if (!isBase && hasSearch) searchWidget(onSearchTap),
      SizedBox(width: 8),
      if (!isBase && hasFilter) filterWidget(onFilterTap),
      SizedBox(width: 8),
    ],
  );
}

GestureDetector filterWidget(GestureTapCallback? onFilterTap) {
  return GestureDetector(
    onTap: onFilterTap,
    child: Stack(
      alignment: Alignment.topRight,
      children: [
        Assets.vec.filterOutlineSvg.svg(
          width: 20,
          height: 20,
          colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
        ),
        Obx(() {
          final controller = Get.find<BaseLogic>();
          return Visibility(
            visible: controller.isFilterSelected.value,
            child: Container(
              width: 8,
              height: 8,
              decoration: const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
            ),
          );
        }),
      ],
    ),
  );
}

GestureDetector searchWidget(GestureTapCallback? onSearchTap) {
  return GestureDetector(
    onTap: onSearchTap,
    child: Stack(
      alignment: Alignment.topRight,
      children: [
        Assets.vec.searchSvg.svg(
          width: 24,
          height: 24,
          colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
        ),
        Obx(() {
          final controller = Get.find<BaseLogic>();
          return Visibility(
            visible: controller.searchValue.value != null,
            child: Container(
              width: 8,
              height: 8,
              decoration: const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
            ),
          );
        }),
      ],
    ),
  );
}
