import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mc_common_app/classes/consts.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/extensions/string_extensions.dart';
import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';

//import 'package:flutter/material.dart';
// import 'package:flutter_svg/flutter_svg.dart';
// import 'package:mc_common_app/classes/consts.dart';
// import 'package:mc_common_app/extensions/int_extensions.dart';
// import 'package:mc_common_app/extensions/string_extensions.dart';
// import 'package:mc_common_app/theme/colors.dart';
// import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
// import 'package:sizer/sizer.dart';
//
// class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
//   final Color? backgroundColor;
//   final double? elevation;
//   final String? title;
//   final Color? titleColor;
//   final bool? isTitleCenter;
//   final Color? backIconColor;
//   final List<Widget>? actions;
//   final bool isRemoveBackButton;
//
//   const CustomAppBar({
//     Key? key,
//     this.title,
//     required this.isRemoveBackButton,
//     this.backgroundColor,
//     this.actions,
//     this.backIconColor,
//     this.elevation,
//     this.isTitleCenter,
//     this.titleColor,
//   }) : super(key: key);
//
//   @override
//   Widget build(BuildContext context) {
//     return AppBar(
//       backgroundColor: backgroundColor ?? appBackgroundColor,
//       elevation: elevation ?? 0,
//       centerTitle: isTitleCenter ?? true,
//       leading: isRemoveBackButton
//           ? null
//           : IconButton(
//               icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
//               onPressed: () => Navigator.of(context).pop(),
//             ),
//       iconTheme: IconThemeData(
//         color: backIconColor ?? Colors.black, //change your color here
//       ),
//       actions: actions,
//       title: (title ?? "").toText(fontSize: 20, isBold: true),
//     );
//   }
//
//   @override
//   Size get preferredSize => const Size.fromHeight(kToolbarHeight);
// }
class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
  final Color? backgroundColor;
  final double? elevation;
  final String? title;
  final Color? titleColor;
  final bool? isTitleCenter;
  final Color? backIconColor;
  final List<Widget>? actions;
  final bool isRemoveBackButton;
  final String profileImageUrl;
  final bool isDrawerEnabled;
  final VoidCallback? onTap;
  final double? leadingWidth;

  const CustomAppBar({
    Key? key,
    this.title,
    this.isDrawerEnabled = false,
    this.profileImageUrl = "",
    this.isRemoveBackButton = false,
    this.backgroundColor,
    this.actions,
    this.backIconColor,
    this.elevation,
    this.isTitleCenter,
    this.titleColor,
    this.onTap,
    this.leadingWidth,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        AppBar(
          leadingWidth: leadingWidth??61,
          backgroundColor: backgroundColor ?? Colors.white,
          elevation: elevation ?? 0,
          centerTitle: isTitleCenter ?? true,
          leading: isDrawerEnabled
              ? InkWell(
                  onTap: onTap,
                  child: Row(
                    children: [
                      Image.asset(
                        profileImageUrl,
                        width: 34,
                        height: 34,
                        fit: BoxFit.fill,
                      ).toCircle(borderRadius: 100),
                      10.width,
                      SvgPicture.asset(MyAssets.dashboardDrawerIcon),
                    ],
                  ).paddingOnly(left: 21),
                )
              : isRemoveBackButton
                  ? null
                  : Row(
                      children: [
                        21.width,
                        IconButton(
                          icon: const Icon(
                            Icons.arrow_back_ios,
                            color: Colors.black,
                            size: 16,
                          ),
                          onPressed: () => onTap??Navigator.of(context).pop(),
                        ).toContainer(
                          paddingAll: 0,
                          borderRadius: 100,
                          borderColor: MyColors.lightGreyEFColor,
                          isEnabledBorder: true,
                          height: 40,
                          width: 40,
                        ),
                      ],
                    ),
          iconTheme: IconThemeData(
            color: backIconColor ?? Colors.black, //change your color here
          ),
          actions: actions,
          title: (title ?? "").toText(fontSize: 20, isBold: true),
        ),
        if (backgroundColor == null)
          const Divider(
            thickness: 1,
            color: MyColors.lightGreyEFColor,
            height: 1,
          )
      ],
    );
  }

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