import { h } from '../webcomponents.core.js';

import { a as __extends, b as __awaiter, c as __generator, e as __spread, d as __assign } from './chunk-de721f0a.js';
import { g as Observable, c as Subscriber, j as map, k as Subject, t as mergeMap, u as from, v as fromEvent } from './chunk-fec5a75d.js';
import { a as startWith, b as scan, c as pluck } from './chunk-d51357a9.js';
import { a as createCommonjsModule, b as unwrapExports, c as commonjsGlobal, d as HttpClient, e as Util, f as ConfigService, g as BaseService, h as PermissionsService, i as User } from './chunk-f9f1602a.js';

/** PURE_IMPORTS_START  PURE_IMPORTS_END */
var __window = typeof window !== 'undefined' && window;
var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
    self instanceof WorkerGlobalScope && self;
var __global = typeof global !== 'undefined' && global;
var _root = __window || __global || __self;
/*@__PURE__*/ (function () {
    if (!_root) {
        throw /*@__PURE__*/ new Error('RxJS could not find any global context (window, self, global)');
    }
})();

/** PURE_IMPORTS_START tslib,_.._util_root,_.._Observable,_.._Subscriber,_.._operators_map PURE_IMPORTS_END */
function getCORSRequest() {
    if (_root.XMLHttpRequest) {
        return new _root.XMLHttpRequest();
    }
    else if (!!_root.XDomainRequest) {
        return new _root.XDomainRequest();
    }
    else {
        throw new Error('CORS is not supported by your browser');
    }
}
function getXMLHttpRequest() {
    if (_root.XMLHttpRequest) {
        return new _root.XMLHttpRequest();
    }
    else {
        var progId = void 0;
        try {
            var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
            for (var i = 0; i < 3; i++) {
                try {
                    progId = progIds[i];
                    if (new _root.ActiveXObject(progId)) {
                        break;
                    }
                }
                catch (e) {
                }
            }
            return new _root.ActiveXObject(progId);
        }
        catch (e) {
            throw new Error('XMLHttpRequest is not supported by your browser');
        }
    }
}
function ajaxGet(url, headers) {
    if (headers === void 0) {
        headers = null;
    }
    return new AjaxObservable({ method: 'GET', url: url, headers: headers });
}
function ajaxPost(url, body, headers) {
    return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers });
}
function ajaxDelete(url, headers) {
    return new AjaxObservable({ method: 'DELETE', url: url, headers: headers });
}
function ajaxPut(url, body, headers) {
    return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers });
}
function ajaxPatch(url, body, headers) {
    return new AjaxObservable({ method: 'PATCH', url: url, body: body, headers: headers });
}
var mapResponse = /*@__PURE__*/ map(function (x, index) { return x.response; });
function ajaxGetJSON(url, headers) {
    return mapResponse(new AjaxObservable({
        method: 'GET',
        url: url,
        responseType: 'json',
        headers: headers
    }));
}
var AjaxObservable = /*@__PURE__*/ (function (_super) {
    __extends(AjaxObservable, _super);
    function AjaxObservable(urlOrRequest) {
        var _this = _super.call(this) || this;
        var request = {
            async: true,
            createXHR: function () {
                return this.crossDomain ? getCORSRequest() : getXMLHttpRequest();
            },
            crossDomain: true,
            withCredentials: false,
            headers: {},
            method: 'GET',
            responseType: 'json',
            timeout: 0
        };
        if (typeof urlOrRequest === 'string') {
            request.url = urlOrRequest;
        }
        else {
            for (var prop in urlOrRequest) {
                if (urlOrRequest.hasOwnProperty(prop)) {
                    request[prop] = urlOrRequest[prop];
                }
            }
        }
        _this.request = request;
        return _this;
    }
    AjaxObservable.prototype._subscribe = function (subscriber) {
        return new AjaxSubscriber(subscriber, this.request);
    };
    AjaxObservable.create = (function () {
        var create = function (urlOrRequest) {
            return new AjaxObservable(urlOrRequest);
        };
        create.get = ajaxGet;
        create.post = ajaxPost;
        create.delete = ajaxDelete;
        create.put = ajaxPut;
        create.patch = ajaxPatch;
        create.getJSON = ajaxGetJSON;
        return create;
    })();
    return AjaxObservable;
}(Observable));
var AjaxSubscriber = /*@__PURE__*/ (function (_super) {
    __extends(AjaxSubscriber, _super);
    function AjaxSubscriber(destination, request) {
        var _this = _super.call(this, destination) || this;
        _this.request = request;
        _this.done = false;
        var headers = request.headers = request.headers || {};
        if (!request.crossDomain && !_this.getHeader(headers, 'X-Requested-With')) {
            headers['X-Requested-With'] = 'XMLHttpRequest';
        }
        var contentTypeHeader = _this.getHeader(headers, 'Content-Type');
        if (!contentTypeHeader && !(_root.FormData && request.body instanceof _root.FormData) && typeof request.body !== 'undefined') {
            headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
        }
        request.body = _this.serializeBody(request.body, _this.getHeader(request.headers, 'Content-Type'));
        _this.send();
        return _this;
    }
    AjaxSubscriber.prototype.next = function (e) {
        this.done = true;
        var _a = this, xhr = _a.xhr, request = _a.request, destination = _a.destination;
        var result;
        try {
            result = new AjaxResponse(e, xhr, request);
        }
        catch (err) {
            return destination.error(err);
        }
        destination.next(result);
    };
    AjaxSubscriber.prototype.send = function () {
        var _a = this, request = _a.request, _b = _a.request, user = _b.user, method = _b.method, url = _b.url, async = _b.async, password = _b.password, headers = _b.headers, body = _b.body;
        try {
            var xhr = this.xhr = request.createXHR();
            this.setupEvents(xhr, request);
            if (user) {
                xhr.open(method, url, async, user, password);
            }
            else {
                xhr.open(method, url, async);
            }
            if (async) {
                xhr.timeout = request.timeout;
                xhr.responseType = request.responseType;
            }
            if ('withCredentials' in xhr) {
                xhr.withCredentials = !!request.withCredentials;
            }
            this.setHeaders(xhr, headers);
            if (body) {
                xhr.send(body);
            }
            else {
                xhr.send();
            }
        }
        catch (err) {
            this.error(err);
        }
    };
    AjaxSubscriber.prototype.serializeBody = function (body, contentType) {
        if (!body || typeof body === 'string') {
            return body;
        }
        else if (_root.FormData && body instanceof _root.FormData) {
            return body;
        }
        if (contentType) {
            var splitIndex = contentType.indexOf(';');
            if (splitIndex !== -1) {
                contentType = contentType.substring(0, splitIndex);
            }
        }
        switch (contentType) {
            case 'application/x-www-form-urlencoded':
                return Object.keys(body).map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(body[key]); }).join('&');
            case 'application/json':
                return JSON.stringify(body);
            default:
                return body;
        }
    };
    AjaxSubscriber.prototype.setHeaders = function (xhr, headers) {
        for (var key in headers) {
            if (headers.hasOwnProperty(key)) {
                xhr.setRequestHeader(key, headers[key]);
            }
        }
    };
    AjaxSubscriber.prototype.getHeader = function (headers, headerName) {
        for (var key in headers) {
            if (key.toLowerCase() === headerName.toLowerCase()) {
                return headers[key];
            }
        }
        return undefined;
    };
    AjaxSubscriber.prototype.setupEvents = function (xhr, request) {
        var progressSubscriber = request.progressSubscriber;
        function xhrTimeout(e) {
            var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
            if (progressSubscriber) {
                progressSubscriber.error(e);
            }
            var error;
            try {
                error = new AjaxTimeoutError(this, request);
            }
            catch (err) {
                error = err;
            }
            subscriber.error(error);
        }
        xhr.ontimeout = xhrTimeout;
        xhrTimeout.request = request;
        xhrTimeout.subscriber = this;
        xhrTimeout.progressSubscriber = progressSubscriber;
        if (xhr.upload && 'withCredentials' in xhr) {
            if (progressSubscriber) {
                var xhrProgress_1;
                xhrProgress_1 = function (e) {
                    var progressSubscriber = xhrProgress_1.progressSubscriber;
                    progressSubscriber.next(e);
                };
                if (_root.XDomainRequest) {
                    xhr.onprogress = xhrProgress_1;
                }
                else {
                    xhr.upload.onprogress = xhrProgress_1;
                }
                xhrProgress_1.progressSubscriber = progressSubscriber;
            }
            var xhrError_1;
            xhrError_1 = function (e) {
                var _a = xhrError_1, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request;
                if (progressSubscriber) {
                    progressSubscriber.error(e);
                }
                var error;
                try {
                    error = new AjaxError('ajax error', this, request);
                }
                catch (err) {
                    error = err;
                }
                subscriber.error(error);
            };
            xhr.onerror = xhrError_1;
            xhrError_1.request = request;
            xhrError_1.subscriber = this;
            xhrError_1.progressSubscriber = progressSubscriber;
        }
        function xhrReadyStateChange(e) {
            return;
        }
        xhr.onreadystatechange = xhrReadyStateChange;
        xhrReadyStateChange.subscriber = this;
        xhrReadyStateChange.progressSubscriber = progressSubscriber;
        xhrReadyStateChange.request = request;
        function xhrLoad(e) {
            var _a = xhrLoad, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request;
            if (this.readyState === 4) {
                var status_1 = this.status === 1223 ? 204 : this.status;
                var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response);
                if (status_1 === 0) {
                    status_1 = response ? 200 : 0;
                }
                if (status_1 < 400) {
                    if (progressSubscriber) {
                        progressSubscriber.complete();
                    }
                    subscriber.next(e);
                    subscriber.complete();
                }
                else {
                    if (progressSubscriber) {
                        progressSubscriber.error(e);
                    }
                    var error = void 0;
                    try {
                        error = new AjaxError('ajax error ' + status_1, this, request);
                    }
                    catch (err) {
                        error = err;
                    }
                    subscriber.error(error);
                }
            }
        }
        xhr.onload = xhrLoad;
        xhrLoad.subscriber = this;
        xhrLoad.progressSubscriber = progressSubscriber;
        xhrLoad.request = request;
    };
    AjaxSubscriber.prototype.unsubscribe = function () {
        var _a = this, done = _a.done, xhr = _a.xhr;
        if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') {
            xhr.abort();
        }
        _super.prototype.unsubscribe.call(this);
    };
    return AjaxSubscriber;
}(Subscriber));
var AjaxResponse = /*@__PURE__*/ (function () {
    function AjaxResponse(originalEvent, xhr, request) {
        this.originalEvent = originalEvent;
        this.xhr = xhr;
        this.request = request;
        this.status = xhr.status;
        this.responseType = xhr.responseType || request.responseType;
        this.response = parseXhrResponse(this.responseType, xhr);
    }
    return AjaxResponse;
}());
function AjaxErrorImpl(message, xhr, request) {
    Error.call(this);
    this.message = message;
    this.name = 'AjaxError';
    this.xhr = xhr;
    this.request = request;
    this.status = xhr.status;
    this.responseType = xhr.responseType || request.responseType;
    this.response = parseXhrResponse(this.responseType, xhr);
    return this;
}
AjaxErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype);
var AjaxError = AjaxErrorImpl;
function parseJson(xhr) {
    if ('response' in xhr) {
        return xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
    }
    else {
        return JSON.parse(xhr.responseText || 'null');
    }
}
function parseXhrResponse(responseType, xhr) {
    switch (responseType) {
        case 'json':
            return parseJson(xhr);
        case 'xml':
            return xhr.responseXML;
        case 'text':
        default:
            return ('response' in xhr) ? xhr.response : xhr.responseText;
    }
}
function AjaxTimeoutErrorImpl(xhr, request) {
    AjaxError.call(this, 'ajax timeout', xhr, request);
    this.name = 'AjaxTimeoutError';
    return this;
}
var AjaxTimeoutError = AjaxTimeoutErrorImpl;

/** PURE_IMPORTS_START _AjaxObservable PURE_IMPORTS_END */
var ajax = AjaxObservable.create;

/** PURE_IMPORTS_START  PURE_IMPORTS_END */

var isFunction_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function isFunction(x) {
    return typeof x === 'function';
}
exports.isFunction = isFunction;

});

unwrapExports(isFunction_1);
var isFunction_2 = isFunction_1.isFunction;

var config = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
var _enable_super_gross_mode_that_will_cause_bad_things = false;
exports.config = {
    Promise: undefined,
    set useDeprecatedSynchronousErrorHandling(value) {
        if (value) {
            var error = new Error();
            console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack);
        }
        else if (_enable_super_gross_mode_that_will_cause_bad_things) {
            console.log('RxJS: Back to a better error behavior. Thank you. <3');
        }
        _enable_super_gross_mode_that_will_cause_bad_things = value;
    },
    get useDeprecatedSynchronousErrorHandling() {
        return _enable_super_gross_mode_that_will_cause_bad_things;
    },
};

});

unwrapExports(config);
var config_1 = config.config;

var hostReportError_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function hostReportError(err) {
    setTimeout(function () { throw err; });
}
exports.hostReportError = hostReportError;

});

unwrapExports(hostReportError_1);
var hostReportError_2 = hostReportError_1.hostReportError;

var Observer = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });


exports.empty = {
    closed: true,
    next: function (value) { },
    error: function (err) {
        if (config.config.useDeprecatedSynchronousErrorHandling) {
            throw err;
        }
        else {
            hostReportError_1.hostReportError(err);
        }
    },
    complete: function () { }
};

});

unwrapExports(Observer);
var Observer_1 = Observer.empty;

var isArray = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.isArray = Array.isArray || (function (x) { return x && typeof x.length === 'number'; });

});

unwrapExports(isArray);
var isArray_1 = isArray.isArray;

var isObject_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function isObject(x) {
    return x !== null && typeof x === 'object';
}
exports.isObject = isObject;

});

unwrapExports(isObject_1);
var isObject_2 = isObject_1.isObject;

var UnsubscriptionError = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function UnsubscriptionErrorImpl(errors) {
    Error.call(this);
    this.message = errors ?
        errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n  ') : '';
    this.name = 'UnsubscriptionError';
    this.errors = errors;
    return this;
}
UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype);
exports.UnsubscriptionError = UnsubscriptionErrorImpl;

});

unwrapExports(UnsubscriptionError);
var UnsubscriptionError_1 = UnsubscriptionError.UnsubscriptionError;

var Subscription_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });




var Subscription = (function () {
    function Subscription(unsubscribe) {
        this.closed = false;
        this._parent = null;
        this._parents = null;
        this._subscriptions = null;
        if (unsubscribe) {
            this._unsubscribe = unsubscribe;
        }
    }
    Subscription.prototype.unsubscribe = function () {
        var hasErrors = false;
        var errors;
        if (this.closed) {
            return;
        }
        var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
        this.closed = true;
        this._parent = null;
        this._parents = null;
        this._subscriptions = null;
        var index = -1;
        var len = _parents ? _parents.length : 0;
        while (_parent) {
            _parent.remove(this);
            _parent = ++index < len && _parents[index] || null;
        }
        if (isFunction_1.isFunction(_unsubscribe)) {
            try {
                _unsubscribe.call(this);
            }
            catch (e) {
                hasErrors = true;
                errors = e instanceof UnsubscriptionError.UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
            }
        }
        if (isArray.isArray(_subscriptions)) {
            index = -1;
            len = _subscriptions.length;
            while (++index < len) {
                var sub = _subscriptions[index];
                if (isObject_1.isObject(sub)) {
                    try {
                        sub.unsubscribe();
                    }
                    catch (e) {
                        hasErrors = true;
                        errors = errors || [];
                        if (e instanceof UnsubscriptionError.UnsubscriptionError) {
                            errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
                        }
                        else {
                            errors.push(e);
                        }
                    }
                }
            }
        }
        if (hasErrors) {
            throw new UnsubscriptionError.UnsubscriptionError(errors);
        }
    };
    Subscription.prototype.add = function (teardown) {
        var subscription = teardown;
        switch (typeof teardown) {
            case 'function':
                subscription = new Subscription(teardown);
            case 'object':
                if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') {
                    return subscription;
                }
                else if (this.closed) {
                    subscription.unsubscribe();
                    return subscription;
                }
                else if (!(subscription instanceof Subscription)) {
                    var tmp = subscription;
                    subscription = new Subscription();
                    subscription._subscriptions = [tmp];
                }
                break;
            default: {
                if (!teardown) {
                    return Subscription.EMPTY;
                }
                throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
            }
        }
        if (subscription._addParent(this)) {
            var subscriptions = this._subscriptions;
            if (subscriptions) {
                subscriptions.push(subscription);
            }
            else {
                this._subscriptions = [subscription];
            }
        }
        return subscription;
    };
    Subscription.prototype.remove = function (subscription) {
        var subscriptions = this._subscriptions;
        if (subscriptions) {
            var subscriptionIndex = subscriptions.indexOf(subscription);
            if (subscriptionIndex !== -1) {
                subscriptions.splice(subscriptionIndex, 1);
            }
        }
    };
    Subscription.prototype._addParent = function (parent) {
        var _a = this, _parent = _a._parent, _parents = _a._parents;
        if (_parent === parent) {
            return false;
        }
        else if (!_parent) {
            this._parent = parent;
            return true;
        }
        else if (!_parents) {
            this._parents = [parent];
            return true;
        }
        else if (_parents.indexOf(parent) === -1) {
            _parents.push(parent);
            return true;
        }
        return false;
    };
    Subscription.EMPTY = (function (empty) {
        empty.closed = true;
        return empty;
    }(new Subscription()));
    return Subscription;
}());
exports.Subscription = Subscription;
function flattenUnsubscriptionErrors(errors) {
    return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError.UnsubscriptionError) ? err.errors : err); }, []);
}

});

unwrapExports(Subscription_1);
var Subscription_2 = Subscription_1.Subscription;

var rxSubscriber = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.rxSubscriber = typeof Symbol === 'function'
    ? Symbol('rxSubscriber')
    : '@@rxSubscriber_' + Math.random();
exports.$$rxSubscriber = exports.rxSubscriber;

});

unwrapExports(rxSubscriber);
var rxSubscriber_1 = rxSubscriber.rxSubscriber;
var rxSubscriber_2 = rxSubscriber.$$rxSubscriber;

var Subscriber_1 = createCommonjsModule(function (module, exports) {
var __extends$$1 = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });






var Subscriber$$1 = (function (_super) {
    __extends$$1(Subscriber$$1, _super);
    function Subscriber$$1(destinationOrNext, error, complete) {
        var _this = _super.call(this) || this;
        _this.syncErrorValue = null;
        _this.syncErrorThrown = false;
        _this.syncErrorThrowable = false;
        _this.isStopped = false;
        switch (arguments.length) {
            case 0:
                _this.destination = Observer.empty;
                break;
            case 1:
                if (!destinationOrNext) {
                    _this.destination = Observer.empty;
                    break;
                }
                if (typeof destinationOrNext === 'object') {
                    if (destinationOrNext instanceof Subscriber$$1) {
                        _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable;
                        _this.destination = destinationOrNext;
                        destinationOrNext.add(_this);
                    }
                    else {
                        _this.syncErrorThrowable = true;
                        _this.destination = new SafeSubscriber(_this, destinationOrNext);
                    }
                    break;
                }
            default:
                _this.syncErrorThrowable = true;
                _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete);
                break;
        }
        return _this;
    }
    Subscriber$$1.prototype[rxSubscriber.rxSubscriber] = function () { return this; };
    Subscriber$$1.create = function (next, error, complete) {
        var subscriber = new Subscriber$$1(next, error, complete);
        subscriber.syncErrorThrowable = false;
        return subscriber;
    };
    Subscriber$$1.prototype.next = function (value) {
        if (!this.isStopped) {
            this._next(value);
        }
    };
    Subscriber$$1.prototype.error = function (err) {
        if (!this.isStopped) {
            this.isStopped = true;
            this._error(err);
        }
    };
    Subscriber$$1.prototype.complete = function () {
        if (!this.isStopped) {
            this.isStopped = true;
            this._complete();
        }
    };
    Subscriber$$1.prototype.unsubscribe = function () {
        if (this.closed) {
            return;
        }
        this.isStopped = true;
        _super.prototype.unsubscribe.call(this);
    };
    Subscriber$$1.prototype._next = function (value) {
        this.destination.next(value);
    };
    Subscriber$$1.prototype._error = function (err) {
        this.destination.error(err);
        this.unsubscribe();
    };
    Subscriber$$1.prototype._complete = function () {
        this.destination.complete();
        this.unsubscribe();
    };
    Subscriber$$1.prototype._unsubscribeAndRecycle = function () {
        var _a = this, _parent = _a._parent, _parents = _a._parents;
        this._parent = null;
        this._parents = null;
        this.unsubscribe();
        this.closed = false;
        this.isStopped = false;
        this._parent = _parent;
        this._parents = _parents;
        return this;
    };
    return Subscriber$$1;
}(Subscription_1.Subscription));
exports.Subscriber = Subscriber$$1;
var SafeSubscriber = (function (_super) {
    __extends$$1(SafeSubscriber, _super);
    function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) {
        var _this = _super.call(this) || this;
        _this._parentSubscriber = _parentSubscriber;
        var next;
        var context = _this;
        if (isFunction_1.isFunction(observerOrNext)) {
            next = observerOrNext;
        }
        else if (observerOrNext) {
            next = observerOrNext.next;
            error = observerOrNext.error;
            complete = observerOrNext.complete;
            if (observerOrNext !== Observer.empty) {
                context = Object.create(observerOrNext);
                if (isFunction_1.isFunction(context.unsubscribe)) {
                    _this.add(context.unsubscribe.bind(context));
                }
                context.unsubscribe = _this.unsubscribe.bind(_this);
            }
        }
        _this._context = context;
        _this._next = next;
        _this._error = error;
        _this._complete = complete;
        return _this;
    }
    SafeSubscriber.prototype.next = function (value) {
        if (!this.isStopped && this._next) {
            var _parentSubscriber = this._parentSubscriber;
            if (!config.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
                this.__tryOrUnsub(this._next, value);
            }
            else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) {
                this.unsubscribe();
            }
        }
    };
    SafeSubscriber.prototype.error = function (err) {
        if (!this.isStopped) {
            var _parentSubscriber = this._parentSubscriber;
            var useDeprecatedSynchronousErrorHandling = config.config.useDeprecatedSynchronousErrorHandling;
            if (this._error) {
                if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
                    this.__tryOrUnsub(this._error, err);
                    this.unsubscribe();
                }
                else {
                    this.__tryOrSetError(_parentSubscriber, this._error, err);
                    this.unsubscribe();
                }
            }
            else if (!_parentSubscriber.syncErrorThrowable) {
                this.unsubscribe();
                if (useDeprecatedSynchronousErrorHandling) {
                    throw err;
                }
                hostReportError_1.hostReportError(err);
            }
            else {
                if (useDeprecatedSynchronousErrorHandling) {
                    _parentSubscriber.syncErrorValue = err;
                    _parentSubscriber.syncErrorThrown = true;
                }
                else {
                    hostReportError_1.hostReportError(err);
                }
                this.unsubscribe();
            }
        }
    };
    SafeSubscriber.prototype.complete = function () {
        var _this = this;
        if (!this.isStopped) {
            var _parentSubscriber = this._parentSubscriber;
            if (this._complete) {
                var wrappedComplete = function () { return _this._complete.call(_this._context); };
                if (!config.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) {
                    this.__tryOrUnsub(wrappedComplete);
                    this.unsubscribe();
                }
                else {
                    this.__tryOrSetError(_parentSubscriber, wrappedComplete);
                    this.unsubscribe();
                }
            }
            else {
                this.unsubscribe();
            }
        }
    };
    SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) {
        try {
            fn.call(this._context, value);
        }
        catch (err) {
            this.unsubscribe();
            if (config.config.useDeprecatedSynchronousErrorHandling) {
                throw err;
            }
            else {
                hostReportError_1.hostReportError(err);
            }
        }
    };
    SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) {
        if (!config.config.useDeprecatedSynchronousErrorHandling) {
            throw new Error('bad call');
        }
        try {
            fn.call(this._context, value);
        }
        catch (err) {
            if (config.config.useDeprecatedSynchronousErrorHandling) {
                parent.syncErrorValue = err;
                parent.syncErrorThrown = true;
                return true;
            }
            else {
                hostReportError_1.hostReportError(err);
                return true;
            }
        }
        return false;
    };
    SafeSubscriber.prototype._unsubscribe = function () {
        var _parentSubscriber = this._parentSubscriber;
        this._context = null;
        this._parentSubscriber = null;
        _parentSubscriber.unsubscribe();
    };
    return SafeSubscriber;
}(Subscriber$$1));
exports.SafeSubscriber = SafeSubscriber;

});

unwrapExports(Subscriber_1);
var Subscriber_2 = Subscriber_1.Subscriber;
var Subscriber_3 = Subscriber_1.SafeSubscriber;

var canReportError_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });

function canReportError(observer) {
    while (observer) {
        var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped;
        if (closed_1 || isStopped) {
            return false;
        }
        else if (destination && destination instanceof Subscriber_1.Subscriber) {
            observer = destination;
        }
        else {
            observer = null;
        }
    }
    return true;
}
exports.canReportError = canReportError;

});

unwrapExports(canReportError_1);
var canReportError_2 = canReportError_1.canReportError;

var toSubscriber_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });



function toSubscriber(nextOrObserver, error, complete) {
    if (nextOrObserver) {
        if (nextOrObserver instanceof Subscriber_1.Subscriber) {
            return nextOrObserver;
        }
        if (nextOrObserver[rxSubscriber.rxSubscriber]) {
            return nextOrObserver[rxSubscriber.rxSubscriber]();
        }
    }
    if (!nextOrObserver && !error && !complete) {
        return new Subscriber_1.Subscriber(Observer.empty);
    }
    return new Subscriber_1.Subscriber(nextOrObserver, error, complete);
}
exports.toSubscriber = toSubscriber;

});

unwrapExports(toSubscriber_1);
var toSubscriber_2 = toSubscriber_1.toSubscriber;

var observable = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.observable = typeof Symbol === 'function' && Symbol.observable || '@@observable';

});

unwrapExports(observable);
var observable_1 = observable.observable;

var noop_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
function noop() { }
exports.noop = noop;

});

unwrapExports(noop_1);
var noop_2 = noop_1.noop;

var pipe_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });

function pipe() {
    var fns = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        fns[_i] = arguments[_i];
    }
    return pipeFromArray(fns);
}
exports.pipe = pipe;
function pipeFromArray(fns) {
    if (!fns) {
        return noop_1.noop;
    }
    if (fns.length === 1) {
        return fns[0];
    }
    return function piped(input) {
        return fns.reduce(function (prev, fn) { return fn(prev); }, input);
    };
}
exports.pipeFromArray = pipeFromArray;

});

unwrapExports(pipe_1);
var pipe_2 = pipe_1.pipe;
var pipe_3 = pipe_1.pipeFromArray;

var Observable_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });





var Observable$$1 = (function () {
    function Observable$$1(subscribe) {
        this._isScalar = false;
        if (subscribe) {
            this._subscribe = subscribe;
        }
    }
    Observable$$1.prototype.lift = function (operator) {
        var observable$$1 = new Observable$$1();
        observable$$1.source = this;
        observable$$1.operator = operator;
        return observable$$1;
    };
    Observable$$1.prototype.subscribe = function (observerOrNext, error, complete) {
        var operator = this.operator;
        var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete);
        if (operator) {
            sink.add(operator.call(sink, this.source));
        }
        else {
            sink.add(this.source || (config.config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ?
                this._subscribe(sink) :
                this._trySubscribe(sink));
        }
        if (config.config.useDeprecatedSynchronousErrorHandling) {
            if (sink.syncErrorThrowable) {
                sink.syncErrorThrowable = false;
                if (sink.syncErrorThrown) {
                    throw sink.syncErrorValue;
                }
            }
        }
        return sink;
    };
    Observable$$1.prototype._trySubscribe = function (sink) {
        try {
            return this._subscribe(sink);
        }
        catch (err) {
            if (config.config.useDeprecatedSynchronousErrorHandling) {
                sink.syncErrorThrown = true;
                sink.syncErrorValue = err;
            }
            if (canReportError_1.canReportError(sink)) {
                sink.error(err);
            }
            else {
                console.warn(err);
            }
        }
    };
    Observable$$1.prototype.forEach = function (next, promiseCtor) {
        var _this = this;
        promiseCtor = getPromiseCtor(promiseCtor);
        return new promiseCtor(function (resolve, reject) {
            var subscription;
            subscription = _this.subscribe(function (value) {
                try {
                    next(value);
                }
                catch (err) {
                    reject(err);
                    if (subscription) {
                        subscription.unsubscribe();
                    }
                }
            }, reject, resolve);
        });
    };
    Observable$$1.prototype._subscribe = function (subscriber) {
        var source = this.source;
        return source && source.subscribe(subscriber);
    };
    Observable$$1.prototype[observable.observable] = function () {
        return this;
    };
    Observable$$1.prototype.pipe = function () {
        var operations = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            operations[_i] = arguments[_i];
        }
        if (operations.length === 0) {
            return this;
        }
        return pipe_1.pipeFromArray(operations)(this);
    };
    Observable$$1.prototype.toPromise = function (promiseCtor) {
        var _this = this;
        promiseCtor = getPromiseCtor(promiseCtor);
        return new promiseCtor(function (resolve, reject) {
            var value;
            _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); });
        });
    };
    Observable$$1.create = function (subscribe) {
        return new Observable$$1(subscribe);
    };
    return Observable$$1;
}());
exports.Observable = Observable$$1;
function getPromiseCtor(promiseCtor) {
    if (!promiseCtor) {
        promiseCtor = config.config.Promise || Promise;
    }
    if (!promiseCtor) {
        throw new Error('no Promise impl found');
    }
    return promiseCtor;
}

});

unwrapExports(Observable_1);
var Observable_2 = Observable_1.Observable;

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var RxUtil = /** @class */ (function () {
    function RxUtil() {
    }
    /**
     * @param {?} obs
     * @return {?}
     */
    RxUtil.isObservable = /**
     * @param {?} obs
     * @return {?}
     */
    function (obs) {
        return obs instanceof Observable;
    };
    /**
     * @return {?}
     */
    RxUtil.log = /**
     * @return {?}
     */
    function () {
        return console.log.bind(console);
    };
    return RxUtil;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/** @type {?} */
var action$ = new Subject();
/** @type {?} */
var createStore = (/**
 * @param {?} reducer
 * @param {?=} initState
 * @return {?}
 */
function (reducer, initState) {
    if (initState === void 0) { initState = { timestamp: Util.getTimeStamp(), config: {} }; }
    return action$.pipe(mergeMap((/**
     * @param {?} action
     * @return {?}
     */
    function (action) { return RxUtil.isObservable(action) ? action : from([action]); })), startWith(initState), scan(reducer));
});
// higher order function to send actions to the stream
/** @type {?} */
var actionCreator = (/**
 * @param {?} func
 * @return {?}
 */
function (func) { return (/**
 * @param {...?} args
 * @return {?}
 */
function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    /** @type {?} */
    var action = func.call.apply(func, __spread([null], args));
    action$.next(action);
    if (RxUtil.isObservable(action.payload))
        action$.next(action.payload);
    return action;
}); });
// let state$: Observable<object> = combineReducers({base: baseReducer, app: reducer, uaas: uaasReducer})
// state$.subscribe((state) => {
//     console.log('state$',state);
// })
/** @type {?} */
var createCombinedStore = (/**
 * @param {?} reducers
 * @param {?=} initialState
 * @return {?}
 */
function (reducers, initialState) {
    if (initialState === void 0) { initialState = { timestamp: Util.getTimeStamp() }; }
    /** @type {?} */
    var globalState = { isCombinedStore: true };
    /** @type {?} */
    var rootReducer = (/**
     * @param {?} state
     * @param {?} action
     * @return {?}
     */
    function (state, action) {
        switch (action.type) {
            default: return __assign({}, globalState, combinedState);
        }
    });
    /** @type {?} */
    var root$ = createStore(rootReducer, globalState);
    /** @type {?} */
    var combinedStore$ = {};
    /** @type {?} */
    var combinedState = {};
    Object.keys(reducers).forEach((/**
     * @param {?} k
     * @return {?}
     */
    function (k) {
        combinedState[k] = {};
        combinedStore$[k] = createStore(reducers[k], initialState);
    }));
    Object.keys(combinedStore$).forEach((/**
     * @param {?} key
     * @return {?}
     */
    function (key) {
        combinedStore$[key].subscribe((/**
         * @param {?} state
         * @return {?}
         */
        function (state) {
            combinedState[key] = state;
            rootReducer(combinedState, '__root');
        }));
    }));
    return root$;
});

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/**
 * @param {?} state
 * @param {?} action
 * @return {?}
 */
function baseReducer(state, action) {
    switch (action.type) {
        case 'ADD_STATE':
            /** @type {?} */
            var nState_1 = __assign({}, state);
            Object.keys(action.payload).forEach((/**
             * @param {?} k
             * @return {?}
             */
            function (k) {
                nState_1[k] = action.payload[k];
            }));
            nState_1.timestamp = Util.getTimeStamp();
            return nState_1;
        case 'ADD_CONFIG':
            /** @type {?} */
            var newConfig_1 = __assign({}, state);
            Object.keys(action.payload).forEach((/**
             * @param {?} k
             * @return {?}
             */
            function (k) {
                newConfig_1[k] = action.payload[k];
                // newConfig.config[k] = action.payload[k];
            }));
            newConfig_1.timestamp = Util.getTimeStamp();
            return newConfig_1;
        case 'CONFIG_LOADING':
            return __assign({}, state, { isLoading: true, timestamp: Util.getTimeStamp() });
        case 'CONFIG_LOADED':
            /** @type {?} */
            var newState_1 = __assign({}, state, { isLoading: false });
            Object.keys(action.payload).forEach((/**
             * @param {?} k
             * @return {?}
             */
            function (k) {
                newState_1[k] = action.payload[k];
                // newState.config[k] = action.payload[k];
            }));
            newState_1.timestamp = Util.getTimeStamp();
            return newState_1;
        default:
            return state;
    }
}

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/** @type {?} */
var addState = actionCreator((/**
 * @param {?} payload
 * @return {?}
 */
function (payload) {
    return {
        type: 'ADD_STATE',
        payload: payload
    };
}));
/** @type {?} */
var setState = actionCreator((/**
 * @param {?} key
 * @param {?} value
 * @return {?}
 */
function (key, value) {
    /** @type {?} */
    var payload = {};
    payload[key] = value;
    return {
        type: 'ADD_STATE',
        payload: payload
    };
}));
/** @type {?} */
var loadConfig = actionCreator((/**
 * @param {?} payload
 * @return {?}
 */
function (payload) {
    if (typeof payload === 'string') {
        return {
            type: 'CONFIG_LOADING',
            payload: ajax(payload).pipe(map((/**
             * @param {?} xhr
             * @return {?}
             */
            function (xhr) {
                return {
                    type: 'CONFIG_LOADED',
                    payload: xhr.response
                };
            })))
        };
    }
    else {
        return {
            type: 'CONFIG_LOADED',
            payload: payload
        };
    }
}));
/** @type {?} */
var addConfig = actionCreator((/**
 * @param {?} payload
 * @return {?}
 */
function (payload) {
    return {
        type: 'ADD_CONFIG',
        payload: payload
    };
}));
/** @type {?} */
var setConfig = actionCreator((/**
 * @param {?} key
 * @param {?} value
 * @return {?}
 */
function (key, value) {
    /** @type {?} */
    var payload = {};
    payload[key] = value;
    return {
        type: 'ADD_CONFIG',
        payload: payload
    };
}));

var baseActions = /*#__PURE__*/Object.freeze({
    addState: addState,
    setState: setState,
    loadConfig: loadConfig,
    addConfig: addConfig,
    setConfig: setConfig
});

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/** @type {?} */
var singleton = Symbol();
/** @type {?} */
var singletonEnforcer = Symbol();
var StateService = /** @class */ (function () {
    function StateService(enforcer) {
        this._state = {};
        if (enforcer !== singletonEnforcer) {
            throw new Error('Cannot construct singleton');
        }
        this._type = 'StateService';
        this._config = ConfigService.instance;
        this.createStore = createStore;
        this.createCombinedStore = createCombinedStore;
        this.initStores();
    }
    /**
     * @return {?}
     */
    StateService.prototype.initStores = /**
     * @return {?}
     */
    function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                // this._store$ = createCombinedStore({base: baseReducer, app: reducer, uaas: uaasReducer}, {foo:'bar'})
                this._store$ = createStore(baseReducer);
                this._actions = baseActions;
                this._store$.subscribe((/**
                 * @param {?} state
                 * @return {?}
                 */
                function (state) {
                    _this._state = state;
                }));
                return [2 /*return*/];
            });
        });
    };
    /**
     * @param {?} key
     * @param {?} value
     * @return {?}
     */
    StateService.prototype.set = /**
     * @param {?} key
     * @param {?} value
     * @return {?}
     */
    function (key, value) {
        setState(key, value);
    };
    /**
     * @param {?} key
     * @return {?}
     */
    StateService.prototype.get = /**
     * @param {?} key
     * @return {?}
     */
    function (key) {
        return this._state[key];
    };
    Object.defineProperty(StateService.prototype, "globalState$", {
        get: /**
         * @return {?}
         */
        function () {
            return this._store$;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(StateService.prototype, "actions", {
        get: /**
         * @return {?}
         */
        function () {
            return this._actions;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(StateService.prototype, "type", {
        get: /**
         * @return {?}
         */
        function () {
            return this._type;
        },
        set: /**
         * @param {?} value
         * @return {?}
         */
        function (value) {
            this._type = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(StateService, "instance", {
        get: /**
         * @return {?}
         */
        function () {
            if (!this[singleton]) {
                this[singleton] = new StateService(singletonEnforcer);
            }
            return this[singleton];
        },
        enumerable: true,
        configurable: true
    });
    return StateService;
}());

/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/** @type {?} */
var singleton$1 = Symbol();
/** @type {?} */
var singletonEnforcer$1 = Symbol();
var HttpService = /** @class */ (function (_super) {
    __extends(HttpService, _super);
    function HttpService(enforcer) {
        var _this = _super.call(this) || this;
        if (enforcer !== singletonEnforcer$1) {
            throw new Error('Cannot construct singleton');
        }
        _this._type = 'HttpService';
        return _this;
    }
    /**
     * @param {?} url
     * @param {?=} options
     * @return {?}
     */
    HttpService.prototype.get = /**
     * @param {?} url
     * @param {?=} options
     * @return {?}
     */
    function (url, options) {
        if (options === void 0) { options = {}; }
        /** @type {?} */
        var preflight = this.preflightGet(url, options);
        return Observable_2.create((/**
         * @param {?} observer
         * @return {?}
         */
        function (observer) {
            fetch(preflight.url, preflight.options)
                .then((/**
             * @param {?} response
             * @return {?}
             */
            function (response) { return response.json(); })) // or text() or blob() etc.
                .then((/**
             * @param {?} data
             * @return {?}
             */
            function (data) {
                observer.next(data);
                observer.complete();
            }))
                .catch((/**
             * @param {?} err
             * @return {?}
             */
            function (err) {
                console.error(err);
                observer.error(err);
            }));
        }));
    };
    /**
     * @param {?} url
     * @param {?} object
     * @param {?} options
     * @return {?}
     */
    HttpService.prototype.put = /**
     * @param {?} url
     * @param {?} object
     * @param {?} options
     * @return {?}
     */
    function (url, object, options) {
    };
    /**
     * @param {?} url
     * @param {?} object
     * @param {?} options
     * @return {?}
     */
    HttpService.prototype.post = /**
     * @param {?} url
     * @param {?} object
     * @param {?} options
     * @return {?}
     */
    function (url, object, options) {
    };
    /**
     * @param {?} url
     * @param {?} object
     * @param {?} options
     * @return {?}
     */
    HttpService.prototype.delete = /**
     * @param {?} url
     * @param {?} object
     * @param {?} options
     * @return {?}
     */
    function (url, object, options) {
    };
    Object.defineProperty(HttpService, "instance", {
        get: /**
         * @return {?}
         */
        function () {
            if (!this[singleton$1]) {
                this[singleton$1] = new HttpService(singletonEnforcer$1);
            }
            return this[singleton$1];
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HttpService.prototype, "type", {
        get: /**
         * @return {?}
         */
        function () {
            return this._type;
        },
        set: /**
         * @param {?} value
         * @return {?}
         */
        function (value) {
            this._type = value;
        },
        enumerable: true,
        configurable: true
    });
    return HttpService;
}(HttpClient));
/** @type {?} */
var log = console.log.bind(console);

const NAME_CHANGED = 'NAME_CHANGED';
const GITHUB_FOLLOWERS_LOADING = 'GITHUB_FOLLOWERS_LOADING';
const GITHUB_FOLLOWERS_LOADED = 'GITHUB_FOLLOWERS_LOADED';
const initialState = { appId: '@ema/js-base', timestamp: Util.getTimeStamp(), config: {} };
const changeName = actionCreator((payload) => {
    return {
        type: NAME_CHANGED,
        payload
    };
});
function reducer(state, action) {
    switch (action.type) {
        case NAME_CHANGED:
            return Object.assign({}, state, { isLoading: false, timestamp: Util.getTimeStamp(), name: action.payload });
        case GITHUB_FOLLOWERS_LOADING:
            return Object.assign({}, state, { isLoading: true });
        case GITHUB_FOLLOWERS_LOADED:
            return Object.assign({}, state, { isLoading: false, users: action.payload });
        default:
            return state;
    }
}

const SUB_ACTION = 'SUB_ACTION';
const initialState$1 = { clientId: 'es-nl', authenticated: false, timestamp: Util.getTimeStamp(), config: {} };
const subAction = actionCreator((payload) => {
    return {
        type: SUB_ACTION,
        payload
    };
});
function uaasReducer(state, action) {
    switch (action.type) {
        case SUB_ACTION:
            return Object.assign({}, state, { subKey: action.payload });
        default:
            return state;
    }
}

const singleton$2 = Symbol();
const singletonEnforcer$2 = Symbol();
class AppService {
    constructor(enforcer) {
        this.baseUrl = '';
        this.loading = true;
        this.authenticated = false;
        this.errorMessage = '';
        if (enforcer !== singletonEnforcer$2) {
            throw new Error('Cannot construct singleton');
        }
        this.base = BaseService.instance;
        this.stateService = StateService.instance;
        this.permissions = PermissionsService.instance;
        this.translation = this.base.translation;
        this.config = this.base.config;
        this.user = new User('visitor');
        this.init().then(() => {
            this.stateService.actions.setState('initialized', true);
            this.test();
        });
    }
    async init() {
        this.initStores();
        await this.base.initApp(this.baseUrl + '/assets/config.json', true, '_emaApp');
        await this.permissions.loadRules(this.baseUrl + '/assets/permissions.json', true, 'rules');
        this.base.translation.use(this.config.get('language'));
        this.data = {};
        this.data.manifest = await Util.fetchJson(this.baseUrl + '/assets/collection-manifest.json');
        this.data.mockData = await Util.fetchJson(this.baseUrl + '/assets/data/mock-data.json');
        this.data.dwpData = await Util.fetchJson(this.baseUrl + '/assets/data/mock-dwp.json');
        this.data.swaggerData = await Util.fetchJson(this.baseUrl + '/assets/data/apiSwagger.json');
        this.collectionManifest = this.data.manifest;
        this.parseComponents();
        this.initHistory();
        this.initSketchListeners();
        if (window.document.location.hostname.match('localhost'))
            this.config.set('dev', true);
    }
    async initStores() {
        this.globalState$ = this.stateService.globalState$;
        this.globalState$.pipe(pluck('initialized')).subscribe((state) => {
            this.initialized = state;
        });
        this.state$ = this.stateService.createCombinedStore({ app: reducer, uaas: uaasReducer }, { foo: 'bar' });
        this.state$.subscribe((state) => {
        });
        this.uaas$ = this.stateService.createStore(uaasReducer, Object.assign({}, initialState$1, { clientId: 'es-nl-config', custom: 'ja ja' }));
        this.uaas$.pipe(pluck('subKey')).subscribe((state) => {
        });
    }
    initSketchListeners() {
        fromEvent(document, 'sketch-artboard-init').subscribe((event) => {
            console.log('sketch init: ', event.detail.selector);
        });
        fromEvent(document, 'sketch-artboard-update').subscribe((event) => {
            console.log('sketch update: ', event.detail.selector);
        });
        fromEvent(document, 'svgElementClick').subscribe((event) => {
            let id = event.detail.id;
            let el = event.detail.el;
            if (id.match('btn-logo')) {
                this.showFlashMessage('Called from sketch: id=' + id, 'primary', 2000);
            }
            if (id.match('icon-sketch')) ;
            console.log('svg: id = ', event.detail.id);
        });
    }
    test() {
        console.log('test');
        this.stateService.actions.addConfig(this.config.all());
        changeName('Bob');
        subAction('uaas payload');
        this.stateService.actions.setConfig('foo', 'bar');
        changeName('Bob de bouwer');
        this.stateService.set('foo', 'global bar');
    }
    initHistory() {
        if (typeof window !== 'undefined' && window.history) ;
    }
    parseComponents() {
        let allComps = Util.copy(this.data.manifest.components);
        let components = [];
        allComps.map((c) => {
            let tag = c.tag;
            let ignore = false;
            this.config.get('componentsIgnorePatterns').forEach((p) => {
                if (tag.match(p)) {
                    ignore = true;
                }
            });
            if (!ignore) {
                components.push(c);
            }
        });
        this.components = components;
    }
    showFlashMessage(message, type, duration = 2000) {
        document.querySelector('ema-flash-message').show(message, type, duration);
    }
    static get instance() {
        if (!this[singleton$2]) {
            this[singleton$2] = new AppService(singletonEnforcer$2);
        }
        return this[singleton$2];
    }
}

export { AppService as a, HttpService as b };
