/**
 * @fileoverview added by tsickle
 * Generated from: lib/service/static-resource.service.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { Injectable } from "@angular/core";
import { DomSanitizer } from "@angular/platform-browser";
import * as i0 from "@angular/core";
import * as i1 from "@angular/platform-browser";
var StaticResourceService = /** @class */ (function () {
    function StaticResourceService(sanitizer) {
        this.sanitizer = sanitizer;
        this.ResultMap = new Map();
    }
    /**
     * @param {?} url
     * @param {?=} cb
     * @return {?}
     */
    StaticResourceService.prototype.load = /**
     * @param {?} url
     * @param {?=} cb
     * @return {?}
     */
    function (url, cb) {
        if (cb === void 0) { cb = (/**
         * @return {?}
         */
        function () { }); }
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var result, res, blob;
            var _this = this;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!url || typeof url !== "string") {
                            cb("");
                            return [2 /*return*/, ""];
                        }
                        if (this.ResultMap.has(url)) {
                            result = this.ResultMap.get(url) || "";
                            cb(result);
                            return [2 /*return*/, result];
                        }
                        return [4 /*yield*/, fetch(url)];
                    case 1:
                        res = _a.sent();
                        if (!res.ok) {
                            cb("");
                            return [2 /*return*/, ""];
                        }
                        return [4 /*yield*/, res.blob()];
                    case 2:
                        blob = _a.sent();
                        return [2 /*return*/, new Promise((/**
                             * @param {?} resolve
                             * @return {?}
                             */
                            function (resolve) {
                                /** @type {?} */
                                var reader = new FileReader();
                                /** @type {?} */
                                var callback = (/**
                                 * @param {?} result
                                 * @return {?}
                                 */
                                function (result) {
                                    /** @type {?} */
                                    var safeUrl = _this.sanitizer.bypassSecurityTrustUrl(result);
                                    if (safeUrl) {
                                        _this.ResultMap.set(url, safeUrl);
                                    }
                                    resolve(safeUrl);
                                    cb(safeUrl);
                                });
                                reader.onloadend = (/**
                                 * @return {?}
                                 */
                                function () { return callback((/** @type {?} */ (reader.result))); });
                                reader.onerror = (/**
                                 * @return {?}
                                 */
                                function () { return callback(""); });
                                reader.readAsDataURL(blob);
                            }))];
                }
            });
        });
    };
    /**
     * @param {?} url
     * @param {?} cb
     * @return {?}
     */
    StaticResourceService.prototype.forceLoad = /**
     * @param {?} url
     * @param {?} cb
     * @return {?}
     */
    function (url, cb) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var result;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!true) return [3 /*break*/, 3];
                        return [4 /*yield*/, this.load(url)];
                    case 1:
                        result = _a.sent();
                        if (result) {
                            cb(result);
                            return [2 /*return*/, result];
                        }
                        return [4 /*yield*/, new Promise((/**
                             * @param {?} resolve
                             * @return {?}
                             */
                            function (resolve) { return setTimeout(resolve, 2000); }))];
                    case 2:
                        _a.sent();
                        return [3 /*break*/, 0];
                    case 3: return [2 /*return*/];
                }
            });
        });
    };
    StaticResourceService.decorators = [
        { type: Injectable, args: [{
                    providedIn: "root",
                },] }
    ];
    /** @nocollapse */
    StaticResourceService.ctorParameters = function () { return [
        { type: DomSanitizer }
    ]; };
    /** @nocollapse */ StaticResourceService.ngInjectableDef = i0.ɵɵdefineInjectable({ factory: function StaticResourceService_Factory() { return new StaticResourceService(i0.ɵɵinject(i1.DomSanitizer)); }, token: StaticResourceService, providedIn: "root" });
    return StaticResourceService;
}());
export { StaticResourceService };
if (false) {
    /**
     * @type {?}
     * @private
     */
    StaticResourceService.prototype.ResultMap;
    /**
     * @type {?}
     * @private
     */
    StaticResourceService.prototype.sanitizer;
}
//# sourceMappingURL=data:application/json;base64, 