import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

/// App-wide language, persisted across launches. Defaults to English
/// until a user preference is loaded/set — no device-locale auto-detect.
class LocaleController {
  LocaleController._();

  static const _prefsKey = 'app_locale';

  static final ValueNotifier<String> localeCode = ValueNotifier('en');

  static Future<void> load() async {
    final prefs = await SharedPreferences.getInstance();
    localeCode.value = prefs.getString(_prefsKey) ?? 'en';
  }

  static Future<void> setLocale(String code) async {
    localeCode.value = code;
    final prefs = await SharedPreferences.getInstance();
    await prefs.setString(_prefsKey, code);
  }
}
