import 'package:flutter/material.dart';
import 'package:widgets/search_app_bar.dart';

class SearchCmp extends StatelessWidget {
  String? value;
  String? hintText;
  Color backgroundColor = Colors.transparent;
  ValueChanged<String>? onSearch;
  ValueChanged<String>? onChanged;
  TextEditingController? controller;
  List<Widget>? actions;
  void Function()? backCallback;

  SearchCmp({
    Key? key,
    this.backCallback,
    this.value,
    this.hintText,
    this.backgroundColor = Colors.transparent,
    this.onSearch,
    this.onChanged,
    this.controller,
    this.actions,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 检查当前主题是亮色还是暗色
    final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;


    return Column(
      children: [
        Container(
          height: kToolbarHeight,
          color: backgroundColor,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              // 搜索栏
              Expanded(
                child: SearchAppBar(
                  onSearch: onSearch,
                  onChanged: onChanged,
                  value: value,
                  hintText: hintText,
                  controller: controller,
                ),
              ),
              // 右侧操作按钮
              Container(
                alignment: Alignment.centerRight,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: actions ?? [],
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}