import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class LocalizationService extends Translations {
  static Map<String, Map<String, String>> _keys = {};

  static const fallbackLocale = Locale('en', 'US');

  static const supportedLocales = [
    Locale('en', 'US'),
    Locale('uz', 'UZ'),
    Locale('ru', 'RU'),
  ];

  @override
  Map<String, Map<String, String>> get keys => _keys;

  // Load JSONs before starting the app
  static Future<void> init() async {
    _keys = {
      "en_US": await _loadJson("assets/translations/en.json"),
      "uz_UZ": await _loadJson("assets/translations/uz.json"),
      "ru_RU": await _loadJson("assets/translations/ru.json"),
    };
  }

  static Future<Map<String, String>> _loadJson(String path) async {
    final data = await rootBundle.loadString(path);
    return Map<String, String>.from(json.decode(data));
  }

  static void changeLocale(Locale locale) {
    Get.updateLocale(locale);
  }
}
