import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:niogu_ecommerce_v1/core/router/app_route.dart';
import 'package:sizer/sizer.dart';

void main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();

  await initializeDateFormatting('id_ID', null);

  Intl.defaultLocale = "id_ID";

  await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

  runApp(const MainApp());
}

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

  @override
  Widget build(BuildContext context) {
    return ProviderScope(
      child: Sizer(
        builder: (context, orientation, deviceType) {
          return MaterialApp.router(
            title: "Niogu",
            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: const [
              const Locale('id', 'ID'),
              const Locale('en', 'US'),
            ],
            locale: const Locale('id', 'ID'),
            debugShowCheckedModeBanner: false,
            theme: ThemeData(fontFamily: "Poppins", useMaterial3: true),
            builder: (context, child) {
              final mediaQueryData = MediaQuery.of(context);

              final scale = mediaQueryData.textScaler.clamp(
                minScaleFactor: 1.0,
                maxScaleFactor: 1.1,
              );

              return MediaQuery(
                data: mediaQueryData.copyWith(textScaler: scale),
                child: child!,
              );
            },
            routerConfig: AppRoute.router,
          );
        },
      ),
    );
  }
}
