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

/// Lays out a list of widgets (intended for [ProfileMenuItem]s) in a responsive grid.
/// It uses [Wrap] and manually calculates item width based on the screen size.
class ProfileMenuGrid extends StatelessWidget {
  final int crossAxisCount;
  final List<Widget> children;

  const ProfileMenuGrid({
    super.key,
    required this.children,
    this.crossAxisCount = 2,
  });

  @override
  Widget build(BuildContext context) {
    // Spacing between items
    final double spacing = UiConstants.space3;

    return LayoutBuilder(
      builder: (context, constraints) {
        final totalWidth = constraints.maxWidth;
        final totalSpacingWidth = spacing * (crossAxisCount - 1);
        final itemWidth = (totalWidth - totalSpacingWidth) / crossAxisCount;

        return Wrap(
          spacing: spacing,
          runSpacing: spacing,
          children: children.map((child) {
            return SizedBox(
              width: itemWidth,
              child: child,
            );
          }).toList(),
        );
      },
    );
  }
}
