import 'package:flutter/material.dart';
import 'mih_config/mih_env.dart';
import 'mih_config/mih_routeGenerator.dart';
import 'mih_config/mih_theme.dart';

class MzansiInnovationHub extends StatefulWidget {
  const MzansiInnovationHub({
    super.key,
  });

  @override
  State<MzansiInnovationHub> createState() => _MzansiInnovationHubState();

  // ignore: library_private_types_in_public_api
  static _MzansiInnovationHubState? of(BuildContext context) =>
      context.findAncestorStateOfType<_MzansiInnovationHubState>();
}

class _MzansiInnovationHubState extends State<MzansiInnovationHub> {
  late MihTheme theme;

  Color getPrimany() {
    return theme.primaryColor();
  }

  String getTitle() {
    if (AppEnviroment.getEnv() == "Dev") {
      return "Dev | MIH App: Mzansi Innovation Hub";
    } else {
      return "MIH App: Mzansi Innovation Hub";
    }
  }

  void changeTheme(ThemeMode themeMode) {
    setState(() {
      if (themeMode == ThemeMode.light) {
        setState(() {
          theme.mode = "Light";
        });
      } else if (themeMode == ThemeMode.dark) {
        setState(() {
          theme.mode = "Dark";
        });
      } else {
        setState(() {
          theme.mode = "Dark";
        });
      }
    });
  }

  @override
  void initState() {
    theme = MihTheme();
    // var systemTheme =
    //     SchedulerBinding.instance.platformDispatcher.platformBrightness;
    // bool isDarkMode = systemTheme == Brightness.dark;
    // if (isDarkMode) {
    //   theme.mode = "Dark";
    // } else {
    //   theme.mode = "Light";
    // }
    theme.mode = "Dark";
    theme.platform = Theme.of(context).platform;
    super.initState();
    //doInit();
  }

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.sizeOf(context).width;
    theme.setScreenType(width);
    precacheImage(theme.loadingImage(), context);
    return MaterialApp(
      title: getTitle(),
      themeMode: ThemeMode.dark,
      theme: theme.getThemeData(),
      darkTheme: theme.getThemeData(),
      debugShowCheckedModeBanner: false,
      initialRoute: '/',
      onGenerateRoute: RouteGenerator.generateRoute,
    );
  }
}
