import 'dart:ui';

import 'package:flame/game.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:nes_ui/nes_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:shitman/game/shitman_game.dart';
import 'package:shitman/ui/in_game_ui.dart';

class AnyInputScrollBehavior extends MaterialScrollBehavior {
  // Override behavior methods and getters like dragDevices
  @override
  Set<PointerDeviceKind> get dragDevices => {
    PointerDeviceKind.touch,
    PointerDeviceKind.mouse,
    PointerDeviceKind.trackpad,
  };
}

void main() {
  LicenseRegistry.addLicense(() async* {
    final license = await rootBundle.loadString('google_fonts/OFL.txt');
    yield LicenseEntryWithLineBreaks(['google_fonts'], license);
  });

  runApp(
    EasyLocalization(
      supportedLocales: [Locale('en'), Locale('da'), Locale('de')],
      path: 'assets/translations',
      fallbackLocale: Locale('en'),
      startLocale: Locale('en'),
      useOnlyLangCode: true,
      useFallbackTranslations: true,
      child: Shitman(),
    ),
  );
}

class Shitman extends StatelessWidget {
  const Shitman({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      scrollBehavior: AnyInputScrollBehavior(),
      locale: context.locale,
      theme: flutterNesTheme(brightness: Brightness.dark),
      themeMode: ThemeMode.dark,
      home: GameWidget(
        game: ShitmanGame(),
        initialActiveOverlays: const ['MainMenu'],
        overlayBuilderMap: {
          InGameUI.overlayID: (context, game) =>
              InGameUI(game as ShitmanGame),
          MainMenuUI.overlayID: (context, game) =>
              MainMenuUI(game as ShitmanGame),
          SettingsUI.overlayID: (context, game) =>
              SettingsUI(game as ShitmanGame),
          PauseMenuUI.overlayID: (context, game) =>
              PauseMenuUI(game as ShitmanGame),
        },
      ),
    );
  }
}
