/**
 * @fileoverview added by tsickle
 * Generated from: lib/shared/translate/services/translate.service.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { Storage } from '@ionic/storage';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common/http";
import * as i2 from "@ionic/storage";
var TranslateService = /** @class */ (function () {
    function TranslateService(http, storage) {
        this.http = http;
        this.storage = storage;
        this.data = {};
        this.selectedLanguage = 'en';
    }
    /**
     * @param {?} lang
     * @return {?}
     */
    TranslateService.prototype.use = /**
     * @param {?} lang
     * @return {?}
     */
    function (lang) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var _a;
            var _this = this;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        if (!lang) return [3 /*break*/, 1];
                        _a = lang;
                        return [3 /*break*/, 3];
                    case 1: return [4 /*yield*/, this.storage.get('lang')];
                    case 2:
                        _a = _b.sent();
                        _b.label = 3;
                    case 3:
                        lang = _a;
                        return [2 /*return*/, new Promise((/**
                             * @param {?} resolve
                             * @return {?}
                             */
                            function (resolve) {
                                /** @type {?} */
                                var langPath = "assets/i18n/" + (lang || 'en') + ".json";
                                _this.selectedLanguage = lang;
                                _this.storage.set('lang', _this.selectedLanguage);
                                _this.http.get(langPath).subscribe((/**
                                 * @param {?} translation
                                 * @return {?}
                                 */
                                function (translation) {
                                    _this.data = Object.assign({}, translation || {});
                                    return resolve(_this.data);
                                }), (/**
                                 * @return {?}
                                 */
                                function () {
                                    _this.data = {};
                                    return resolve(_this.data);
                                }));
                            }))];
                }
            });
        });
    };
    /**
     * @return {?}
     */
    TranslateService.prototype.get = /**
     * @return {?}
     */
    function () {
        return this.selectedLanguage;
    };
    TranslateService.decorators = [
        { type: Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];
    /** @nocollapse */
    TranslateService.ctorParameters = function () { return [
        { type: HttpClient },
        { type: Storage }
    ]; };
    /** @nocollapse */ TranslateService.ngInjectableDef = i0.defineInjectable({ factory: function TranslateService_Factory() { return new TranslateService(i0.inject(i1.HttpClient), i0.inject(i2.Storage)); }, token: TranslateService, providedIn: "root" });
    return TranslateService;
}());
export { TranslateService };
if (false) {
    /** @type {?} */
    TranslateService.prototype.data;
    /** @type {?} */
    TranslateService.prototype.selectedLanguage;
    /**
     * @type {?}
     * @private
     */
    TranslateService.prototype.http;
    /**
     * @type {?}
     * @private
     */
    TranslateService.prototype.storage;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNsYXRlLnNlcnZpY2UuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW5jbG91ZGVkL2lvbmljNC1pbmNsb3VkZWQtbGliLyIsInNvdXJjZXMiOlsibGliL3NoYXJlZC90cmFuc2xhdGUvc2VydmljZXMvdHJhbnNsYXRlLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLGdCQUFnQixDQUFDO0FBQ3pDLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDM0MsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLHNCQUFzQixDQUFDOzs7O0FBRWxEO0lBUUUsMEJBQW9CLElBQWdCLEVBQVUsT0FBZ0I7UUFBMUMsU0FBSSxHQUFKLElBQUksQ0FBWTtRQUFVLFlBQU8sR0FBUCxPQUFPLENBQVM7UUFIOUQsU0FBSSxHQUFRLEVBQUUsQ0FBQztRQUNmLHFCQUFnQixHQUFHLElBQUksQ0FBQztJQUd4QixDQUFDOzs7OztJQUVLLDhCQUFHOzs7O0lBQVQsVUFBVSxJQUFZOzs7Ozs7OzZCQUNiLElBQUksRUFBSix3QkFBSTt3QkFBRyxLQUFBLElBQUksQ0FBQTs7N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