import 'package:flutter/widgets.dart';
import 'package:get/get.dart';

import 'package:luckychit/l10n/app_localizations.dart';
import 'package:luckychit/l10n/app_localizations_en.dart';

/// Localizations from a [BuildContext] (widgets).
extension AppL10n on BuildContext {
  AppLocalizations get l10n {
    final l = AppLocalizations.of(this);
    assert(l != null, 'AppLocalizations not found — check GetMaterialApp delegates');
    return l!;
  }
}

/// Localizations when there is no [BuildContext] (GetX services, etc.).
/// Falls back to English if [Get.context] is missing or not localized yet.
final class L10nSvc {
  L10nSvc._();

  static AppLocalizations of() {
    final ctx = Get.context;
    final l = ctx != null ? AppLocalizations.of(ctx) : null;
    return l ?? AppLocalizationsEn();
  }
}
