import 'package:diplomaticquarterapp/routes.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';
import 'package:diplomaticquarterapp/services/robo_search/search_provider.dart';
import 'config/size_config.dart';
import 'core/viewModels/project_view_model.dart';
import 'locator.dart';
import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart';

void main() async {
  setupLocator();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  /// static final _myTabbedPageKey = new GlobalKey<_LandingPageState>();
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        return OrientationBuilder(
          builder: (context, orientation) {
            SizeConfig().init(constraints, orientation);
            return MultiProvider(
              providers: [
                ChangeNotifierProvider<ProjectViewModel>(
                  create: (context) => ProjectViewModel(),
                ),
                ChangeNotifierProvider<SearchProvider>(
                    create: (context) => SearchProvider()),
                ChangeNotifierProvider.value(
                  value: SearchProvider(),
                ),
                StreamProvider.value(
                  value: RobotProvider().intStream(),
                  initialData: RobotProvider().setValue({}),
                )
              ],
              child: Consumer<ProjectViewModel>(
                builder: (context, projectProvider, child) => MaterialApp(
                  showSemanticsDebugger: false,
                  title: 'Diplomatic Quarter App',
                  locale: projectProvider.appLocal,
                  localizationsDelegates: [
                    TranslationBaseDelegate(),
                    GlobalMaterialLocalizations.delegate,
                    GlobalWidgetsLocalizations.delegate,
                  ],
                  supportedLocales: [
                    const Locale('ar', ''), // Arabic
                    const Locale('en', ''), // English
                  ],
                  theme: ThemeData(
                    primarySwatch: Colors.blue,
                    visualDensity: VisualDensity.adaptivePlatformDensity,
                    brightness: Brightness.light,
                    pageTransitionsTheme: const PageTransitionsTheme(
                      builders: {
                        TargetPlatform.android: ZoomPageTransitionsBuilder(),
                        TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
                      },
                    ),
                    hintColor: Colors.grey[400],
                    disabledColor: Colors.grey[300],
                    errorColor: Color.fromRGBO(235, 80, 60, 1.0),
                    scaffoldBackgroundColor:Hexcolor('#E9E9E9'),// Colors.grey[100],
                    textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
                    textSelectionHandleColor: Colors.grey,
                    canvasColor: Colors.white,
                    backgroundColor: Color.fromRGBO(255, 255, 255, 1),
                    highlightColor: Colors.grey[100].withOpacity(0.4),
                    splashColor: Colors.transparent,
                    primaryColor: Colors.grey,
                    bottomSheetTheme:BottomSheetThemeData(
                      backgroundColor: Hexcolor('#E0E0E0')
                    ) ,
                    cursorColor: Colors.grey,
                    iconTheme: IconThemeData(),
                    appBarTheme: AppBarTheme(
                      color: Colors.grey[700],
                      brightness: Brightness.light,
                      elevation: 0.0,
                      actionsIconTheme: IconThemeData(
                        color: Colors.grey[800],
                      ),
                    ),
                  ),
                  initialRoute: HOME,
                  routes: routes,
                  debugShowCheckedModeBanner: false,
                ),
              ),
            );
          },
        );
      },
    );
  }
}
