import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:chain_studio/l10n/app_localizations.dart';
import 'package:chain_studio/theme/theme.dart';

/// Recreates the exact DocReaderSheet code path that
/// welcome.dart uses, including ChainTheme.markdownStyle, so a
/// regression in either rootBundle, the markdown parser, or
/// the style sheet surfaces here instead of only at runtime
/// when an operator clicks a doc card.
void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  testWidgets('DocReaderSheet renders all four german + english docs',
      (tester) async {
    final theme = ChainTheme.light();
    for (final slug in ['architecture', 'security', 'audit', 'flows']) {
      for (final locale in ['de', 'en']) {
        final path = locale == 'de'
            ? 'assets/docs/${slug}_de.md'
            : 'assets/docs/$slug.md';
        final text = await rootBundle.loadString(path);

        await tester.pumpWidget(MaterialApp(
          locale: Locale(locale),
          supportedLocales: const [Locale('en'), Locale('de')],
          localizationsDelegates: const [
            AppLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          theme: theme,
          home: Scaffold(
            body: Markdown(
              data: text,
              padding: const EdgeInsets.all(8),
              selectable: true,
              styleSheet: ChainTheme.markdownStyle(theme),
            ),
          ),
        ));
        await tester.pump();
        // ignore: avoid_print
        print('rendered $path');
      }
    }
  });
}
