import 'package:flutter/material.dart';
import '../../../core/theme/app_colors.dart';

class SearchAppBar extends StatefulWidget implements PreferredSizeWidget {
  final TextEditingController searchController;
  final VoidCallback onSearch;
  final VoidCallback onClose;
  
  const SearchAppBar({
    Key? key,
    required this.searchController,
    required this.onSearch,
    required this.onClose,
  }) : super(key: key);
  
  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
  
  @override
  State<SearchAppBar> createState() => _SearchAppBarState();
}

class _SearchAppBarState extends State<SearchAppBar> {
  @override
  Widget build(BuildContext context) {
    return AppBar(
      backgroundColor: AppColors.primary,
      foregroundColor: AppColors.appBarForeground,
      elevation: 0,
      automaticallyImplyLeading: false,
      titleSpacing: 0,
      title: Row(
        children: [
          IconButton(
            icon: const Icon(Icons.arrow_back),
            onPressed: widget.onClose,
          ),
          Expanded(
            child: TextField(
              controller: widget.searchController,
              decoration: InputDecoration(
                hintText: 'Cari pesan...',
                hintStyle: TextStyle(color: Colors.white70),
                border: InputBorder.none,
              ),
              style: TextStyle(color: Colors.white),
              autofocus: true,
              textInputAction: TextInputAction.search,
              onSubmitted: (_) => widget.onSearch(),
            ),
          ),
          IconButton(
            icon: Icon(Icons.clear),
            onPressed: () {
              widget.searchController.clear();
            },
          ),
        ],
      ),
      actions: [
        IconButton(
          icon: Icon(Icons.search),
          onPressed: widget.onSearch,
        ),
      ],
    );
  }
} 