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

class SearchField extends FStatelessWidget {
  final TextEditingController textEditingController;
  final Function() onSearch;
  SearchField({required this.textEditingController, required this.onSearch});

  @override
  FWidget build(BuildContext context) {
    return FContainer(
      decoration: BoxDecoration(
        border: Border.all(color: Colors.grey),
        borderRadius: BorderRadius.circular(8),
      ),
      margin: EdgeInsets.all(8),
      padding: EdgeInsets.only(left: 8),
      clipBehavior: Clip.antiAlias,
      child: FRow(
        children: [
          FExpanded(
            child: _buildSearchTextField(),
          ),
          FContainer(
            width: 1,
            margin: EdgeInsets.only(left: 8),
            color: Colors.grey,
          ),
          _buildSearchButton(),
        ],
      ),
    );
  }

  /// 搜索框输入栏
  FWidget _buildSearchTextField() {
    return FContainer(
      child: FTextField(
        maxLines: 1,
        controller: textEditingController,
        decoration: InputDecoration(
          hintText: "搜索",
          isCollapsed: true,
          border: InputBorder.none,
        ),
        onSubmitted: (value) {
          print("onSubmitted");
          onSearch.call();
        },
      ),
    );
  }

  /// 搜索按钮
  FWidget _buildSearchButton() {
    return FMaterial(
      color: Colors.transparent,
      child: FInkWell(
        onTap: onSearch,
        child: Container(
          margin: EdgeInsets.symmetric(horizontal: 8),
          child: FCenter(
            child: FIcon(
              Icons.search,
              color: Colors.grey,
            ),
          ),
        ),
      ),
    );
  }
}
