import 'package:block_seasons/core/rng.dart';
import 'package:block_seasons/game/engine/piece_generator.dart';
import 'package:block_seasons/l10n/gen/app_localizations.dart';
import 'package:block_seasons/game/models/stage.dart';
import 'package:block_seasons/state/providers.dart';
import 'package:block_seasons/ui/screens/game_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';

final _stage = StageConfig.fromJson({
  'id': 'golden_stage',
  'seed': 777,
  'moveLimit': 22,
  'preset': [
    {'x': 2, 'y': 2, 't': 'gem'},
    {'x': 5, 'y': 2, 't': 'gem'},
    {'x': 2, 'y': 5, 't': 'gem'},
    {'x': 3, 'y': 7, 't': 'filled', 'c': 1},
    {'x': 4, 'y': 7, 't': 'filled', 'c': 2},
    {'x': 5, 'y': 7, 't': 'filled', 'c': 3},
    {'x': 1, 'y': 6, 't': 'filled', 'c': 4},
  ],
  'objectives': [
    {'type': 'clearGems', 'count': 3},
  ],
  'stars': {
    'two': {'movesLeft': 5},
    'three': {'movesLeft': 10},
  },
  'generatorProfile': 'mid',
});

void main() {
  testWidgets('game screen golden snapshot', (tester) async {
    await tester.binding.setSurfaceSize(const Size(390, 844)); // iPhone-ish
    final container = ProviderContainer();
    addTearDown(container.dispose);
    container
        .read(gameSessionProvider.notifier)
        .startStage(_stage, generator: PieceGenerator(SeededRng(7)));

    await tester.pumpWidget(
      UncontrolledProviderScope(
        container: container,
        child: MaterialApp(
          debugShowCheckedModeBanner: false,
          localizationsDelegates: AppLocalizations.localizationsDelegates,
          supportedLocales: AppLocalizations.supportedLocales,
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(
              seedColor: const Color(0xFF5B7FFF),
              brightness: Brightness.dark,
            ),
            useMaterial3: true,
          ),
          home: const GameScreen(),
        ),
      ),
    );
    await tester.pumpAndSettle();

    await expectLater(
      find.byType(GameScreen),
      matchesGoldenFile('goldens/game_screen.png'),
    );
  });
}
