import 'package:flutter/material.dart';
import '../../../shared/design_system/tokens/app_colors.dart';
import '../../../shared/design_system/tokens/app_typography.dart';
import '../../../shared/widgets/mini_avatar.dart';

/// UnionFlow Mobile - Composant DRY : MiniHeaderBar
/// Remplace l'AppBar massive. Maximum 35-40px de hauteur.
class MiniHeaderBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final String? profileImageUrl;
  final Widget? trailing;

  const MiniHeaderBar({
    Key? key,
    required this.title,
    this.profileImageUrl,
    this.trailing,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final isDark = Theme.of(context).brightness == Brightness.dark;

    return Container(
      color: Theme.of(context).scaffoldBackgroundColor,
      padding: EdgeInsets.only(
        top: MediaQuery.of(context).padding.top + 8, // Respecte la Status Bar
        bottom: 8,
        left: 16,
        right: 16,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          // Bouton Menu/Profil à gauche
          GestureDetector(
            onTap: () {
              Scaffold.of(context).openDrawer();
            },
            child: MiniAvatar(
              imageUrl: profileImageUrl,
              fallbackText: 'ME',
              size: 28,
            ),
          ),
          
          // Titre central (Petit)
          Text(
            title,
            style: AppTypography.headerSmall.copyWith(
              color: isDark ? AppColors.textPrimaryDark : AppColors.textPrimaryLight,
            ),
          ),
          
          if (trailing != null) trailing! else const SizedBox(width: 28),
        ],
      ),
    );
  }

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