import 'package:flutter/material.dart';

import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';

import '../../../../common/const/const.dart';

class SearchBarWidget extends StatelessWidget {
  final void Function(String)? onChanged;
  final VoidCallback onSearch;
  final TextEditingController? controller;
  final double? radius;
  final String? hint;

  const SearchBarWidget({
    super.key,
    required this.onChanged,
    required this.onSearch,
    this.radius,
    this.hint,
    this.controller,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(top: 3),
      width: MediaQuery.of(context).size.width,
      height: 50,
      child: TextFormField(
        controller: controller,
        textInputAction: TextInputAction.search,
        // onFieldSubmitted: onFieldSubmitted ??
        //     (value) {
        //       if (Get.currentRoute != RoutesName.search) {
        //         RoutingManager.to(RoutesName.search);
        //         controller!.clear();
        //         FocusManager.instance.primaryFocus
        //             ?.unfocus(disposition: UnfocusDisposition.scope);
        //         return;
        //       }

        //       searchController.search();
        //     },
        cursorColor: AppColors.primeColor,

        style: const TextStyle(
          height: 1.6,
        ),
        onChanged: onChanged,
        keyboardType: TextInputType.text,

        decoration: InputDecoration(
            fillColor: Colors.white,
            enabledBorder: OutlineInputBorder(
              borderSide: BorderSide(color: AppColors.borderColor),
              borderRadius: BorderRadius.circular(radius ?? 44),
            ),
            disabledBorder: OutlineInputBorder(
              borderSide: BorderSide(color: AppColors.borderColor),
              borderRadius: BorderRadius.circular(radius ?? 44),
            ),
            isDense: true,
            filled: true,
            prefixIcon: IconButton(
              onPressed: onSearch,
              icon: SvgPicture.asset('assets/icons/search.svg'),
            ),
            contentPadding: const EdgeInsets.symmetric(horizontal: 10),
            hintText: hint ?? 'search'.tr,
            hintStyle: const TextStyle(fontSize: 14),
            border: OutlineInputBorder(
              borderSide: BorderSide(
                color: AppColors.borderColor,
              ),
              borderRadius: BorderRadius.circular(radius ?? 44),
            )),
      ),
    );
  }
}
