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

import { a as __extends, e as __assign } from './chunk-de721f0a.js';
import { i as Observable, e as Subscriber, j as map, r as BehaviorSubject, s as concatAll, q as interval } from './chunk-237a2f57.js';
import { n as createCommonjsModule, o as unwrapExports, p as commonjsGlobal, d as Util, q as Config, r as HttpClient, s as BaseApi, f as ConfigService, e as DomUtil } from './chunk-f41c48db.js';
import { a as AppService } from './chunk-628d443f.js';
import { b as pluck } from './chunk-4fdb8e51.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; }, 0);
}
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._parentOrParents = null;
        this._subscriptions = null;
        if (unsubscribe) {
            this._unsubscribe = unsubscribe;
        }
    }
    Subscription.prototype.unsubscribe = function () {
        var errors;
        if (this.closed) {
            return;
        }
        var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions;
        this.closed = true;
        this._parentOrParents = null;
        this._subscriptions = null;
        if (_parentOrParents instanceof Subscription) {
            _parentOrParents.remove(this);
        }
        else if (_parentOrParents !== null) {
            for (var index = 0; index < _parentOrParents.length; ++index) {
                var parent_1 = _parentOrParents[index];
                parent_1.remove(this);
            }
        }
        if (isFunction_1.isFunction(_unsubscribe)) {
            try {
                _unsubscribe.call(this);
            }
            catch (e) {
                errors = e instanceof UnsubscriptionError.UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e];
            }
        }
        if (isArray.isArray(_subscriptions)) {
            var index = -1;
            var len = _subscriptions.length;
            while (++index < len) {
                var sub = _subscriptions[index];
                if (isObject_1.isObject(sub)) {
                    try {
                        sub.unsubscribe();
                    }
                    catch (e) {
                        errors = errors || [];
                        if (e instanceof UnsubscriptionError.UnsubscriptionError) {
                            errors = errors.concat(flattenUnsubscriptionErrors(e.errors));
                        }
                        else {
                            errors.push(e);
                        }
                    }
                }
            }
        }
        if (errors) {
            throw new UnsubscriptionError.UnsubscriptionError(errors);
        }
    };
    Subscription.prototype.add = function (teardown) {
        var subscription = teardown;
        if (!teardown) {
            return Subscription.EMPTY;
        }
        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: {
                throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
            }
        }
        var _parentOrParents = subscription._parentOrParents;
        if (_parentOrParents === null) {
            subscription._parentOrParents = this;
        }
        else if (_parentOrParents instanceof Subscription) {
            if (_parentOrParents === this) {
                return subscription;
            }
            subscription._parentOrParents = [_parentOrParents, this];
        }
        else if (_parentOrParents.indexOf(this) === -1) {
            _parentOrParents.push(this);
        }
        else {
            return subscription;
        }
        var subscriptions = this._subscriptions;
        if (subscriptions === null) {
            this._subscriptions = [subscription];
        }
        else {
            subscriptions.push(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.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 _parentOrParents = this._parentOrParents;
        this._parentOrParents = null;
        this.unsubscribe();
        this.closed = false;
        this.isStopped = false;
        this._parentOrParents = _parentOrParents;
        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;

var RxStore = /** @class */ (function () {
    function RxStore(initialState) {
        this._state$ = new BehaviorSubject(initialState);
        this.state$ = this._state$.asObservable();
    }
    Object.defineProperty(RxStore.prototype, "state", {
        get: function () {
            return this._state$.getValue();
        },
        enumerable: true,
        configurable: true
    });
    RxStore.prototype.setState = function (nextState) {
        this._state$.next(nextState);
    };
    RxStore.prototype.getStateItem = function (key) {
        return this.state[key];
    };
    RxStore.prototype.setStateItem = function (key, value) {
        var newState = {};
        newState[key] = value;
        this.setState(__assign({}, this.state, newState));
    };
    return RxStore;
}());

var RxAppStore = /** @class */ (function (_super) {
    __extends(RxAppStore, _super);
    function RxAppStore(initialState) {
        var _this = _super.call(this, initialState) || this;
        _this.setStateItem('timestamp', Util.getTimeStamp());
        _this.config = new Config();
        return _this;
    }
    RxAppStore.prototype.setConfig = function (key, value) {
        this.config.set(key, value);
        this.setState(__assign({}, this.state, { config: this.config.get() }));
    };
    RxAppStore.prototype.setConfigInstance = function (configInstance) {
        this.config = configInstance;
    };
    // todo: implement ?
    RxAppStore.prototype.dispatch = function (obj) {
        var _this = this;
        var nextState = this.state;
        switch (obj.key) {
            case 'AJAX':
                return ajax(obj.payload.url).pipe(map(function (xhr) {
                    nextState[obj.payload.key] = xhr.response;
                    _this.setState(nextState);
                })).subscribe();
            default:
                nextState[obj.key] = obj.payload;
                this.setState(nextState);
        }
    };
    return RxAppStore;
}(RxStore));

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

/*
//
// Base class for vanilla js webcomponents
//
*/
class WebComponent extends HTMLElement {

    constructor() {
        super();
        this.getData = this.getData.bind(this);
        this.setData = this.setData.bind(this);
        // this.state = this.state.bind(this);
        if (this.definePublicMethods) {
            this.definePublicMethods();
        }
    }

    // to be overridden in subclass
    async init() {
    }

    render() {
    }

    definePublicMethods() {
    }

    attributeChangedCallback(name, oldVal, newVal) {
    }

    //

    connectedCallback() {
        let shadowRoot;
        if (!this.shadowRoot) {
            if (this.shadow) {
                shadowRoot = this.root = this.attachShadow({
                    mode: 'open'
                });
            } else {
                shadowRoot = this.root = this;
            }
        } else {
            shadowRoot = this.root = this.shadowRoot;
        }
        shadowRoot.appendChild(this.template.content.cloneNode(true));
        this.el = this.root.querySelector('.content');
        this.data = {};
        // this.html = this.html.bind(this);
        // this.state = this.state.bind(this);
        // this.getData = this.getData.bind(this);
        // this.setData = this.setData.bind(this);
        // if (this.definePublicMethods) {
        //     this.definePublicMethods();
        // }
        if (this.init) {
            this.init = this.init.bind(this);
        }
        if (this.dataJson) {
            this.data = JSON.parse(this.dataJson);
        }
        if (this.init) {
            this.init().then(() => {
                this.render();
            });
        } else {
            this.render();
        }
    }

    set html(markup) {
        if (this.el && markup) {
            this.el.innerHTML = markup;
        }
    }

    get template() {
        if (this._template) {
            return this._template;
        }
        this._template = document.createElement('template');
        let styles = document.createElement('style');
        let content = document.createElement('div');
        let imports = document.createElement('head');
        imports.innerHTML = this.imports || ``;
        styles.innerHTML = this.styles || ``;
        content.innerHTML = this.htmlTemplate || ``;
        content.className = 'content';
        this._template.content.appendChild(styles);
        this._template.content.appendChild(imports);
        this._template.content.appendChild(content);
        return this._template;
    }

    declareProp(propName, getFn, setFn) {
        let obj = {};
        if (!getFn) {
            getFn = function () {
                if (this.getAttribute(propName) !== null) {
                    return this.getAttribute(propName);
                } else {
                    return '';
                }
            };
        }
        if (!setFn) {
            setFn = function (value) {
                this.setAttribute(propName, value);
            };
        }
        if (propName === 'data-json') {
            setFn = (value) => {
                let data = JSON.parse(value);
                Object.keys(data).forEach((k) => {
                    this.data[k] = data[k];
                });
                this.setState({data: data});
                this.setAttribute(propName, value);
            };
        }
        obj[this.kebabToLowerCamelCase(propName)] = {get: getFn, set: setFn};
        Object.defineProperties(this, obj);
    }

    dispatch(eventName, detail) {
        this.dispatchEvent(new CustomEvent(eventName, {bubbles: true, detail: detail}));
    }

    setState(state) {
        if (typeof state === 'string' && !this.isJson(state)) {
            console.error('setState only accepts an object as argument');
            return;
        }
        if (typeof state === 'string' && this.isJson(state)) {
            state = JSON.parse(state);
        }
        if (!this.state) {
            this.state = {};
        }
        this.state = {...this.state, ...state};
        this.render();
    }

    setData(object, extend) {
        if (extend) {
            Object.keys(object).forEach((k, i) => {
                this.data[k] = object[k];
            });
        } else {
            this.data = object;
        }
        this.setState({data: this.data});
        // this.render();
    }

    getData() {
        return this.data;
    }

    isJson(jsonString) {
        try {
            let o = JSON.parse(jsonString);
            if (o && typeof o === "object") {
                return o;
            }
        } catch (e) {
        }
        return false;
    }

    kebabToLowerCamelCase(str) {
        let string = str.charAt(0).toLowerCase() + str.slice(1);
        return string.replace(/(\-\w)/g, function (m) {
            return m[1].toUpperCase();
        });
    }

}

const props = ['label', 'foo', 'foo2', 'test', 'data-json'];
window.customElements.define('web-comp-runtime', class extends WebComponent {
    constructor() {
        super();
        this.defineProps(props);
        this.styles = `:host .content { 
            background: var(--ema-primary,black); 
            color:white;padding:15px;
        }`;
    }
    render() {
        this.html = `
      
          <h5>${this.label}: - foo =  ${this['data'].foo}  - sliderV: ${this['data'].sliderV}</h5>
       
          <ema-slider value="${this['data'].sliderV}"></ema-slider>
          <ema-card>
            <ema-card-header>
                <span class="ema-card-header-title">${this.label}</span>
                <span class="ema-card-header-subtitle">${this['data'].foo}</span>
            </ema-card-header>
            <ema-card-content>
                Content goes here
            </ema-card-content>
            <ema-card-footer>
                <button class="btn btn-primary">Action!</button>
            </ema-card-footer>
            </ema-card>
        `;
    }
    attributeChangedCallback(name, oldVal, newVal) {
        this.render();
    }
    defineProps(props) {
        props.forEach((propName) => {
            let get, set;
            if (propName === 'test') {
                get = () => {
                    return this.getAttribute(propName) + ': CUSTOM GET';
                };
                set = (value) => {
                    this.setAttribute(propName, value + ': CUSTOM SET');
                };
            }
            this.declareProp(propName, get, set);
        });
    }
    hide() {
        this.root.querySelector('.content').style.display = 'none';
    }
    definePublicMethods() {
        this.hide = this.hide.bind(this);
    }
});

class AppDev {
    constructor() {
        this.authenticated = false;
        this.clientId = 'e-be';
        this.app = AppService.instance;
        this.api = new BaseApi();
        this.http = HttpService.instance;
        this.config = ConfigService.instance;
        this.translation = this.app.translation;
        this.data = this.app.data;
    }
    async runTests() {
        let repeaterMockData = [];
        let data$ = this.http.get('assets/data/mock-data.json');
        data$.pipe(pluck('data'), concatAll(), map((item) => item['data']['attributes'])).subscribe((arg) => {
            repeaterMockData.push(arg);
        }, undefined, () => {
            console.log('complete');
            this.data = Object.assign({}, this.data, { repeaterMockData: repeaterMockData });
        });
        let webcomponent = this.el.querySelector('web-comp-runtime');
        interval(3000).subscribe((arg) => {
            if (webcomponent) {
                webcomponent['label'] = Math.random();
                webcomponent['setData'](this.data);
            }
        });
        let dialogComponent = document.getElementById('app-dialog');
        if (dialogComponent) {
            dialogComponent['setConfirmHandler'](function () {
                console.log('dialogConfirmHandler called');
            });
        }
    }
    debuggerTest() {
        let emaDebugger = document.querySelector('ema-debugger');
        if (emaDebugger) {
            emaDebugger.open();
            interval(1500).subscribe((i) => {
                if (i <= this.data.dwpData.length - 1) {
                    if (emaDebugger) {
                        emaDebugger.dataJson = JSON.stringify(this.data.dwpData[i]);
                    }
                }
            });
        }
    }
    componentDidLoad() {
        this.runTests();
    }
    render() {
        return (h("div", null,
            h("div", { class: 'container' }, this.data &&
                h("div", null,
                    h("ema-tabs", null,
                        h("ema-tab-header", { slot: "header", name: "tab1" }, "Div"),
                        h("ema-tab-content", { slot: "content", name: "tab1" },
                            h("div", { class: "btn-group mb-3", role: "group", "aria-label": "Basic examples" },
                                h("button", { class: 'btn ', onClick: ev => this.runTests() }, "Run tests"),
                                h("button", { class: 'btn ', onClick: ev => this.debuggerTest() }, "Open debugger"),
                                h("button", { class: 'btn ', onClick: ev => document.getElementById('login-modal')['show']() }, "Login modal"),
                                h("button", { class: 'btn ', onClick: () => this.app.showFlashMessage('zis is ze message', 'secondary', 3000) }, "Show flashmessage"),
                                h("button", { class: 'btn ', onClick: ev => document.querySelector('ema-dialog').alert('yep') }, "Alert"),
                                h("button", { class: 'btn ', onClick: ev => document.querySelector('ema-dialog').confirm('Are you sure?', function () { console.log('confirmed'); }) }, "Confirm"),
                                h("button", { class: 'btn ', onClick: ev => document.querySelector('ema-dialog').confirm('Are you sure?') }, "Confirm2"),
                                h("button", { class: 'btn ', onClick: ev => document.querySelector('ema-dialog').notice('Notice content') }, "Notice"),
                                h("button", { class: 'btn ', onClick: ev => DomUtil.fadeIn(document.getElementById('logo')) }, "fIn"),
                                h("button", { class: 'btn ', onClick: ev => DomUtil.fadeOut(document.getElementById('logo')) }, "fOut")),
                            h("web-comp", { label: "runtime webcomponent", test: "test", "data-json": JSON.stringify({ foo: 'bar', sliderV: 0 }) }),
                            h("web-comp-runtime", { label: "runtime webcomponent", "data-json": JSON.stringify({ foo: 'bar', sliderV: 0 }) }),
                            h("ema-collapsible", { label: 'config', collapsed: true },
                                h("ema-json-viewer", { "json-url": '/assets/config.json', allowCopy: true }))),
                        h("ema-tab-header", { slot: "header", name: "tab6" }, "Flip board"),
                        h("ema-tab-content", { slot: "content", name: "tab6" },
                            h("ema-layout", { class: 'layout-grid-fill flip-board' }, this.data.manifest.components.map((item, i) => {
                                return h("ema-flip", { class: "item", "flip-events": "click", "flip-back-events": "click", "flip-duration": "350", "flip-timing-function": "ease-in-out" },
                                    h("div", { slot: "front" },
                                        h("ema-card", null,
                                            h("ema-card-header", null,
                                                h("span", { class: "ema-card-header-title" }, (i + 1)),
                                                h("span", { class: "ema-card-header-subtitle" }, '<ema-flip>')),
                                            h("ema-card-content", null, "info goes here"),
                                            h("ema-card-footer", null,
                                                h("button", { class: 'btn btn-primary' }, "flip me")))),
                                    h("div", { slot: "back" },
                                        h("ema-card", null,
                                            h("ema-card-header", null,
                                                h("span", { class: "ema-card-header-title" }, "Flip card back"),
                                                h("span", { class: "ema-card-header-subtitle" }, "Subtitle")),
                                            h("ema-card-content", null, "Content goes here"),
                                            h("ema-card-footer", null,
                                                h("button", { class: 'btn btn-primary' }, "Action!")))));
                            }))),
                        h("ema-tab-header", { slot: "header", name: "tab5" }, "Layout"),
                        h("ema-tab-content", { slot: "content", name: "tab5" },
                            h("h5", null, ".layout-header-sidebar20-content80-footer"),
                            h("ema-layout", { class: 'layout-header-sidebar20-content80-footer', "grid-gap": '5px' },
                                h("header", null, "My header"),
                                h("aside", null, "Sidebar"),
                                h("article", null,
                                    h("h4", null, "2 column, header and footer"),
                                    h("p", null, "Example content.")),
                                h("footer", null, "My footer")),
                            h("h5", null, ".layout-grid-fill"),
                            h("ema-layout", { class: 'layout-grid-fill' }, this.data.mockData.data.map((item) => {
                                return h("article", { class: 'text-center' },
                                    h("h4", null, item.data.attributes.title),
                                    h("ema-lazy-img", { src: item.links.self }));
                            })),
                            this.data.mockData.data.map((item) => {
                                return h("ema-layout", { class: 'layout-header-content80-sidebar20-footer mb-3' },
                                    h("header", null,
                                        h("h4", null, item.data.type)),
                                    h("article", null,
                                        h("h3", null, item.data.attributes.title),
                                        h("p", null, item.data.attributes.body)),
                                    h("aside", null,
                                        h("ema-lazy-img", { src: item.links.self })),
                                    h("footer", null, item.data.attributes.email));
                            })),
                        h("ema-tab-header", { slot: "header", name: "repeater" }, "Repeater"),
                        h("ema-tab-content", { slot: "content", name: "repeater" },
                            h("h4", null, "repeater-component"),
                            h("ema-repeater", { element: "ul", template: '<li><h5>${title}</h5><p>${body}</p></li>', "data-json": JSON.stringify(this.data.repeaterMockData) }))))),
            h("footer", null)));
    }
    static get is() { return "ema-app-dev"; }
    static get properties() { return {
        "authenticated": {
            "state": true
        },
        "clientId": {
            "type": String,
            "attr": "client-id"
        },
        "data": {
            "state": true
        },
        "el": {
            "elementRef": true
        }
    }; }
    static get style() { return ":root{--ema-color:#343a40;--ema-primary:#007bff;--ema-secondary:#6c757d;--ema-success:#28a745;--ema-info:#17a2b8;--ema-warning:#ffc107;--ema-danger:#dc3545;--ema-light:#f8f9fa;--ema-dark:#343a40;--ema-background:#fff;--ema-background-diap:rgba(29,29,29,0.97);--ema-border-color:#c5c9cd;--ema-border:1px solid #c5c9cd;--ema-border-radius:3px 3px 3px 3px;--ema-box-shadow:1px 1px 10px 1px #ccc;--ema-margin:0.25rem;--ema-margin-sm:0.5rem;--ema-margin-md:1rem;--ema-margin-lg:1.5rem;--ema-margin-xl:2rem;--ema-padding:0.25rem;--ema-padding-sm:0.5rem;--ema-padding-md:1rem;--ema-padding-lg:1.5rem;--ema-padding-xl:2rem;--ema-gray-100:#f8f9fa;--ema-gray-200:#e9ecef;--ema-gray-300:#dee2e6;--ema-gray-400:#ced4da;--ema-gray-500:#adb5bd;--ema-gray-600:#868e96;--ema-gray-700:#495057;--ema-gray-800:#343a40;--ema-gray-900:#212529}ema-app-dev .flip-board .item{width:240px;justify-self:center;margin:0 auto}ema-app-dev .flip-board .item .ema-card-header-title{font-weight:700}ema-app-dev .flip-board .item .ema-flip__front ema-card{text-align:center}ema-app-dev .flip-board .item .ema-flip__back ema-card{text-align:center;background:#e9e9e9}ema-app-dev .ema-splitter-container{position:absolute;padding-top:0;padding-bottom:calc(var(--header-height) * 2);left:0;height:100%;width:100%}ema-app-dev .ema-splitter-container ema-splitter div[slot]{height:100%;width:100%;display:-ms-flexbox;display:flex;overflow:hidden;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center}ema-app-dev .ema-splitter-container ema-splitter div[slot] ion-icon{display:block;font-size:3rem;color:var(--ema-primary)}ema-app-dev .ema-splitter-container ema-splitter .main .column-2{background:var(--ema-gray-300);border-radius:50%}"; }
}

class Flip {
    constructor() {
        this.events = { flipEvents: [], flipBackEvents: [] };
    }
    componentWillLoad() {
        this.init();
    }
    componentDidLoad() {
        const duration = this.flipDuration || 400;
        const timingFunction = this.flipTimingFunction || 'ease-in';
        ['front', 'back']
            .forEach(key => {
            const el = this.element.querySelector(`.ema-flip__${key}`);
            el['style'].transition = `all ${duration / 1000}s ${timingFunction}`;
        });
    }
    componentWillUpdate() {
        if (this.isFlipped !== undefined) {
            this.flipState = this.isFlipped;
        }
    }
    init() {
        if (this.isFlipped !== undefined) {
            this.flipState = this.isFlipped;
        }
        else if (this.flipEvents !== undefined) {
            ['flipEvents', 'flipBackEvents'].forEach(key => {
                this.events[key] = (this[key]) ?
                    this[key].split(',') :
                    [];
            });
            const allEvents = [...this.events.flipEvents, ...this.events.flipBackEvents];
            allEvents
                .filter((eventType, index) => allEvents.indexOf(eventType) === index)
                .forEach(eventType => this.element.addEventListener(eventType, (evt) => this.processFlip(evt)));
            this.flipState = false;
        }
    }
    processFlip(evt) {
        const eventType = evt.type;
        if (this.flipState && this.events.flipBackEvents.indexOf(eventType) !== -1) {
            this.flipState = !this.flipState;
        }
        else if (!this.flipState && this.events.flipEvents.indexOf(eventType) !== -1) {
            this.flipState = !this.flipState;
        }
    }
    flip() {
        this.flipState = !this.flipState;
        console.log(this.flipState);
    }
    render() {
        return (h("div", { class: `ema-flip ${(this.flipState ? 'ema-flip--flipped' : '')}` },
            h("div", { class: "ema-flip__front" },
                h("slot", { name: "front" })),
            h("div", { class: "ema-flip__back" },
                h("slot", { name: "back" }))));
    }
    static get is() { return "ema-flip"; }
    static get properties() { return {
        "element": {
            "elementRef": true
        },
        "flip": {
            "method": true
        },
        "flipBackEvents": {
            "type": String,
            "attr": "flip-back-events"
        },
        "flipDuration": {
            "type": Number,
            "attr": "flip-duration"
        },
        "flipEvents": {
            "type": String,
            "attr": "flip-events"
        },
        "flipState": {
            "state": true
        },
        "flipTimingFunction": {
            "type": String,
            "attr": "flip-timing-function"
        },
        "isFlipped": {
            "type": Boolean,
            "attr": "is-flipped"
        }
    }; }
    static get style() { return ":root{--ema-color:#343a40;--ema-primary:#007bff;--ema-secondary:#6c757d;--ema-success:#28a745;--ema-info:#17a2b8;--ema-warning:#ffc107;--ema-danger:#dc3545;--ema-light:#f8f9fa;--ema-dark:#343a40;--ema-background:#fff;--ema-background-diap:rgba(29,29,29,0.97);--ema-border-color:#c5c9cd;--ema-border:1px solid #c5c9cd;--ema-border-radius:3px 3px 3px 3px;--ema-box-shadow:1px 1px 10px 1px #ccc;--ema-margin:0.25rem;--ema-margin-sm:0.5rem;--ema-margin-md:1rem;--ema-margin-lg:1.5rem;--ema-margin-xl:2rem;--ema-padding:0.25rem;--ema-padding-sm:0.5rem;--ema-padding-md:1rem;--ema-padding-lg:1.5rem;--ema-padding-xl:2rem;--ema-gray-100:#f8f9fa;--ema-gray-200:#e9ecef;--ema-gray-300:#dee2e6;--ema-gray-400:#ced4da;--ema-gray-500:#adb5bd;--ema-gray-600:#868e96;--ema-gray-700:#495057;--ema-gray-800:#343a40;--ema-gray-900:#212529}.ema-flip{-webkit-perspective:1000px;perspective:1000px;text-align:center}.ema-flip__back,.ema-flip__front{position:absolute;width:inherit;height:inherit;-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-backface-visibility:hidden;backface-visibility:hidden}.ema-flip__front{z-index:900;-webkit-transform:rotate3d(0,0,0,0deg);transform:rotate3d(0,0,0,0deg)}.ema-flip--flipped .ema-flip__front{z-index:900;-webkit-transform:rotateY(180deg);transform:rotateY(180deg);-ms-transform:rotateY(180deg)}.ema-flip__back{z-index:800;-webkit-transform:rotateY(-180deg);transform:rotateY(-180deg)}.ema-flip--flipped .ema-flip__back{z-index:1000;-webkit-transform:rotate3d(0,0,0,0deg);transform:rotate3d(0,0,0,0deg)}"; }
}

class LazyImg {
    componentDidLoad() {
        this.addIntersectionObserver();
    }
    componentWillUpdate() {
        if (this.src !== this.oldSrc) {
            this.addIntersectionObserver();
        }
        this.oldSrc = this.src;
    }
    handleImage() {
        const image = this.el.shadowRoot.querySelector('img');
        image.setAttribute('src', image.getAttribute('data-src'));
        image.onload = () => {
            image.removeAttribute('data-src');
        };
    }
    addIntersectionObserver() {
        if (!this.src) {
            return;
        }
        if ('IntersectionObserver' in window) {
            this.io = new IntersectionObserver((data) => {
                if (data[0].isIntersecting) {
                    this.handleImage();
                    this.removeIntersectionObserver();
                }
            });
            this.io.observe(this.el.shadowRoot.querySelector('img'));
        }
        else {
            this.handleImage();
        }
    }
    removeIntersectionObserver() {
        if (this.io) {
            this.io.disconnect();
            this.io = null;
        }
    }
    render() {
        return (h("img", { "data-src": this.src, alt: this.alt }));
    }
    static get is() { return "ema-lazy-img"; }
    static get encapsulation() { return "shadow"; }
    static get properties() { return {
        "alt": {
            "type": String,
            "attr": "alt"
        },
        "el": {
            "elementRef": true
        },
        "oldSrc": {
            "state": true
        },
        "src": {
            "type": String,
            "attr": "src"
        }
    }; }
    static get style() { return ":root{--ema-color:#343a40;--ema-primary:#007bff;--ema-secondary:#6c757d;--ema-success:#28a745;--ema-info:#17a2b8;--ema-warning:#ffc107;--ema-danger:#dc3545;--ema-light:#f8f9fa;--ema-dark:#343a40;--ema-background:#fff;--ema-background-diap:rgba(29,29,29,0.97);--ema-border-color:#c5c9cd;--ema-border:1px solid #c5c9cd;--ema-border-radius:3px 3px 3px 3px;--ema-box-shadow:1px 1px 10px 1px #ccc;--ema-margin:0.25rem;--ema-margin-sm:0.5rem;--ema-margin-md:1rem;--ema-margin-lg:1.5rem;--ema-margin-xl:2rem;--ema-padding:0.25rem;--ema-padding-sm:0.5rem;--ema-padding-md:1rem;--ema-padding-lg:1.5rem;--ema-padding-xl:2rem;--ema-gray-100:#f8f9fa;--ema-gray-200:#e9ecef;--ema-gray-300:#dee2e6;--ema-gray-400:#ced4da;--ema-gray-500:#adb5bd;--ema-gray-600:#868e96;--ema-gray-700:#495057;--ema-gray-800:#343a40;--ema-gray-900:#212529}:host{display:block}img{max-width:100%}"; }
}

class Repeater {
    constructor() {
        this.content = [];
        this.element = "ul";
        this.template = '';
    }
    componentDidLoad() {
        this.postRender();
    }
    componentDidUpdate() {
        this.postRender();
    }
    postRender() {
        this.el.innerHTML = this.html;
    }
    async setData(content) {
        this.content = content;
    }
    async setTemplate(template) {
        this.templateString = template;
    }
    interpolate(template, obj) {
        if (typeof obj == "object") {
            for (let key in obj) {
                const find = "${" + key + "}";
                if (template.indexOf(find) > -1) {
                    template = template.replace(find, obj[key]);
                    delete obj[key];
                }
            }
        }
        return template;
    }
    render() {
        const element = this.element;
        let html = (element !== null) ? "<" + element.toLowerCase() + ">" : "";
        if (this.template) {
            this.templateString = this.template;
        }
        if (this.dataJson) {
            this.content = JSON.parse(this.dataJson);
        }
        if (Array.isArray(this.content)) {
            this.content.forEach((item) => {
                html += this.interpolate(this.templateString, item);
            });
        }
        else {
            throw new Error("Content should be an Array of objects.");
        }
        html += (element !== null) ? "</" + element.toLowerCase() + ">" : "";
        this.html = html;
        return (h("div", null));
    }
    static get is() { return "ema-repeater"; }
    static get properties() { return {
        "content": {
            "state": true
        },
        "dataJson": {
            "type": String,
            "attr": "data-json"
        },
        "el": {
            "elementRef": true
        },
        "element": {
            "type": String,
            "attr": "element"
        },
        "setData": {
            "method": true
        },
        "setTemplate": {
            "method": true
        },
        "template": {
            "type": String,
            "attr": "template"
        },
        "templateString": {
            "state": true
        }
    }; }
}

export { AppDev as EmaAppDev, Flip as EmaFlip, LazyImg as EmaLazyImg, Repeater as EmaRepeater };
