
const WINDOW = 'WaitingMode';

class DemoApiWindowManager {
    static init() {
        window.sigApiReadyPromise.then(() => {
            const codemodule = new DemoApiWindowManager();
        });
    }

    constructor() {
        this._registerEvents();
    }

    delay(delayInms) {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(2);
            }, delayInms);
        });
    }
    /**
     * @private
     * Subscribe to user defined events.
     * There is no need to use the sigUtils API to register event listeners because
     * global code modules such as this one are never destroyed during runtime. 
     */
    _registerEvents() {
        sigApi.eventMediator.subscribe(
            sigApi.events.getUserDefinedInternalEvent('CloseWindow68'),
            () => {
                this.sample();
            }
        );
    }

    async sample() {
        window.window.sigApi.windowManager.openWindowByWindowIndex(68);
        let delayres26 = await this.delay(250); // Wartezeit 300ms / 1000 = 1 sec
        window.window.sigApi.windowManager.closeWindowByWindowIndex(68);
    }

}

/**
 * Create the codemodule instance
 */
DemoApiWindowManager.init();
