"use strict";define(["app","Controller","../Views/FailView","../Models/FailModel","webapps/FirstAccess/CommonControls/Localization/Views/SelectLanguageView","utils"],function(e,f,g,b,d,a){var c=f.extend({title:a.localize(this,["FirstAccess.title"]),timeoutSeconds:null,login:e.instance().router.root+"FirstAccess",initialize:function(h){f.prototype.initialize.apply(this,arguments);_.extend(this,h);this.failModel=new b();this.failView=new g();e.instance().sessionTimeout.disabled=false;},refreshView:function(){this.data.ChartLockMessage=this.GetChartLockCurLang();this.view=this.failView.render(this.data,this.allowExitOptions);this.selectLanguageView=new d({parentView:this});this.selectLanguageView.render(e.instance().Cache.LanguageSettings.Languages,e.instance().Cache.LanguageSettings.CurrentLanguage,a.getLanguageName);this.view.$el.find("#selectLanguage").html(this.selectLanguageView.$el);},GetChartLockCurLang:function(){var j=e.instance().Cache.profileSettingsModel;var k=e.instance().Cache.LanguageSettings.CurrentLanguage;var i=null;var h=_.find(j.CustomMessages,function(l){return l.LangCd===k&&l.MessageType===1;});if(h){i=h.CustomMessageText;}return i;},timeout:function(){e.instance().sessionTimeout.disabled=true;var i=this.timeoutSeconds;if(i===0){this.view.$el.hide();window.location=this.login;}else{var h=this;this.intervalId=window.setInterval(function(){i-=1;$("#tick").toggle();if(i<=0){window.clearInterval(h.intervalId);window.location=h.login;}},1000);}},index:function(h){this.failModel.fetch({data:{profileId:e.instance().Cache.profileId},success:_.bind(function(t){var o={};var r=e.instance().router.routeAttributes();var m=r?r.apptId:"";var p=r?r.mustExit?r.mustExit:false:false;var q=r?r.clException?r.clException:false:false;var j=r?r.chartLockException?r.chartLockException:false:false;var i=_.filter(e.instance().Cache.appts,function(u){return u.ApptId===m;})[0];o.clinicException=q;o.chartLockException=j;_.extend(o,i,t.toJSON());var n=e.instance().Cache.appts;var k=[];if((n&&n.length>1)){k=$.grep(n,function(u){return !u.TooEarly;});}var s=!p&&(k&&k.length>0);if(o.chartLockException){var l=e.instance().Cache.profileSettingsModel;this.timeoutSeconds=(l&&l.ChartLockMessageSeconds>=0)?l.ChartLockMessageSeconds:60;}this.data=o;this.allowExitOptions=s;this.refreshView();this.trigger("controller:attach",this.view);this.listenTo(this.view,"view:quit",_.bind(function(){window.clearInterval(this.intervalId);},this));if(o.chartLockException){this.timeout();}},this),error:function(){e.instance().router.navigate("/FirstAccess/error");}});}});return c;});