import 'package:flutter/material.dart';

import 'back_button.dart';

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final List<Widget> leftButtons;
  final List<Widget> rightButtons;
  final double height;

  const CustomAppBar({
    super.key,
    required this.title,
    this.leftButtons = const [],
    this.rightButtons = const [],
    this.height = 56,
  });

  /// 🔥 AppBar mặc định với nút back và title
  static CustomAppBar back({required String title}) {
    return CustomAppBar(
      title: title,
      leftButtons: [CustomBackButton()],
    );
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Container(
        height: height,
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: Stack(
          alignment: Alignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(children: leftButtons),
                Row(children: rightButtons),
              ],
            ),
            Center(
              child: Text(
                title,
                style: const TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                  color: Colors.black87,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

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