import 'package:flutter/widgets.dart';
import 'package:flyinsono/architecture/services/modules/config_language.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/js_platform/methods.dart';
import 'package:get/get.dart';

import 'base.dart';

class OnChangeLanguageHandler extends MethodHandlerBase {
  OnChangeLanguageHandler() : super(TargetMethodName.OnChangeLanguage);
  @override
  void execute(List<String> args) {
    var languageCode = args[0];
    final languageService = Get.find<LanguageService>();
    if (languageService.ifLocalIs(languageCode)) {
      return;
    }
    var lans = languageCode.split('-');
    Store.app.updateLocale(Locale(lans[0], lans[1]));
    languageService.reload();
  }
}
