var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Injectable } from "@angular/core";
var TranslationService = /** @class */ (function () {
    function TranslationService() {
        this.translationMap = this.createTranslationMap(this.getTranslations());
    }
    TranslationService.prototype.getText = function (key) {
        var parameters = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            parameters[_i - 1] = arguments[_i];
        }
        if (key == null) {
            return "";
        }
        else if (key[this.getUserLanguage()] != null) {
            return key[this.getUserLanguage()];
        }
        else if (key["default"] != null) {
            return key["default"];
        }
        else if (this.getTranslation(key) == null) {
            return "{" + key + "}";
        }
        var result = this.getTranslation(key);
        var k = 0;
        for (var _a = 0, parameters_1 = parameters; _a < parameters_1.length; _a++) {
            var parameter = parameters_1[_a];
            result = result.replace("{" + k + "}", parameter);
            k++;
        }
        return result;
    };
    TranslationService.prototype.getTranslation = function (key) {
        return this.translationMap.get(key);
    };
    TranslationService.prototype.createTranslationMap = function (data) {
        var result = new Map();
        for (var _i = 0, _a = Object.keys(data); _i < _a.length; _i++) {
            var item = _a[_i];
            result.set(item, data[item]);
        }
        return result;
    };
    TranslationService.prototype.getUserLanguage = function () {
        var languageCode = sessionStorage.getItem("languageCode");
        if (languageCode && this.getSupportedLanguageCodes().indexOf(languageCode) > 0) {
            return languageCode;
        }
        if (this.getSupportedLanguageCodes().length <= 0) {
            console.log("No supported language codes defined. Please check translation service.");
            return "en";
        }
        return this.getSupportedLanguageCodes()[0];
    };
    TranslationService.prototype.getUserDateFormat = function () {
        // TODO: add locale support
        if (this.getUserLanguage() === "de") {
            return "DD.MM.YYYY";
        }
        return "MM/DD/YYYY";
    };
    TranslationService.prototype.getSupportedLanguageCodes = function () {
        return ["en", "de"];
    };
    TranslationService.prototype.getTranslations = function () {
        var languageCode = this.getUserLanguage();
        if (languageCode === "de") {
            return {
                "Back": "Zurück",
                "Cancel": "Abbrechen",
                "Delete": "Löschen",
                "DeleteWarningQuestion": "Wollen Sie diesen Datensatz löschen?",
                "Detail": "Detail",
                "Files": "Dateien",
                "FileLimitMessage": "Die Anzahl Dateien ist auf {0} limitiert. Bitte reduzieren Sie die Anzahl Dateien.",
                "FileSingleSizeMessage": "Die Dateigrösse einer Datei sollte {0} nicht überschreiten.",
                "FileAllSizeMessage": "Die Dateigrösse aller Dateien zusammen sollte {0} nicht überschreiten.",
                "Logout": "Abmelden",
                "MainMenu": "Hauptmenü",
                "New": "Neu",
                "NotSignedIn": "Nicht angemeldet",
                "Ok": "OK",
                "Result": "Resultat",
                "Results": "Resultate",
                "Search": "Suche",
                "SearchInputLabel": "Suchbegriff",
                "SearchTextTooShort": "Suchbegriff zu kurz",
                "SignedInAs": "Angemeldet als",
                "SliderValue": "Wert",
                "Translation": "Übersetzung",
                "Translations": "Übersetzungen",
                "de": "Deutsch",
                "en": "Englisch",
            };
        }
        else {
            return {
                "Back": "Back",
                "Cancel": "Cancel",
                "Delete": "Delete",
                "DeleteWarningQuestion": "Do you want to delete this item?",
                "Detail": "Detail",
                "Files": "Files",
                "FileLimitMessage": "The number of files is limited to {0}. Please reduce the number of files.",
                "FileSingleSizeMessage": "The file size for a single file is limited to {0}.",
                "FileAllSizeMessage": "The size of all files should not exceed {0}.",
                "Logout": "Logout",
                "MainMenu": "Main Menu",
                "New": "New",
                "NotSignedIn": "Not signed in",
                "Ok": "Ok",
                "Result": "Result",
                "Results": "Results",
                "Search": "Search",
                "SearchInputLabel": "Enter search text",
                "SearchTextTooShort": "Search text too short",
                "SignedInAs": "Signed in as",
                "SliderValue": "Value",
                "Translation": "Translation",
                "Translations": "Translations",
                "de": "German",
                "en": "English",
            };
        }
    };
    TranslationService = __decorate([
        Injectable()
    ], TranslationService);
    return TranslationService;
}());
export { TranslationService };
//# sourceMappingURL=translation.service.js.map