import 'package:intl/intl.dart';
import 'i18n/messages_all.dart';
import 'package:sprintf/sprintf.dart';
import 'dart:async';

class StringsLocalization {

  static Future load(String locale) async {
    return initializeMessages(locale);
  }

   static String declineCurrency(int num, int code) {

    int residual = num % 100;
      if (residual >= 20) {
      residual %= 10;
    }

    List<String> strings = currencies(code);

    switch (residual) {
      case 1:
        return strings[0];
      case 2:
      case 3:
      case 4:
        return strings[1];
      default: // case 0, 5-19
        return strings[2];
    }
  }

  static List<String> currencies(int code) {

    String nominative, singular, plural;

    switch (code) {
      case 643:
        nominative = nominativeRuble();
        singular = singularRuble();
        plural = pluralRuble();
        break;
      case 840:
        nominative = nominativeDollar();
        singular = singularDollar();
        plural = pluralDollar();
        break;
      case 980:
        nominative = nominativeHryvna();
        singular = singularHryvna();
        plural = pluralHryvna();
        break;
      case 978:
        nominative = nominativeEuro();
        singular = singularEuro();
        plural = pluralEuro();
        break;
      case 398:
        nominative = nominativeTenge();
        singular = singularTenge();
        plural = pluralTenge();
        break;
    }


    return [nominative, singular, plural];
  }


  static String confirmPurchase(String val, int code) {
    String trimmedVal =val.substring(0, val.length - 3);
    return sprintf(Intl.message('confirm_purchase', name: 'confirm_purchase', locale: Intl.defaultLocale), [trimmedVal, declineCurrency(int.parse(trimmedVal), code)]);
  }

  static String purchaseCompleted(String val, int code) {
    String trimmedVal =val.substring(0, val.length - 3);
    return sprintf(Intl.message('purchase_complite', name: 'purchase_complite', locale: Intl.defaultLocale), [val, declineCurrency(int.parse(trimmedVal), code)]);
  }

  static String registration() => Intl.message('registration', name: 'registration', locale: Intl.defaultLocale);
  static String usage() => Intl.message('usage', name: 'usage', locale: Intl.defaultLocale);
  static String support() => Intl.message('support', name: 'support', locale: Intl.defaultLocale);
  static String common() => Intl.message('common', name: 'common', locale: Intl.defaultLocale);
  static String idStore() => Intl.message('ID_Store', name: 'ID_Store', locale: Intl.defaultLocale);
  static String signUp() => Intl.message('sign_up', name: 'sign_up', locale: Intl.defaultLocale);
  static String specifyDinStore() => Intl.message('specify_din_store', name: 'specify_din_store', locale: Intl.defaultLocale);
  static String confirmation() => Intl.message('confirmation', name: 'confirmation', locale: Intl.defaultLocale);
  static String askChangeStore() => Intl.message('ask_change_store', name: 'ask_change_store', locale: Intl.defaultLocale);
  static String yes() => Intl.message('yes', name: 'yes', locale: Intl.defaultLocale);
  static String no() => Intl.message('no', name: 'no', locale: Intl.defaultLocale);
  static String requestSentWaitActivation() => Intl.message('request_sent_wait_activ', name: 'request_sent_wait_activ', locale: Intl.defaultLocale);
  static String refreshActivationStatus() => Intl.message('update_activ_status', name: 'update_activ_status', locale: Intl.defaultLocale);
  static String appActivated() => Intl.message('app_activ', name: 'app_activ', locale: Intl.defaultLocale);
  static String completeRegistration() => Intl.message('complite_activ', name: 'complite_activ', locale: Intl.defaultLocale);
  static String cardScanner() => Intl.message('card_scaner', name: 'card_scaner', locale: Intl.defaultLocale);
  static String card() => Intl.message('card', name: 'card', locale: Intl.defaultLocale);
  static String reward() => Intl.message('reward', name: 'reward', locale: Intl.defaultLocale);
  static String sum() => Intl.message('sum', name: 'sum', locale: Intl.defaultLocale);
  static String bonus() => Intl.message('bonus', name: 'bonus', locale: Intl.defaultLocale);
  static String carryingPurchase() => Intl.message('carry_purchase', name: 'carry_purchase', locale: Intl.defaultLocale);
  static String completePurchase() => Intl.message('complite_purchase', name: 'complite_purchase', locale: Intl.defaultLocale);
  static String scan() => Intl.message('scan', name: 'scan', locale: Intl.defaultLocale);
  static String buyer() => Intl.message('buyer', name: 'buyer', locale: Intl.defaultLocale);
  static String idNotFound() => Intl.message('ID_not_found', name: 'ID_not_found', locale: Intl.defaultLocale);
  static String settings() => Intl.message('settings', name: 'settings', locale: Intl.defaultLocale);
  static String help() => Intl.message('help', name: 'help', locale: Intl.defaultLocale);
  static String logout() => Intl.message('logout', name: 'logout', locale: Intl.defaultLocale);
  static String currency() => Intl.message('currency', name: 'currency', locale: Intl.defaultLocale);
  static String locale() => Intl.message('locale', name: 'locale', locale: Intl.defaultLocale);

  // Валюты
  static String nominativeRuble() => Intl.message('nominative_ruble', name: 'nominative_ruble', locale: Intl.defaultLocale);
  static String singularRuble() => Intl.message('singular_ruble', name: 'singular_ruble', locale: Intl.defaultLocale);
  static String pluralRuble() => Intl.message('plural_ruble', name: 'plural_ruble', locale: Intl.defaultLocale);

  static String nominativeEuro() => Intl.message('nominative_euro', name: 'nominative_euro', locale: Intl.defaultLocale);
  static String singularEuro() => Intl.message('singular_euro', name: 'singular_euro', locale: Intl.defaultLocale);
  static String pluralEuro() => Intl.message('plural_euro', name: 'plural_euro', locale: Intl.defaultLocale);


  static String nominativeDollar() => Intl.message('nominative_dollar', name: 'nominative_dollar', locale: Intl.defaultLocale);
  static String singularDollar() => Intl.message('singular_dollar', name: 'singular_dollar', locale: Intl.defaultLocale);
  static String pluralDollar() => Intl.message('plural_dollar', name: 'plural_dollar', locale: Intl.defaultLocale);

  static String nominativeHryvna() => Intl.message('nominative_hryvna', name: 'nominative_hryvna', locale: Intl.defaultLocale);
  static String singularHryvna() => Intl.message('singular_hryvna', name: 'singular_hryvna', locale: Intl.defaultLocale);
  static String pluralHryvna() => Intl.message('plural_hryvna', name: 'plural_hryvna', locale: Intl.defaultLocale);

  static String nominativeTenge() => Intl.message('nominative_tenge', name: 'nominative_tenge', locale: Intl.defaultLocale);
  static String singularTenge() => Intl.message('singular_tenge', name: 'singular_tenge', locale: Intl.defaultLocale);
  static String pluralTenge() => Intl.message('plural_tenge', name: 'plural_tenge', locale: Intl.defaultLocale);

  static String registrationGuide() => Intl.message('registration_guide', name: 'registration_guide', locale: Intl.defaultLocale);
  static String usageGuide() => Intl.message('usage_guide', name: 'usage_guide', locale: Intl.defaultLocale);
  static String commonGuide() => Intl.message('common_guide', name: 'common_guide', locale: Intl.defaultLocale);

  static String supportGuide(String phone, String url) {
    return sprintf(Intl.message('support_guide', name: 'support_guide', locale: Intl.defaultLocale), [phone, url]);
  }
}