import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:redux_sample/actions/actions.dart';
import 'package:redux_sample/containers/add_todo.dart';
import 'package:redux_sample/localization.dart';
import 'package:redux_sample/models/models.dart';
import 'package:redux_sample/presentation/home_screen.dart';
import 'package:todos_app_core/todos_app_core.dart';

class ReduxApp extends StatelessWidget {
  final Store<AppState> store;

  const ReduxApp({super.key, required this.store});

  @override
  Widget build(BuildContext context) {
    return StoreProvider(
      store: store,
      child: MaterialApp(
        onGenerateTitle: (context) => ReduxLocalizations.of(context).appTitle,
        theme: ArchSampleTheme.lightTheme,
        darkTheme: ArchSampleTheme.darkTheme,
        localizationsDelegates: [
          ArchSampleLocalizationsDelegate(),
          ReduxLocalizationsDelegate(),
        ],
        routes: {
          ArchSampleRoutes.home: (context) {
            return HomeScreen(
              onInit: () {
                StoreProvider.of<AppState>(context).dispatch(LoadTodosAction());
              },
            );
          },
          ArchSampleRoutes.addTodo: (context) => AddTodo(),
        },
      ),
    );
  }
}
