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

class RShimmerList extends StatelessWidget {
  const RShimmerList({super.key, this.itemCount = 6, this.itemBuilder, this.height = 80, this.isSeparated = false});

  final int itemCount;
  final double height;
  final bool isSeparated;
  final IndexedWidgetBuilder? itemBuilder;

  @override
  Widget build(BuildContext context) {
    final builder =
        itemBuilder ??
        (_, __) => Container(
          height: height,
          margin: const EdgeInsets.symmetric(vertical: 8),
          decoration: BoxDecoration(color: Colors.grey[300], borderRadius: BorderRadius.circular(8)),
        );

    final children = List.generate(itemCount, (index) => builder(context, index));

    return Shimmer.fromColors(
      baseColor: Colors.grey.shade300,
      highlightColor: Colors.grey.shade100,
      child: isSeparated
          ? ListView.separated(
              itemCount: itemCount,
              padding: const EdgeInsets.all(12),
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: builder,
              separatorBuilder: (_, __) => const SizedBox(height: 8),
            )
          : ListView.builder(
              itemCount: itemCount,
              padding: const EdgeInsets.all(12),
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemBuilder: builder,
            ),
    );
  }
}
