import 'package:flutter/material.dart';
import 'package:satu/core/services/navigator_service.dart';
import 'package:satu/core/utils/locator.dart';
import 'package:satu/shared/app_colors.dart';
import 'package:satu/widgets/bar/products_header_bar.dart';

class ProductsAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String? title;
  final List<Widget>? actions;
  final Widget? child;
  final int? childHeight;
  final double elevation;
  final Color? backgroundColor;
  final bool drawerShow;

  const ProductsAppBar(
      {Key? key,
      this.title,
      this.actions,
      this.child,
      this.childHeight = 0,
      this.elevation = 0.0,
      this.drawerShow = false,
      this.backgroundColor = Colors.transparent})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      elevation: elevation,
      color: backgroundColor,
      child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/images/top_bar_bg.png'),
            fit: BoxFit.fitWidth,
            alignment: FractionalOffset.topLeft,
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            AppBar(
              title: Text(title ?? ''),
              centerTitle: true,
              backgroundColor: Colors.transparent,
              elevation: 0.0,
              leading: drawerShow ? IconButton(
                icon: Icon(
                  Icons.menu,
                  color: blackColor,
                ),
                onPressed: () {
                  locator<NavigatorService>()
                      .scaffoldDrawerKey
                      .currentState!
                      .openDrawer();
                },
              ) : null ,
              actions: actions,
            ),
            if (child != null && childHeight! > 0) child!,
          ],
        ),
      ),
    );
  }

  @override
  Size get preferredSize {
    return new Size.fromHeight(60.0 + childHeight!);
  }
}
