var wowOnLabel = $L("Keep Wi-Fi On");
var wowOffLabel = $L("Turn Wi-Fi Off");

SleepconfigAssistant = Class.create({
    initialize: function(){
    },

    configurations:
    [
        {
            label: wowOnLabel,
            value: "enabled"
        },
        {
            label: wowOffLabel,
            value: "disabled"
        }
    ],	

    configModel:
    {
        value: '',
    },

    setup: function(){
        Mojo.Log.info("sleepconfig setup");
        this.controller.setupWidget('configSelector',
            {
                choices: this.configurations
            }, this.configModel);
        this.controller.get('configSelector').observe('mojo-property-change', this.configChanged.bindAsEventListener(this) );
        NetworkList.getWakeOnWlanSupport(this.controller, this.wakeOnWlanSupportHandler.bind(this), this.wakeOnWlanSupportHandler.bind(this));
    },
	
    configChanged: function(event)
    {
       NetworkList.setWakeOnWlanSupport(this.controller, this.configModel.value, this.wakeOnWlanSupportHandler.bind(this), this.wakeOnWlanSupportHandler.bind(this)); 
    },

    wakeOnWlanSupportHandler: function(response)
    {
        Mojo.Log.info("wakeOnWlanSupportHandler " + Object.toJSON(response));

        var wakeOnWlanSupportEnabled = 'disabled';

        if (response.returnValue && response.wakeOnWlanSupport){
            wakeOnWlanSupportEnabled = 'enabled';
        }

        if (wakeOnWlanSupportEnabled != this.configModel.value){
            this.configModel.value = wakeOnWlanSupportEnabled;
            this.controller.modelChanged(this.configModel);
        }

        if (wakeOnWlanSupportEnabled == 'enabled'){
            this.controller.get('wowOffText').hide();
            this.controller.get('wowOnText').show();
        }
        else {
            this.controller.get('wowOffText').show();
            this.controller.get('wowOnText').hide();
        }
    },
});
