/**
 * composite control module template
 */
let myelement;

class CompositeControlModule {
    /**
     * @returns {CompositeControlModule}
     */
    static create(myelement) {
        return new CompositeControlModule(myelement);
    }

    constructor(myelement)
    {

        this.myelement = myelement;
    }

    /**
     * @param {ViewModel} viewModel
     */
    init(viewModel) {
        this._viewModel = viewModel;

        // Add your own initialization

        this._initialized = true;
        this._active = false;

        myelement = document.getElementById("lvd4a93009dc7024fe6a3afd5b86dff8974");

        //.querySelector(`sig-composite-container > sig-control-input`);

        Applymyelement.initApplymyelement(myelement);
    }

    /**
     * @param {ViewModel} viewModel
     */
    cleanUp(viewModel) {
        // Timeouts, intervals, promises and eventListeners registered using
        // sigApi.sigUtils functions are cleaned up by runtime
        // example of sigApi.sigUtils.setTimeout
        //   sigApi.sigUtils.setTimeout(this, () => {}, 1000);

        // Add your own cleanUp code

        this._initialized = false;
    }

    /**
     * @param {boolean} active
     */
    onActiveChanged(active) {
        // Add your own active state handling code

        this._active = active;
    }

}

class Applymyelement {

    static initApplymyelement(myelement) {

        if (window.sigApi !== undefined) {
            const fm = new Applymyelement(window.sigApi,myelement);
        } else {
            // ist sigApi noch nicht geladen, als EventListener fuer 'SigApiReady' registrieren
            window.addEventListener('SigApiReady', () => {
                const fm = new Applymyelement(window.sigApi,myelement);
            });
        }
    }

    constructor(api, myelement) {

        this.events = null;
        this.eventMediator = null;
        this.datapointAPI = null;
        this._initAPIs(api);

        this.myelement =  myelement;

        this._registerEvents(myelement);
    }

    _initAPIs(api) {
        if ((api !== null) && (api !== undefined)) {
            if (api.datapointManager !== undefined) {
                this.datapointAPI = api.datapointManager;
            }
            if (api.eventMediator !== undefined) {
                this.eventMediator = api.eventMediator;
            }
            if (api.events !== undefined) {
                this.events = api.events;
            }
        }
    }

    _registerEvents(myelement) {myelement.addEventListener("click", () => {window.sigApi.windowManager.openWindowByWindowIndex(65);});}

}

// Register the CompositeControlModule for a composite control
//window.registerCompositeControlModule('ZoneDetails', CompositeControlModule.create);
window.registerDashboardModule('ZoneDetail_Stellbetrieb', CompositeControlModule.create);