import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';

import 'core/app_theme.dart';
import 'core/env.dart';
import 'core/routes.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Inisialisasi Supabase
  await Supabase.initialize(
    url: Env.supabaseUrl,
    anonKey: Env.supabaseAnonKey,
  );

  // Inisialisasi OneSignal
  OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
  OneSignal.initialize(Env.oneSignalAppId);
  OneSignal.Notifications.requestPermission(true);

  runApp(const ProviderScope(child: JtaApp()));
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'JTA – Jamur Tiram Antirogo',
      debugShowCheckedModeBanner: false,
      theme: AppTheme.light,
      initialRoute: AppRoutes.splash,
      onGenerateRoute: AppRoutes.generateRoute,
      builder: (context, child) {
        // Nonaktifkan text scaling sistem agar UI tidak rusak
        return MediaQuery(
          data: MediaQuery.of(
            context,
          ).copyWith(textScaler: TextScaler.noScaling),
          child: child!,
        );
      },
    );
  }
}
