import 'package:flutter/material.dart';

class VSearchInput extends StatelessWidget {
  /// 占位提示
  final String? placeholder;

  /// 搜索回调
  final ValueChanged<String>? onSearch;

  const VSearchInput({
    super.key,
    this.placeholder,
    this.onSearch,
  });

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (_, c) {
        final controller = TextEditingController();
        final radius = c.maxHeight / 2;
        final border = OutlineInputBorder(
          borderRadius: BorderRadius.all(Radius.circular(radius)),
          borderSide: BorderSide.none,
        );
        return TextField(
          controller: controller,
          decoration: InputDecoration(
            enabledBorder: border,
            focusedBorder: border,
            fillColor: Colors.grey.shade400,
            filled: true,
            hintText: placeholder,
            hintStyle: const TextStyle(
              fontSize: 20,
              color: Colors.black54,
            ),
            contentPadding: EdgeInsets.symmetric(
              horizontal: radius * 1.2,
              vertical: (c.maxHeight - 24) / 2,
            ),
            // isDense: true,
            isCollapsed: false,
            prefixIcon: IconButton(
              padding: const EdgeInsets.symmetric(horizontal: 18),
              icon: const Icon(Icons.search, size: 36),
              onPressed: () {
                onSearch?.call(controller.text);
              },
            ),
          ),
        );
      },
    );
  }
}
