import 'package:flutter/material.dart';
import 'package:supplier_new/common/settings.dart';

class SearchPlanAppBar extends StatelessWidget implements PreferredSizeWidget {
  final TextEditingController controller;
  final VoidCallback onBack;
  final VoidCallback onHelp;

  const SearchPlanAppBar({
    super.key,
    required this.controller,
    required this.onBack,
    required this.onHelp,
  });

  @override
  Widget build(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.white,
      scrolledUnderElevation: 0,
      elevation: 0,
      leading: GestureDetector(
        onTap: onBack, // 👉 use callback from parent
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Image.asset(
            'images/backbutton_appbar.png',
            height: 24,
            width: 24,
            fit: BoxFit.contain,
          ),
        ),
      ),
      titleSpacing: 0,
      title: Container(
        height: 40,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(22),
          border: Border.all(color: const Color(0XFF939495)),
        ),
        child: TextField(
          controller: controller,
          decoration: InputDecoration(
            hintText: "Search Plan",
            hintStyle: fontTextStyle(16, const Color(0XFF646566), FontWeight.w400),
            prefixIcon: SizedBox(
              height: 20,
              width: 20,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Image.asset(
                  'images/search.png',
                  fit: BoxFit.contain,
                ),
              ),
            ),
            border: InputBorder.none,
            contentPadding: const EdgeInsets.symmetric(vertical: 0),
          ),
          style: fontTextStyle(16, const Color(0XFF2A2A2A), FontWeight.w400),
          onSubmitted: (value) {
            debugPrint("Search Plan: $value");
          },
        ),
      ),
      actions: [
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: GestureDetector(
            onTap: onHelp, // 👉 use callback from parent
            child: Image.asset(
              'images/help_appbar.png',
              height: 24,
              width: 24,
              fit: BoxFit.contain,
            ),
          ),
        ),
      ],
    );
  }

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
