import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';
import '../theme/app_colors.dart';
import '../theme/app_radius.dart';

class FSShimmer extends StatelessWidget {
  final double width;
  final double height;
  final double borderRadius;

  const FSShimmer({
    super.key,
    this.width = double.infinity,
    required this.height,
    this.borderRadius = 8,
  });

  /// Card-shaped shimmer placeholder
  factory FSShimmer.card({double height = 120}) => FSShimmer(height: height, borderRadius: 12);

  /// Text line shimmer
  factory FSShimmer.line({double width = 200, double height = 14}) =>
      FSShimmer(width: width, height: height, borderRadius: 4);

  /// Circle shimmer (for avatars)
  factory FSShimmer.circle({double size = 40}) =>
      FSShimmer(width: size, height: size, borderRadius: size / 2);

  @override
  Widget build(BuildContext context) {
    return Shimmer.fromColors(
      baseColor: AppColors.panelLight,
      highlightColor: AppColors.panelLighter,
      child: Container(
        width: width,
        height: height,
        decoration: BoxDecoration(
          color: AppColors.panelLight,
          borderRadius: BorderRadius.circular(borderRadius),
        ),
      ),
    );
  }
}

/// A preset shimmer layout for list items
class FSShimmerList extends StatelessWidget {
  final int itemCount;

  const FSShimmerList({super.key, this.itemCount = 5});

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      physics: const NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      itemCount: itemCount,
      separatorBuilder: (_, __) => const SizedBox(height: 12),
      itemBuilder: (_, __) => const FSShimmer(height: 80, borderRadius: 12),
    );
  }
}