/*!
 * Custom elements for Nanopore-Digital Web applications
 */
import { getElement } from '@stencil/core/internal/client';

var createDeferredPromise = function () {
    var resolve;
    var promise = new Promise(function (res) { resolve = res; });
    return { promise: promise, resolve: resolve };
};

var openWormhole = function (Component, props) {
    var ComponentPrototype = Component.prototype;
    var componentWillLoad = ComponentPrototype.componentWillLoad;
    ComponentPrototype.componentWillLoad = function () {
        var _this = this;
        var el = getElement(this);
        var onOpen = createDeferredPromise();
        var event = new CustomEvent('openWormhole', {
            bubbles: true,
            composed: true,
            detail: {
                consumer: this,
                fields: props,
                updater: function (prop, value) { _this[prop] = value; },
                onOpen: onOpen,
            },
        });
        el.dispatchEvent(event);
        return onOpen.promise.then(function () {
            if (componentWillLoad) {
                return componentWillLoad.call(_this);
            }
        });
    };
};

var SearchChangeEvent;
(function (SearchChangeEvent) {
    SearchChangeEvent["Filter"] = "filter";
    SearchChangeEvent["Page"] = "page";
    SearchChangeEvent["Replica"] = "replica";
    SearchChangeEvent["Init"] = "init";
})(SearchChangeEvent || (SearchChangeEvent = {}));
const Wormhole = (Component, props) => openWormhole(Component, props);

export { SearchChangeEvent as S, Wormhole as W };
