import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:ui_kit/ui_kit.dart';

class SearchWidget extends StatefulWidget {
  const SearchWidget({
    super.key,
    required this.controller,
    required this.hintText,
    this.isClosable = true,
  });
  final TextEditingController controller;
  final String hintText;
  final bool isClosable;

  @override
  State<SearchWidget> createState() => _SearchWidgetState();
}

class _SearchWidgetState extends State<SearchWidget> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          height: 48,
          child: TextFormField(
            controller: widget.controller,
            decoration: InputDecoration(
              fillColor: inputBgColor,
              filled: true,
              contentPadding: EdgeInsets.symmetric(
                vertical: 14,
                horizontal: 14,
              ),
              suffixIcon: widget.isClosable
                  ? SvgPicture.asset(
                      'assets/close.svg',
                      fit: BoxFit.none,
                      height: 20,
                      width: 20,
                    )
                  : null,
              prefixIcon: SvgPicture.asset(
                'assets/search.svg',
                width: 20,
                height: 20,
                fit: BoxFit.none,
              ),
              hintText: widget.hintText,
              hintStyle: textRegular.copyWith(color: captionColor),
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(10),
                borderSide: BorderSide(color: inputStrokeColor, width: 1),
              ),
              focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(10),
                borderSide: BorderSide(color: primaryHoverColor, width: 1),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
