import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:web_panel/utils/spacing.dart';


import '../../../controllers/MenuController.dart';
import '../../../responsive.dart';
import 'search_field.dart';

class Header extends StatelessWidget {
  Header({Key? key, required this.title,required this.scaffoldKey,this.onChanged}) : super(key: key);

  String title;

  final SidebarController menuController =Get.find();
  final GlobalKey<ScaffoldState> scaffoldKey;
  void Function(String)? onChanged;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        if (!Responsive.isDesktop(context))
          GetBuilder<SidebarController>(
            init: menuController,
            builder: (controller) {
              return Row(
                children: [
                  IconButton(
                    icon: Icon(Icons.menu,size: 18,),
                    onPressed:() {
                      // controller.controlMenu();
                      if (!scaffoldKey.currentState!.isDrawerOpen) {
                        scaffoldKey.currentState!.openDrawer();
                      }
                    },
                  ),
                  Spacing.width(8),
                  if(Responsive.isMobile(context) &&onChanged!= null)
                  SizedBox(
                    width: 300,
                    height: 35,
                    child: SearchField(
                      onChanged: onChanged,
                    ),
                  )
                ],
              );
            }
          ),
        if (!Responsive.isMobile(context))
          Text(title, style: Theme.of(context).textTheme.titleLarge),
        if (!Responsive.isMobile(context))
          Spacer(flex: Responsive.isDesktop(context) ? 2 : 1),
        // if (Responsive.isMobile(context)) Expanded(child: SearchField()),
        // ProfileCard()
      ],
    );
  }
}
