import 'package:flutter/material.dart';
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.dart';

class SceneGrid extends StatelessWidget {
  final List<dynamic> scenes;
  final String? loadingSceneId;
  final bool disablePlayButton;
  final Map<String, bool> loadingStates;

  const SceneGrid({
    required this.scenes,
    required this.loadingSceneId,
    required this.disablePlayButton,
    required this.loadingStates,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        mainAxisSpacing: 12,
        crossAxisSpacing: 12,
        childAspectRatio: 1.5,
      ),
      itemCount: scenes.length,
      itemBuilder: (context, index) {
        final scene = scenes[index];
        final isLoading = loadingSceneId == scene.id;
        final isSwitchLoading = loadingStates[scene.id] ?? false;

        return SceneItem(
          scene: scene,
          isLoading: isLoading,
          disablePlayButton: disablePlayButton,
          isSwitchLoading: isSwitchLoading,
        );
      },
    );
  }
}
