import 'package:get/get.dart';

import '../../../../config/theme/theme_extensions/theme_extension.dart';
import '../../../../config/translations/strings_enum.dart';
import '../../../data/sp/ix_sp.dart';

/// 主题模式信息
class ThemeModeInfo {
  final String code; // 'system', 'dark', 'light'
  final String name;

  ThemeModeInfo({required this.code, required this.name});
}

class ThemeController extends GetxController {
  /// 当前选中的主题模式
  final selectedMode = 'system'.obs;

  /// 主题模式列表
  List<ThemeModeInfo> get themeModes => [
    ThemeModeInfo(code: 'system', name: Strings.followSystem.tr),
    ThemeModeInfo(code: 'dark', name: Strings.darkMode.tr),
    ThemeModeInfo(code: 'light', name: Strings.lightMode.tr),
  ];

  @override
  void onInit() {
    super.onInit();
    // 加载当前主题模式
    selectedMode.value = IXSP.getThemeMode();
  }

  /// 选择主题模式
  void selectThemeMode(String mode) {
    if (selectedMode.value == mode) return;

    selectedMode.value = mode;
    IXSP.setThemeMode(mode);

    // 应用主题
    _applyTheme(mode);
  }

  /// 应用主题
  void _applyTheme(String mode) {
    ReactiveTheme.setThemeMode(mode);
  }
}
