import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';

class SearchWidget extends GetView<BaseLogic> {
  const SearchWidget({super.key});


  @override
  Widget build(BuildContext context) {
    return ObxValue((data) {
      return AnimatedContainer(
        duration: const Duration(milliseconds: 300),
        curve: Curves.easeInOut,
        height: data.value ? 40 : 0,
        child: Visibility(
          visible: data.value,
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 8),
            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.clearSearch();
                          },
                          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.searchValue,
              ),
              hintText: 'جستجو کنید ...',
              hintStyle: AppFonts.yekan16.copyWith(color: AppColor.blueNormal),
              filledColor: Colors.white,
              filled: true,
              controller: controller.searchTextController,
              onChanged: (val) => controller.searchValue.value = val,
            ),
          ),
        ),
      );
    }, controller.isSearchSelected);
  }
}
