import 'package:flutter/material.dart';
import 'screens/home_screen.dart';
import 'services/app_strings.dart';
import 'theme/app_theme.dart';
import 'theme/theme_controller.dart';
import 'theme/locale_controller.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await ThemeController.load();
  await AppStrings.preloadAll();
  await LocaleController.load();
  runApp(const PalmOilApp());
}

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

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<ThemeMode>(
      valueListenable: ThemeController.themeMode,
      builder: (context, mode, _) {
        return ValueListenableBuilder<String>(
          valueListenable: LocaleController.localeCode,
          builder: (context, _, _) {
            return MaterialApp(
              title: 'Palm Oil Ripeness AI',
              debugShowCheckedModeBanner: false,
              theme: AppTheme.light,
              darkTheme: AppTheme.dark,
              themeMode: mode,
              home: const HomeScreen(),
            );
          },
        );
      },
    );
  }
}
