import 'package:flutter/material.dart';

class AuthDecoration extends StatelessWidget {
  final double minSquareSize;
  final double spacing;
  final Color color;

  const AuthDecoration({
    super.key,
    this.minSquareSize = 40,
    this.spacing = 24, // ✅ default 24px gap
    this.color = Colors.blue,
  });

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        final width = constraints.maxWidth;

        // Step 1: decide number of columns (max 4)
        int columns = 4;

        double calcSize(int cols) {
          final totalSpacing = spacing * (cols - 1);
          return (width - totalSpacing) / cols;
        }

        while (columns > 1 && calcSize(columns) < minSquareSize) {
          columns--;
        }

        final squareSize = calcSize(columns);

        // Step 2: compute how many rows are needed to fill screen height
        final height = constraints.maxHeight;
        final rows = (height / (squareSize + spacing)).ceil();

        return Column(
          children: List.generate(rows, (row) {
            return Padding(
              padding: EdgeInsets.all(spacing),
              child: Row(
                children: List.generate(columns, (col) {
                  return Padding(
                    padding: EdgeInsets.only(
                      right: col == columns - 1 ? 0 : spacing,
                    ),
                    child: SizedBox(
                      width: squareSize,
                      height: squareSize,
                      child: DecoratedBox(
                        decoration: BoxDecoration(
                          color: color,
                          borderRadius: BorderRadius.circular(6),
                        ),
                      ),
                    ),
                  );
                }),
              ),
            );
          }),
        );
      },
    );
  }
}
