import 'package:fis_ui/index.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:flutter/material.dart';

///搜索组件
class SearchInput extends FStatefulWidget {
  SearchInput({
    Key? key,
    this.onChanged,
    this.serchOnPressed,
    this.hintText,
    this.controller,
    this.focusNode,
    this.margin = const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
    required this.businessParent,
  }) : super(key: key);

  final EdgeInsets margin;

  ///父级节点
  final FPage businessParent;

  ///查询文本编辑Controller
  final TextEditingController? controller;

  ///查找事件回调
  final VoidCallback? serchOnPressed;

  ///文本改变回调
  final ValueChanged? onChanged;

  ///提示文字
  final String? hintText;

  final FocusNode? focusNode;

  @override
  FState<SearchInput> createState() => _SearchInputState();
}

class _SearchInputState extends FState<SearchInput> {
  @override
  FWidget build(BuildContext context) {
    return FContainer(
      margin: widget.margin,
      color: Colors.white,
      child: FRow(
        children: [
          FExpanded(
            child: FContainer(
              height: 36,
              // color: Colors.red,
              child: FRow(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  FBorderInput(
                    hintSize: 16,
                    contentSize: 16,
                    maxLength: 20,
                    controller: widget.controller ?? TextEditingController(),
                    borderColor: Color.fromRGBO(211, 211, 211, 1),
                    focusNode: widget.focusNode,
                    suffixIcon: FMaterial(
                      color: Colors.transparent,
                      child: FIconButton(
                        name: "search",
                        businessParent: widget.businessParent,
                        onPressed: () {
                          widget.serchOnPressed!.call();
                        },
                        icon: FIcon(
                          Icons.search,
                        ),
                      ),
                    ),
                    // width: 400,
                    height: 36,
                    hintText: widget.hintText,
                    onChanged: (value) {
                      widget.onChanged!.call(value);
                    },
                    // controller: controller.OrgName,
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
