import 'package:flutter/material.dart';
import 'back_button.dart';

class CustomNavigationBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final String? backgroundImage;
  final bool showBackButton;
  final List<Widget> rightButtons;

  const CustomNavigationBar({
    super.key,
    required this.title,
    this.backgroundImage = "assets/images/bg_header_navi.png",
    this.showBackButton = true,
    this.rightButtons = const [],
  });

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
  @override
  Widget build(BuildContext context) {
    final double statusBarHeight = MediaQuery.of(context).padding.top;

    return Container(
      height: statusBarHeight + kToolbarHeight,
      decoration: BoxDecoration(
        image: backgroundImage != null
            ? DecorationImage(
          image: AssetImage(backgroundImage!),
          fit: BoxFit.cover,
        )
            : null,
        color: backgroundImage == null ? Colors.white : null,
      ),
      child: SafeArea(
        bottom: false,
        child: Stack(
          alignment: Alignment.center,
          children: [
            // Title ở giữa
            Text(
              title,
              style: const TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Colors.white,
              ),
              textAlign: TextAlign.center,
            ),
            // Back button bên trái
            if (showBackButton)
              Positioned(
                left: 12,
                child: CustomBackButton(),
              ),
            // Buttons bên phải
            if (rightButtons != null)
              Positioned(
                right: 12,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: rightButtons!,
                ),
              ),
          ],
        ),
      ),
    );
  }
}