import 'dart:io';

import 'package:cashier_reserve/common/manager/app_manager.dart';
import 'package:cashier_reserve/root_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'common/base/widgets.dart';
import 'common/local/cupertino_localizations_delegate.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  /// 状态栏沉浸
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: getAppBrightness(false),
      statusBarBrightness: getAppBrightness(false)));

  await AppManager.initThirdPackage();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    List<Locale> an = [
      const Locale('zh', 'CN'),
      const Locale('en', 'US'),
    ];
    List<Locale> ios = [
      const Locale('en', 'US'),
      const Locale('zh', 'CN'),
    ];

    return MaterialApp(
      locale: const Locale('zh'),
      localizationsDelegates: const [
        CupertinoLocalizationsDelegate(),
        // 添加Material Design本地化委托
        GlobalMaterialLocalizations.delegate,
        // 添加Cupertino本地化委托（用于iOS风格组件的本地化）
        GlobalCupertinoLocalizations.delegate,
        // 添加通用的Flutter本地化委托
        GlobalWidgetsLocalizations.delegate,
      ],
      title: 'Flutter Demo',
      supportedLocales: Platform.isIOS ? ios : an,
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        platform: TargetPlatform.iOS,
      ),
      home: const RootView(),
    );
  }
}
