/*
*@Author: XianKaiQun
*@Date: 2020-04-20 00:57:53
 * @LastEditors: wuwei 
 * @LastEditTime: 2025-03-19 17:24:22
*@Descripttion: 
*/
import 'dart:io';

import 'package:app_package/app_package.dart';
import 'package:app_package/src/route_observer_util.dart';
// import 'package:app_package/src/stores/push.dart';
// import 'package:catcher_2/core/catcher_2.dart';
// import 'package:catcher_2/mode/page_report_mode.dart';
// import 'package:catcher_2/model/catcher_2_options.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/single_child_widget.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'routes.dart';
import 'constants/env.dart' as env;
import 'stores/push.dart';
// import 'utils/catch_error.dart';
import 'view.dart';

appMain({
  required Map<String, WidgetBuilder> routes,
  required List<SingleChildWidget> providers,
  required bool isProdEnv,
}) async {
  ///设置环境
  env.isProdEnv = isProdEnv;

  ///沉浸式状态栏
  if (Platform.isAndroid) {
    SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(statusBarColor: Colors.transparent),
    );
  }
  await Future.wait([
    ///屏幕适配
    WisAdaptUtil.init(),

    ///持久化储存
    WisStorageUtil.init(),
  ]);
  print(
      '---------------------------------------------------------------------mainmainmain-------------------------------------------');

  ///推送依赖注入
  // if (!GetIt.I.isRegistered<PushGlobalStore>()) {
  //   GetIt.I.registerLazySingleton(() => PushGlobalStore());
  // }

  ///APP配置依赖注入
  GetIt.I.registerLazySingleton(() => AppGlobalStore());

  ///用户配置依赖注入
  GetIt.I.registerLazySingleton(() => AuthGlobalStore());

  ///小区配置依赖注入
  GetIt.I.registerLazySingleton(() => CommunityGlobalStore());

  GetIt.I.registerLazySingleton(() => RouteObserverUtil());

  ///合并路由

  appRoutes = {
    ...appRoutes,
    ...routes,
  };

  ///挂载providers
  ///[_globalProviders] App全局provider
  ///[providers]  各项业务私有的全局providers

  // List<SingleChildWidget> provider = [];

  Provider.debugCheckInvalidValueType = null;

  Widget app = MultiProvider(
    providers: [
      Provider(
        create: (_) => AppGlobalStore(),
        lazy: false,
      ),
    ],
    child: AppView(),
  );

  // final releaseConfig = Catcher2Options(
  //   PageReportMode(),
  //   [CatchHandle()],
  // );

  runApp(app);
}
