import 'package:driverapp/pages/splash_screen_page.dart';
import 'package:driverapp/uitl/translations_delegate_base.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';

import 'config/size_config.dart';
import 'core/viewModels/authentication_view_model.dart';
import 'core/viewModels/project_view_model.dart';
import 'locator.dart';

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

class MyApp extends StatelessWidget {
  @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<AuthenticationViewModel>(
                  create: (context) => AuthenticationViewModel(),
                ),
              ],
              child: Consumer<ProjectViewModel>(
                builder: (context, projectProvider, child) => MaterialApp(
                  showSemanticsDebugger: false,
                  title: 'Driver App',
                  locale: projectProvider.appLocal,
                  localizationsDelegates: [
                    TranslationBaseDelegate(),
                    GlobalMaterialLocalizations.delegate,
                    GlobalWidgetsLocalizations.delegate,
                  ],
                  supportedLocales: [
                    const Locale('ar', ''), // Arabic
                    const Locale('en', ''), // English
                  ],
                  theme: ThemeData(
                    fontFamily: 'Metropolis',
                    primarySwatch: Colors.blue,
                    visualDensity: VisualDensity.adaptivePlatformDensity,
                    brightness: Brightness.light,
                    pageTransitionsTheme: const PageTransitionsTheme(
                      builders: {
                        TargetPlatform.android: ZoomPageTransitionsBuilder(),
                        TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
                      },
                    ),
                    scaffoldBackgroundColor: Color.fromRGBO(239, 245, 245, 1),
                    hintColor: Colors.grey[400],
                    disabledColor: Colors.grey[300],
                    bottomSheetTheme: BottomSheetThemeData(
                        backgroundColor: Color.fromRGBO(239, 245, 245, 1)),
                    errorColor: Color.fromRGBO(235, 80, 60, 1.0),
                    textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
                    textSelectionHandleColor: Color.fromRGBO(80, 100, 253, 1.0),
                    canvasColor: Colors.white,
                    backgroundColor: Color.fromRGBO(255, 255, 255, 1),
                    highlightColor: Colors.grey[100].withOpacity(0.4),
                    splashColor: Colors.transparent,
                    primaryColor: Color(0xff3ABBBA),
                    cursorColor: Color.fromRGBO(78, 62, 253, 1.0),
                    iconTheme: IconThemeData(),
                    dividerColor: Color.fromRGBO(112, 112, 112, 1.0),
                    appBarTheme: AppBarTheme(
                      color: Colors.transparent,
                      brightness: Brightness.light,
                      elevation: 0.0,
                      actionsIconTheme: IconThemeData(
                        color: Colors.grey[800],
                      ),
                    ),
                  ),
                  home: SplashScreenPage(),
//                  initialRoute: '/',
//                  routes: {'/': (context) => RootPage()},
                  debugShowCheckedModeBanner: false,
                ),
              ),
            );
          },
        );
      },
    );
  }
}
