import 'package:flutter/material.dart';
import 'package:siro_driver/constant/box_name.dart';
import 'package:siro_driver/main.dart';
import 'package:get/get.dart';
import '../local/local_controller.dart';

class SettingController extends GetxController {
  bool isGoogleMapsEnabled = false;
  bool isMapDarkMode = false;
  bool isDarkMode = false;

  void onChangMapApp() {
    isGoogleMapsEnabled = !isGoogleMapsEnabled;
    box.write(BoxName.googlaMapApp, isGoogleMapsEnabled);
    update();
  }

  void toggleMapTheme() {
    isMapDarkMode = !isMapDarkMode;
    box.write('isMapDarkMode', isMapDarkMode);
    update();
  }

  void toggleAppTheme() {
    isDarkMode = !isDarkMode;
    box.write('isDarkMode', isDarkMode);
    
    // Switch theme instantly across the app
    Get.changeThemeMode(isDarkMode ? ThemeMode.dark : ThemeMode.light);
    
    // Update the theme using the LocaleController to ensure correct fonts/colors are refreshed
    if (Get.isRegistered<LocaleController>()) {
      Get.find<LocaleController>().refreshTheme();
    }
    
    update();
  }

  @override
  void onInit() {
    isGoogleMapsEnabled = box.read(BoxName.googlaMapApp) ?? false;
    isMapDarkMode = box.read('isMapDarkMode') ?? false;
    isDarkMode = box.read('isDarkMode') ?? false;
    
    super.onInit();
  }
}

