// Author: fengshengxiong
// Date: 2024/5/7
// Description: BaseAppBar

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return AppBar(
      centerTitle: true,
      backgroundColor: backgroundColor,
      title: _buildTitle(),
      leading: backWidget ?? _buildBackWidget(),
    );
  }

  Widget _buildBackWidget() {
    return ClipOval(
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onBackTap ?? Get.back,
          child: Icon(
            Icons.arrow_back_rounded,
            size: 32.w,
            color: Colors.white,
          ),
        ),
      ),
    );
  }

  Widget _buildTitle() {
    return Text(
      title,
      style: TextStyle(
        color: Colors.white,
        fontSize: 20.sp,
        fontWeight: FontWeight.w600,
      ),
    );
  }

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