import 'package:doctor_app_flutter/providers/livecare_provider.dart';
import 'package:doctor_app_flutter/providers/medicine_provider.dart';
import 'package:doctor_app_flutter/providers/project_provider.dart';
import 'package:doctor_app_flutter/providers/schedule_provider.dart';
import 'package:doctor_app_flutter/util/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 './config/size_config.dart';
import './providers/auth_provider.dart';
import './providers/patients_provider.dart';
import './providers/hospital_provider.dart';
import './routes.dart';
import 'config/config.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    AppGlobal.CONTEX = context;
    return LayoutBuilder(
      builder: (context, constraints) {
        return OrientationBuilder(builder: (context, orientation) {
          SizeConfig().init(constraints, orientation);
          return MultiProvider(
            providers: [
              ChangeNotifierProvider<PatientsProvider>(
                  create: (context) => PatientsProvider()),
              ChangeNotifierProvider<AuthProvider>(
                  create: (context) => AuthProvider()),
              ChangeNotifierProvider<HospitalProvider>(
                  create: (context) => HospitalProvider()),
              ChangeNotifierProvider<ProjectProvider>(
                create: (context) => ProjectProvider(),
              ),
              ChangeNotifierProvider<ScheduleProvider>(
                create: (context) => ScheduleProvider(),
              ),
              ChangeNotifierProvider<LiveCareProvider>(
                create: (context) => LiveCareProvider(),
              ),
              ChangeNotifierProvider<MedicineProvider>(create: (context) => MedicineProvider(),),
            ],
            child: Consumer<ProjectProvider>(
              builder: (context,projectProvider,child) => MaterialApp(
                showSemanticsDebugger: false,
                title: 'Flutter Demo',
                locale: projectProvider.appLocal,
                localizationsDelegates: [
                  TranslationBaseDelegate(),
                  GlobalMaterialLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                ],
                supportedLocales: [
                  const Locale('ar', ''), // Arabic
                  const Locale('en', ''), // English
                ],
                theme: ThemeData(
                  primarySwatch: Colors.grey,
                  primaryColor: Colors.grey,
                  buttonColor: Hexcolor('#B8382C'),
                  fontFamily: 'WorkSans',
                  dividerColor: Colors.grey[350],
                  backgroundColor:  Color.fromRGBO(255,255,255, 1)
                ),
                initialRoute: INIT_ROUTE,
                routes: routes,
                debugShowCheckedModeBanner: false,
              )
            ),
          );
        });
      },
    );
  }
}
