/**
 * Copyright (C) 2020 to the present, Crestron Electronics, Inc.
 * All rights reserved.
 * No part of this software may be reproduced in any form, machine
 * or natural, without the express written consent of Crestron Electronics.
 * Use of this source code is subject to the terms of the Crestron Software License Agreement 
 * under which you licensed this source code.  
 *
 * This code was automatically generated by Crestron's code generation tool.
 */
/* jslint es6 */

const initializingModule = (function () {
    'use strict';

    let subInitializingReady = null;

    /**
     * Onload of the screen
     */
    function onInit() {
        invokeUnsubscriptions();
        initializeVariables();
        invokeSubscriptions();
    }

    /**
     * Invoke subscriptions related to module
     */
    function invokeSubscriptions() {
        subInitializingReady = CrComLib.subscribeState('b', 'Room[0].SystemInfo.Ready', (response) => {
            const initializingResponse = avfUtility.toBool(response);
            avfUtility.log('Room[0].SystemInfo.Ready: ', initializingResponse);
            if (initializingResponse) {
                // if (appModule.getSystemReady() === false) {
                    appModule.setSystemReady(true);
                    // reset(false);
                    avfUtility.log("navigationModule SYSTEM is Ready")
                    navigationModule.closePopup(navigationModule.popupPages.initializingImportPage);
                    navigationModule.goToPage();
                // }
            } else {
                // reset(true);                
                navigationModule.openPopup(navigationModule.popupPages.initializingImportPage);
            }
        });
    }

    /**
     * Invoke unsubscriptions related to module
     */
    function invokeUnsubscriptions() {
        CrComLib.unsubscribeState('b', 'Room[0].SystemInfo.Ready', subInitializingReady);
    }

    /**
     * Initialize all the variables used in this module
     */
    function initializeVariables() {
        subInitializingReady = null;
    }

    /**
     * All public method and properties are exported here
     */
    return {
        onInit
    };

}());