/**
 * 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 horizontalPresentModule = (function () {
    'use strict';

    /**
     * Updates the view of the horizontal presentation page
     * @param {*} sourceIndex 
     * @param {*} responseValue 
     * @param {*} inputType 
     */
    function updateHorizontalPresentationPage(sourceIndex, responseValue, inputType) {
        const horizontalIconButon = document.getElementById(`horizontal_source_${sourceIndex}`);
        const stopButton = document.getElementById(`horizontal_source_stop_btn_${sourceIndex}`);
        avfUtility.log("updateHorizontalPresentationPage for sourceIndex", sourceIndex, ", responseValue", responseValue, ", inputType", inputType);
        // The horizontal icon button is checked because we can run through the loop for max number of sources in the subscribe state
        if (horizontalIconButon) {
            horizontalIconButon.setAttribute("displaySelectionIndex", 0);
            horizontalIconButon.setAttribute("sourceSelectionIndex", sourceIndex);

            switch (!!inputType && inputType.toLowerCase()) {
                case "devicename":
                    if (responseValue) {
                        horizontalIconButon.setAttribute("selectedDeviceName", responseValue);
                    }
                    break;
                case "presenting":
                    const iconValue = horizontalIconButon.getAttribute("iconName");
                    avfUtility.log("iconValue", iconValue);
                    if (responseValue) {
                        stopButton.style.display = 'block';
                        horizontalIconButon.setAttribute("selected", true);
                        if (avfUtility.isValidInput(iconValue)) {
                            const imageName = configModule.getConfigIcon(iconValue, 'solid');
                            horizontalIconButon.setAttribute("iconurl", `./app/project/assets/img/avf/${imageName}`);
                        }
                    } else {
                        stopButton.style.display = 'none';
                        horizontalIconButon.setAttribute("selected", false);
                        if (avfUtility.isValidInput(iconValue)) {
                            const imageName = configModule.getConfigIcon(iconValue, 'outline');
                            horizontalIconButon.setAttribute("iconurl", `./app/project/assets/img/avf/${imageName}`);
                        }
                    }
                    horizontalIconButon.setAttribute("iconNameSelected", './app/project/assets/img/avf/' + configModule.getConfigIcon(iconValue, 'solid'));
                    horizontalIconButon.setAttribute("iconNameUnselected", './app/project/assets/img/avf/' + configModule.getConfigIcon(iconValue, 'outline'));
                    break;

                case "icon":
                    let iconName = '';
                    if (horizontalIconButon.getAttribute("selected") == true) {
                        iconName = configModule.getConfigIcon(responseValue, 'solid');
                    } else {
                        iconName = configModule.getConfigIcon(responseValue, 'outline');
                    }
                    horizontalIconButon.setAttribute("iconurl", `./app/project/assets/img/avf/${iconName}`);
                    horizontalIconButon.setAttribute("iconName", responseValue);
                    break;

                case "sourcedevicemodel":
                    if (!responseValue) {
                        responseValue = '';
                    }
                    // horizontalIconButon.setAttribute("sourceDeviceModelName", responseValue);
                    break;

                case "sourcedevicetype":
                    if (!responseValue) {
                        responseValue = '';
                    }
                    // horizontalIconButon.setAttribute("sourceDeviceType", responseValue);
                    break;
            }
        }
    }

    return {
        updateHorizontalPresentationPage
    };

}());
