import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wallpaperx/generated/assets.dart';
import 'package:wallpaperx/res/themes/app_colors.dart';

class CustomAppbar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppbar(
    this.title, {
    super.key,
    this.backgroundColor,
    this.backWidget,
    this.titleStyle,
    this.onBackTap,
  });

  final Color? backgroundColor;
  final Widget? backWidget;
  final String title;
  final TextStyle? titleStyle;
  final Function()? onBackTap;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: preferredSize.height,
      padding: EdgeInsets.fromLTRB(10, ScreenUtil().statusBarHeight, 10, 0).w,
      color: backgroundColor ?? seedColor,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          backWidget ??
              ClipOval(
                child: Material(
                  color: Colors.transparent,
                  child: InkWell(
                    onTap: onBackTap ?? () => Get.back(),
                    child: Image.asset(
                      Assets.iconBack,
                      width: 32.w,
                      height: 32.w,
                      color: Colors.white,
                    ),
                  ),
                ),
              ),
          Flexible(
            child: Text(
              title,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: titleStyle ??
                  TextStyle(
                    color: Colors.black,
                    fontSize: 20.sp,
                    fontWeight: FontWeight.w500,
                  ),
            ),
          ),
          Container(width: 32.w),
        ],
      ),
    );
  }

  @override
  Size get preferredSize =>
      Size.fromHeight(ScreenUtil().statusBarHeight + kToolbarHeight);
}
