import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/dependency_injection/get_it.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/flavors/flavor.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/routes/router.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/data/repositories/counter_repository_impl.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/domain/repositories/counter_repository.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/gen/app_localizations.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/presentation/features/counter/blocs/counter_bloc/counter_bloc.dart';
import 'package:wyatt_bloc_helper/wyatt_bloc_helper.dart';

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

  Widget _flavorBanner(Widget child) {
    final flavor = Flavor.get();
    if (flavor.banner != null && !kReleaseMode) {
      return Directionality(
        textDirection: TextDirection.ltr,
        child: Banner(
          location: BannerLocation.topEnd,
          message: flavor.banner!,
          color: flavor.bannerColor,
          child: child,
        ),
      );
    }

    return child;
  }

  @override
  Widget build(BuildContext context) => MultiProvider(
      repositoryProviders: [
        RepositoryProvider<CounterRepository>(
          create: (_) => CounterRepositoryImpl(counterDataSource: getIt()),
        ),
      ],
      blocProviders: [
        BlocProvider<CounterBloc>(
          create: (_) => CounterBloc(),
        ),
      ],
      child: _flavorBanner(
        MaterialApp.router(
          title: '{{#titleCase}}{{display_name}}{{/titleCase}}',
          debugShowCheckedModeBanner: false,
          routerDelegate: AppRouter.router.routerDelegate,
          routeInformationParser: AppRouter.router.routeInformationParser,
          routeInformationProvider: AppRouter.router.routeInformationProvider,
          localizationsDelegates: const [
            AppLocalizations.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          supportedLocales: AppLocalizations.supportedLocales,
        ),
      ),
    );
}
