"use strict";define(["app","Controller","../Views/SignInMultiView","../Models/SignInMultiModel","../../PA/Controllers/PAController","webapps/FirstAccess/CommonControls/Localization/Views/SelectLanguageView","utils"],function(g,h,f,a,c,e,b){var d=h.extend({title:b.localize(this,["FirstAccess.title"]),initialize:function(i){h.prototype.initialize.apply(this,arguments);_.extend(this,i);this.signInMultiModel=new a();this.signInMultiView=new f();this.paController=new c();},refreshView:function(){this.view=this.signInMultiView.render(this.data);this.view.$el.show();this.selectLanguageView=new e({parentView:this});this.selectLanguageView.render(g.instance().Cache.LanguageSettings.Languages,g.instance().Cache.LanguageSettings.CurrentLanguage,b.getLanguageName);this.view.$el.find("#selectLanguage").html(this.selectLanguageView.$el);},index:function(i){var l=g.instance().Cache.profileId;var j=this.signInMultiModel.toJSON();_.extend(j,g.instance().Cache);this.data=j;this.refreshView();this.view.$el.hide();this.trigger("controller:attach",this.view);if(g.instance().Cache.paEnabled&&!g.instance().Cache.paVisted&&g.instance().Cache.appts){g.instance().Cache.paVisted=true;var k="?mode=kiosk";this.paController.launch({parent:this.view,src:g.instance().Cache.paURL+k,profileId:l});}else{this.view.$el.show();}this.listenTo(this.view,"view:submit",function(p){g.instance().showSpinner();var m=g.instance().Cache.apptsWithClException;var o={};if(_.contains(m,p)){o=_.extend(o,{attributes:{clException:true,apptId:p}});g.instance().router.navigate("/FirstAccess/fail",o);}else{var n=j;o=_.extend(o,{trigger:true,attributes:{clException:false,apptId:p}});n.appts=[_.filter(n.appts,function(q){return q.ApptId===p;})[0]];if(n.appts[0].TooEarly===true){$.ajax({url:"/FirstAccess/ValidateSignIn",data:{apptId:n.appts[0].ApptId,profileId:l},success:_.bind(function(r){g.instance().hideSpinner();var q=JSON.parse(r);if(q.TooEarly===true){g.instance().router.navigate("/FirstAccess/fail",o);}else{g.instance().router.navigate("/FirstAccess/signin",o);}},this),error:function(){g.instance().hideSpinner();g.instance().router.navigate("/FirstAccess/error");}});}else{g.instance().router.navigate("/FirstAccess/signin",o);}}});}});return d;});