// ignore_for_file: non_constant_identifier_names, file_names, prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:tanami_app/core/routes/routes.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/shared/components/text_widget.dart';

class AppBarWidget extends StatelessWidget implements PreferredSizeWidget {
  @override
  Size get preferredSize => Size.fromHeight(height!);
  const AppBarWidget({
    super.key,
    required this.titleTxt,
    this.suffixIcon,
    this.showLeading = true,
    this.customBack,
    this.backPageName = '',
    this.customActionWidget,
    this.onCustomActionPressed,
    this.height = 10,
    this.centerTitle,
  });

  final String titleTxt;
  final String? suffixIcon;
  final bool? showLeading;
  final bool? customBack;
  final String? backPageName;
  final Widget? customActionWidget;
  final VoidCallback? onCustomActionPressed;
  final double? height;
  final bool? centerTitle;
  @override
  Widget build(BuildContext context) {
    return PreferredSize(
      preferredSize: Size.fromHeight(height ?? 130),
      child: AppBar(
        scrolledUnderElevation: 0.0,
        backgroundColor: AppColor.plainWhite,
        elevation: 0,
        centerTitle: centerTitle ?? true,
        title: TextWidget().text20W700(titleTxt, clr: AppColor.charcoalColor),
        leading: Padding(
          padding: EdgeInsets.only(
            left: !showLeading! ? 0 : 16.w,
          ),
          child: !showLeading!
              ? null
              : GestureDetector(
                  onTap: () {
                    customBack ?? false
                        ? goRouter.goNamed(backPageName!)
                        : goRouter.pop();
                  },
                  child: Padding(
                    padding: EdgeInsets.only(left: 8.w),
                    child: Icon(
                      Icons.arrow_back_rounded,
                      color: AppColor.appBarIconColor,
                      size: 25.r,
                    ),
                  ),
                ),
        ),
        actions: [
          if (customActionWidget != null)
            GestureDetector(
              onTap: onCustomActionPressed,
              child: Padding(
                padding: EdgeInsets.only(right: 14.w),
                child: customActionWidget,
              ),
            ),
        ],
      ),
    );
  }
}
