/* Copyright 2009 Palm, Inc.  All rights reserved. */

var FirstuseWithAcctsAssistant = Class.create({
	
		appMenuModel: { visible:true, 
						label:$L('Calendar'), 
						items: [ Mojo.Menu.editItem,
								{label:$L('Preferences'), command:Mojo.Menu.prefsCmd, disabled: true},
								{label:$L('Help'), command:Mojo.Menu.helpCmd, disabled:false}]
					   },
	
	calendarAcctsUpdated: function() {
		this.acctsModel.items = getFirstUseManager().getCalendarAccts();
		this.controller.modelChanged(this.acctsModel);
	},
	
	setup: function() {
		getFirstUseManager().observeCalendarAccts("firstuse_with_accts", this);
		this.acctsModel.items = getFirstUseManager().getCalendarAccts();
		this.controller.setupWidget('fwa_accts_list', this.acctsAttrs, this.acctsModel);
		this.controller.setupWidget(Mojo.Menu.appMenu, {omitDefaultItems:true}, this.appMenuModel);
	},
	
	activate: function() {
		this.yesBtnTapHandler = this.goToFirstUseAcctTypePicker.bindAsEventListener(this);
		this.controller.get('fwa_yes_btn').observe(Mojo.Event.tap, this.yesBtnTapHandler);
		this.noBtnTapHandler = this.goToDayView.bindAsEventListener(this);
		this.controller.get('fwa_no_btn').observe(Mojo.Event.tap, this.noBtnTapHandler);
	},
	
	deactivate: function() {
		this.controller.get('fwa_yes_btn').stopObserving(Mojo.Event.tap, this.yesBtnTapHandler);
		this.controller.get('fwa_no_btn').stopObserving(Mojo.Event.tap, this.noBtnTapHandler);
	},
	handleCommand:function(event){
		if(event.command == Mojo.Menu.helpCmd){
				getAppManagerService().launchHelp(this.controller);
			}
	},
	// *** EVENT HANDLERS ***
	
	goToFirstUseAcctTypePicker: function(event) {
		this.controller.stageController.pushScene("choosetransport", "firstuse-with-accts");
	},
	
	goToDayView: function(event) {
		// The user is done setting up for first use... 
		getFirstUseManager().stopObservingCalendarAccts("firstuse_with_accts");
		finishedFirstUse();
		// Go to the Day View
		var sController = this.controller.stageController;
		sController.popScene();
		sController.pushScene('day');
	},
	
	// *** LIST ATTRS & MODELS ***
	acctsAttrs : {
		itemTemplate: 'firstuse-with-accts/firstuse-acct',
	},
	
	acctsModel : {
		items: [],
	},
});