import 'package:flutter/material.dart';

/// AppBar personnalisée avec support du thème et design moderne.
///
/// Ce widget fournit une AppBar cohérente avec le thème de l'application
/// et des options de personnalisation.
///
/// **Usage:**
/// ```dart
/// CustomAppBar(
///   title: 'Mon Écran',
///   actions: [
///     IconButton(icon: Icon(Icons.search), onPressed: () {}),
///   ],
/// )
/// ```
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppBar({
    required this.title,
    super.key,
    this.actions = const [],
    this.leading,
    this.automaticallyImplyLeading = true,
    this.centerTitle,
    this.elevation,
  });

  final String title;
  final List<Widget> actions;
  final Widget? leading;
  final bool automaticallyImplyLeading;
  final bool? centerTitle;
  final double? elevation;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return AppBar(
      title: Text(title),
      actions: actions,
      leading: leading,
      automaticallyImplyLeading: automaticallyImplyLeading,
      centerTitle: centerTitle,
      elevation: elevation ?? 0,
      backgroundColor: theme.colorScheme.surface,
      foregroundColor: theme.colorScheme.onSurface,
    );
  }

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