import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../app.dart';

OutlineInputBorder searchBoxBorder = new OutlineInputBorder(
  borderRadius: BorderRadius.circular(10),
  borderSide: BorderSide(color: Colors.transparent),
);

class DecoratedSearchWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    debugPrint('DecoratedSearchWidget: build');
    return GetX<SSearchController>(
      init: SSearchController(),
      builder: (sc) => Padding(
        padding: const EdgeInsets.only(left: 4.0, right: 4),
        child: TextFormField(
          controller: sc.searchTxtCtrl,
          focusNode: sc.searchFocusNode,
          onChanged: (newValue) => sc.onSearchChanged(newValue),
          cursorColor: Color(0xFF000000).withOpacity(0.40),
          style: new TextStyle(fontSize: 14.sp),
          textAlignVertical: TextAlignVertical.center,
          onFieldSubmitted: (value) => sc.onDecoratedTxtFormFieldTap(value),
          decoration: InputDecoration(
            hintText: 'search'.tr,
            hintStyle: new TextStyle(fontSize: 14.sp),
            filled: true,
            fillColor: ThemeColor.searchBoxFillColor,
            focusColor: ThemeColor.white,
            hoverColor: ThemeColor.white,
            border: searchBoxBorder,
            enabledBorder: searchBoxBorder,
            focusedBorder: searchBoxBorder,
            disabledBorder: searchBoxBorder,
            prefixIcon: Material(
              color: Colors.transparent,
              child: IconButton(
                splashRadius: 22.w,
                onPressed: sc.onSearchIconPressed,
                icon: Icon(
                  Icons.search_sharp,
                  color: Color(0xFF000000).withOpacity(0.30),
                  size: 22.h,
                ),
              ),
            ),
            suffixIcon: sc.state.hasSuffixIcon.value
                ? ClearTextButton(
                    callback: sc.clearSearchText,
                  )
                : SizedBox.shrink(),
            suffixIconConstraints: BoxConstraints(),
          ),
        ),
      ),
    );
  }
}
