import 'package:flutter/material.dart';
import 'app_theme_dark.dart';
import 'app_theme_light.dart';

import '../constant/enums/app_theme_enums.dart';

class ThemeNotifier extends ChangeNotifier {
  // ThemeData _currentTheme = AppThemeLight.instance.theme;
  // // ThemeData get currentTheme => LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
  // //             AppThemes.LIGHT.name
  // //         ? AppThemeLight.instance.theme
  // //         : AppThemeDark.instance.theme;
  // ThemeData get currentTheme {
  //   log("ThemeKey: ${LocaleManager.instance.getStringValue(PreferencesKeys.THEME)}");
  //   if (LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
  //       AppThemes.LIGHT.name) {
  //     log("light");
  //   } else {
  //     log("dark");
  //   }
  //   return LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
  //           AppThemes.LIGHT.name
  //       ? AppThemeLight.instance.theme
  //       : AppThemeDark.instance.theme;
  // }

  // ThemeData _currentTheme = AppThemeLight.instance.theme; // Mặc định là light

  // ThemeNotifier() {
  //   loadThemeFromPreferences();
  // }

  // Future<void> loadThemeFromPreferences() async {
  //   String themeKey =
  //       LocaleManager.instance.getStringValue(PreferencesKeys.THEME);
  //   log("ThemeNotifierKey:$themeKey ");
  //   if (themeKey == AppThemes.LIGHT.name) {
  //     _currentTheme = AppThemeLight.instance.theme;
  //   } else {
  //     _currentTheme = AppThemeDark.instance.theme;
  //   }
  //   notifyListeners(); // Thông báo cho các widget lắng nghe
  // }

  // ThemeData get currentTheme => _currentTheme;

  // AppThemes _currenThemeEnum = AppThemes.LIGHT;
  // AppThemes get currenThemeEnum =>
  //     LocaleManager.instance.getStringValue(PreferencesKeys.THEME) ==
  //             AppThemes.LIGHT.name
  //         ? AppThemes.LIGHT
  //         : AppThemes.DARK;
  // // AppThemes get currenThemeEnum => _currenThemeEnum;

  // void changeValue(AppThemes theme) {
  //   if (theme == AppThemes.LIGHT) {
  //     _currentTheme = ThemeData.dark();
  //   } else {
  //     _currentTheme = ThemeData.light();
  //   }
  //   notifyListeners();
  // }

  // void changeTheme() {
  //   if (_currenThemeEnum == AppThemes.LIGHT) {
  //     _currentTheme = AppThemeDark.instance.theme;
  //     _currenThemeEnum = AppThemes.DARK;
  //     LocaleManager.instance
  //         .setString(PreferencesKeys.THEME, AppThemes.DARK.name);
  //   } else {
  //     _currentTheme = AppThemeLight.instance.theme;
  //     _currenThemeEnum = AppThemes.LIGHT;
  //     LocaleManager.instance
  //         .setString(PreferencesKeys.THEME, AppThemes.LIGHT.name);
  //   }
  //   notifyListeners();
  // }

  ThemeData _currentTheme = AppThemeLight.instance.theme;
  ThemeData get currentTheme => _currentTheme;

  AppThemes _currenThemeEnum = AppThemes.LIGHT;
  AppThemes get currenThemeEnum => _currenThemeEnum;

  void changeValue(AppThemes theme) {
    if (theme == AppThemes.LIGHT) {
      _currentTheme = AppThemeLight.instance.theme;
    } else {
      _currentTheme = AppThemeDark.instance.theme;
    }
    notifyListeners();
  }

  void changeTheme() {
    if (_currenThemeEnum == AppThemes.LIGHT) {
      _currentTheme = AppThemeDark.instance.theme;
      _currenThemeEnum = AppThemes.DARK;
    } else {
      _currentTheme = AppThemeLight.instance.theme;
      _currenThemeEnum = AppThemes.LIGHT;
    }
    notifyListeners();
  }
}
