import 'package:flyinsono/architecture/services/modules/config_language.dart';
import 'package:get/get.dart';

class translation_delegate_helper {
  translation_delegate_helper();

  /// 后端语言包
  static final languageService = Get.find<LanguageService>();

  /// 获取application模块的翻译值
  static String getValuesFromApplication(String code) {
    var value = languageService.findLanguageValueByCode('application', code);
    return value;
  }

  /// 获取location模块的翻译值
  static String getValuesFromLocation(String? code) {
    var value = languageService.findLanguageValueByCode('location', code ?? '');
    return value;
  }

  ///翻译图片描述
  static String translateDescription(
      String? application, String? applicationCategory) {
    String description = '';
    //判断是否是老数据，老数据里面没有applicationCategory的字段
    if (applicationCategory != null) {
      //如果不是老数据
      description = getDescription(application!, applicationCategory);
    } else {
      //如果是老数据
      // List<String> oldApplicationToList = application!.split('-');
      // String oldApplication = oldApplicationToList[0];
      // String oldApplicationCategory = oldApplicationToList[1];
      description = "Old data";
      //description = getDescription(oldApplication, oldApplicationCategory);
    }

    return description;
  }

  ///翻译图片定位描述
  static String translateLocationDescription(
      String? quadrant, String? position) {
    String description = '';
    description = getLocationDescription(quadrant, position);

    return description;
  }

  static String getLocationDescription(String? quadrant, String? position) {
    String description = '';
    if (quadrant != '' || quadrant != '') {
      description = getValuesFromLocation(quadrant) +
          "-" +
          getValuesFromLocation(position);
    } else {
      description = '';
    }
    return description;
  }

  static String getDescription(String application, String applicationCategory) {
    String description = '';
    if (applicationCategory == "FromSonopost" ||
        application == "FromSonopost") {
      description = getValuesFromApplication("FromSonopost");
    } else {
      if (application != '' || applicationCategory != '') {
        description = getValuesFromApplication(applicationCategory) +
            "-" +
            getValuesFromApplication(application);
      } else {
        description = '';
      }
    }
    return description;
  }
}
