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

/// Data model for a breadcrumb item.
class BreadcrumbItem {
  final String title;
  final void Function(BuildContext)? onTap;
  final String? tooltip;

  BreadcrumbItem({
    required this.title,
    this.onTap,
    this.tooltip,
  });
}

/// Breadcrumb UI widget
class BreadcrumbNavigation extends StatelessWidget {
  final List<BreadcrumbItem> breadcrumbItems;
  final bool isDesktop;

  const BreadcrumbNavigation({
    super.key,
    required this.breadcrumbItems,
    required this.isDesktop,
  });

  @override
  Widget build(BuildContext context) {
    return Wrap(
      crossAxisAlignment: WrapCrossAlignment.center, // Align text + arrows
      children: List.generate(breadcrumbItems.length * 2 - 1, (index) {
        if (index.isEven) {
          final int itemIndex = index ~/ 2;
          final item = breadcrumbItems[itemIndex];
          final bool isLast = itemIndex == breadcrumbItems.length - 1;

          // If last item or no tap handler, show as plain black text without tooltip/click
          if (isLast || item.onTap == null) {
            return Text(
              item.title,
              style: GoogleFonts.poppins(
                // fontSize: isDesktop ? 16 : 14,
                // fontWeight: FontWeight.w600,
                color: Colors.black,
                decoration: TextDecoration.none,
              ),
            );
          } else {
            // If clickable, wrap with GestureDetector + Tooltip + MouseRegion
            return MouseRegion(
              cursor: SystemMouseCursors.click,
              child: Tooltip(
                message: item.tooltip ?? item.title,
                child: GestureDetector(
                  onTap: () => item.onTap!(context),
                  child: Text(
                    item.title,
                    style: GoogleFonts.poppins(
                      // fontSize: isDesktop ? 16 : 14,
                      // fontWeight: FontWeight.w600,
                      color: Colors.black54,
                      decoration: TextDecoration.none,
                    ),
                  ),
                ),
              ),
            );
          }
        } else {
          // Arrow between items
          return Padding(
            padding: const EdgeInsets.symmetric(horizontal: 4.0),
            child: Align(
              alignment: Alignment.center,
              child: Text(
                ">",
                style: TextStyle(
                  color: Colors.black54,
                  fontSize: isDesktop ? 16 : 14,
                  height: 1.2,
                ),
              ),
            ),
          );
        }
      }),
    );
  }
}

// import 'package:flutter/material.dart';
// import 'package:google_fonts/google_fonts.dart';
//
// class BreadcrumbItem {
//   final String title;
//   final void Function(BuildContext)? onTap;
//   final String? tooltip;
//
//   BreadcrumbItem({
//     required this.title,
//     this.onTap,
//     this.tooltip,
//   });
// }
//
// class BreadcrumbNavigation extends StatelessWidget {
//   final List<BreadcrumbItem> breadcrumbItems;
//   final bool isDesktop;
//
//   const BreadcrumbNavigation({
//     super.key,
//     required this.breadcrumbItems,
//     required this.isDesktop,
//   });
//
//   @override
//   Widget build(BuildContext context) {
//     return Wrap(
//       crossAxisAlignment: WrapCrossAlignment.center, // Ensures vertical alignment
//       children: List.generate(breadcrumbItems.length * 2 - 1, (index) {
//         if (index.isEven) {
//           final int itemIndex = index ~/ 2;
//           final item = breadcrumbItems[itemIndex];
//           final bool isLast = itemIndex == breadcrumbItems.length - 1;
//
//           return Tooltip(
//             message: item.tooltip ?? item.title,
//             child: GestureDetector(
//               onTap: isLast || item.onTap == null
//                   ? null
//                   : () => item.onTap!(context), // pass context
//               child: Text( item.title,
//                   style: GoogleFonts.poppins(
//                     fontSize: isDesktop ? 16 : 14,
//                     fontWeight: FontWeight.w600,
//                     color: isLast ? Colors.black : Colors.black54,
//                     decoration: TextDecoration.none,
//                   ),
//               ),
//             ),
//           );
//         } else {
//           // Arrow between items, centered vertically
//           return Padding(
//             padding: const EdgeInsets.symmetric(horizontal: 4.0),
//             child: Align(
//               alignment: Alignment.center,
//               child: Text(" > ",
//                 style: TextStyle(
//                   color: Colors.black54,
//                   fontSize: isDesktop ? 16 : 14,
//                   height: 1.2, // Aligns better with text
//                 ),
//               ),
//             ),
//           );
//         }
//       }),
//     );
//   }
// }