UI.moduleBuilder['Alexa']['register_chooseDevice'] = function() {
    var chooseDeviceData = {
        remoteAppBg:UI.item_bg,
        OKBtnImg:UI.item_bg,
        hisIcon:"",
        oemIcon:"",
        remoteAPPHelpText: "[SE3940]",
        setupLaterBtnText:"[SE3941]",
        subHelpText:"[SE4009]",
        setupNowBtnText: "[LA0082]"
    };
    var template = Util.readJson("module/Alexa/register_chooseDevice.json");
    var register_chooseDevice = SubModule.create(chooseDeviceData, template);
    var remoteAppTiles = UI.getItem(register_chooseDevice, "remoteAppTiles");
    var oemIcon = UI.getItem(register_chooseDevice, "oemIcon");
    var hisIcon = UI.getItem(register_chooseDevice, "hisIcon");

    var setupLaterBtn = UI.getItem(register_chooseDevice, "setupLaterBtn");
    var setupNowBtn = UI.getItem(register_chooseDevice, "setupNowBtn");
    register_chooseDevice.protected = true;

    register_chooseDevice.onPush = function(){
        if(tv){
            try{
                pubAvsRegisterOpen();
            }catch(ex){
                DBG_ERROR(ex.message);
            }
        }
        var currBrand = tv ? model.system.getCurBrand() :"his";
        var testArray = [];
        var subTestArray = [];
        var bgImg = [];
        var remoteAppArray = [];
        var remoteAppArrayLength ;
        if(currBrand == "his"){
            hisIcon.alpha = 1;
            oemIcon.alpha = 0;
           UI.setImage(hisIcon,"Alexa/register/HisenseAlexalogo.png");
        }else{
            hisIcon.alpha = 0;
            oemIcon.alpha = 1;
            if(avs_support && avg_support){
                UI.setImage(oemIcon,"Alexa/register/AlexaENABLED.png");
            }else if(!avs_support && avg_support){
                UI.setImage(oemIcon,"Alexa/register/WorkwithAlexa.png");
            }else{
                DBG_ERROR("no such requirement");
            }
        }
        if(avs_support && avg_support){
            subTestArray = ["", "[SE4013]", ""];
            if(currBrand == "his"){
                testArray = ["[SE4010]",
                    "[SE4012]",
                    "[SE4011]"
                ];
                bgImg = ["Alexa/register/alexa_remote_app.png", "Alexa/register/alexa_echo.png", "Alexa/register/alexa_remote.png"];
            }else{
                testArray = ["Download our Smart TV Remote app to control smart home devices and stream Amazon Music on your Smart TV - just tap to ask Alexa.",
                    "[SE4012]",
                    "[SE4011]"
                ];
                bgImg = ["Alexa/register/alexa_remote_app_sharp.png", "Alexa/register/alexa_echo.png", "Alexa/register/alexa_remote.png"];
            }
            remoteAppArray = [];
            if(!!AVSClient.model.getBTRCSupport()){
                remoteAppArrayLength = 3;
                remoteAppTiles.x = 110;
            }else{
                remoteAppArrayLength = 2;
                remoteAppTiles.x = 380;
            }
        }else if(!avs_support && avg_support){
            testArray = ["[SE4012]"];
            subTestArray = ["[SE4013]"];
            bgImg = [ "Alexa/register/alexa_echo.png"];
            remoteAppArray = [];
            remoteAppArrayLength = 1;
            remoteAppTiles.x = 650;
        }else{
            DBG_ERROR("no such requirement");
        }
        for (var i=0; i < remoteAppArrayLength; i++) {
            remoteAppArray.push({});
            remoteAppArray[i].name = "remoteAppDevice" + i;
            remoteAppArray[i].bgImg = bgImg[i];
            remoteAppArray[i].text = testArray[i];
            remoteAppArray[i].subText = subTestArray[i];
        }
        while (remoteAppTiles.children.length > 0) {
            remoteAppTiles.children.pop();
        }
        var info = {
            template: "alexa_register_remoteApp_item",
            direction: CONST.GIRD_DIRECTION.H,
            breakNum: 3,
            distanceX: 80,
            distanceY: 0,
            container: remoteAppTiles
        };
        Gird.create(remoteAppArray, info);
        register_chooseDevice.currFocus = setupNowBtn;
    };



    register_chooseDevice.onPop = function(){
    }

    /*if(group1.alpha == SHOW){
        tiles.children[0].onkey_ENTER = function(){
//        if(group1.alpha == SHOW){
            writeFileToNative("hisenseUI/disVoiceChrome", "able", 1);
            registerUpdate(1);
//        }
        }

        tiles.children[1].onkey_ENTER = function(){
//        if(group1.alpha == SHOW){
            var register_bg = UI.getSubModule("register_bg");
            var navbarTiles = UI.getItem(register_bg, "navbarTiles");
            register_bg.sequence = ["register_chooseDevice", "register_hisense", "register_rename", "register_setup","register_demo"];
            register_bg.navbarContent = ["1", "2", "3", "4", "5"];
            register_bg.title = ["chooseDevice", "hisense", "rename", "setup","demo"];
            navbarTiles.removeAllChildren();
            var navbar = [];
            for (var i = 0; i < register_bg.navbarContent.length; i++) {
                navbar.push({});
                navbar[i].navName = register_bg.navbarContent[i];
                navbar[i].name = "register" + i;
            }
            var navinfo = {
                template: "fte_background_item",
                direction: CONST.GIRD_DIRECTION.v,
                breakNum: 1,
                distanceX: 48,
                distanceY: 0,
                container: navbarTiles,
                x: 0,
                y: 0
            };
            Gird.create(navbar, navinfo);
            for (var i=0; i < navbarTiles.children.length; i++) {
                navbarTiles.children[i].children[0].alpha = 0.3;
            }
            registerUpdate(1);
            writeFileToNative("hisenseUI/disVoiceChrome", "disable", 1);
//        }
        }

    }*/

    setupLaterBtn.onkey_ENTER = function(){
        Alexa.onkey_BACKSPACE();
    }

    setupNowBtn.onkey_ENTER = function(){
        registerUpdate(1);
    }

}

