"use strict";define(["app","Controller","../Views/SuccessView","../Models/SuccessModel","../../AdminSettings/Models/PatientOrientationModel","../../Report/Controllers/ReportController","../../PatientOrientation/Controllers/PatientOrientationController","webapps/FirstAccess/CommonControls/Localization/Views/SelectLanguageView","utils"],function(b,f,g,a,d,e,j,h,i){var c=f.extend({title:i.localize(this,["FirstAccess.title"]),timeoutSeconds:null,login:b.instance().router.root+"FirstAccess",intervalId:0,initialize:function(k){f.prototype.initialize.apply(this,arguments);_.extend(this,k);this.successModel=new a();this.successView=new g();this.reportController=new e();this.patientOrientationModel=new d();b.instance().sessionTimeout.disabled=false;},refreshView:function(){this.data.CustomMessage=this.checkCurrLang();this.view=this.successView.render(this.data);this.view.$el.find("#successPage").show();this.selectLanguageView=new h({parentView:this});this.selectLanguageView.render(b.instance().Cache.LanguageSettings.Languages,b.instance().Cache.LanguageSettings.CurrentLanguage,i.getLanguageName);this.view.$el.find("#selectLanguage").html(this.selectLanguageView.$el);},checkCurrLang:function(){var m=b.instance().Cache.profileSettingsModel;var n=b.instance().Cache.LanguageSettings.CurrentLanguage;var l=null;var k=_.find(m.CustomMessages,function(o){return o.LangCd===n&&o.MessageType===0;});if(k){l=k.CustomMessageText;}return l;},timeout:function(){this.view.$el.find("#successPage").show();if(b.instance().Cache.setPatientStatus===true){var k=b.instance().Cache.patientStatus;this.setPatientStatus(k);}b.instance().sessionTimeout.disabled=true;var m=this.timeoutSeconds;if(m===0){this.view.$el.hide();window.location=this.login;}else{var l=this;this.intervalId=window.setInterval(function(){m-=1;$("#tick").toggle();if(m<=0){window.clearInterval(l.intervalId);window.location=l.login;}},1000);}},index:function(m){var q={};var o=b.instance().Cache.profileSettingsModel;var n=this.checkCurrLang();var l=b.instance().router.routeAttributes();var k=l?l.OrderId:"";var p=b.instance().Cache&&b.instance().Cache.appts?_.filter(b.instance().Cache.appts,function(r){return r.ApptId===l.apptId;})[0]:null;_.extend(q,p,{orderId:k,CustomMessage:(n)?n:""});this.timeoutSeconds=(o&&o.CustomMessageSeconds>=0)?o.CustomMessageSeconds:60;this.data=q;this.refreshView();this.trigger("controller:attach",this.view);this.listenTo(this.view,"view:quit",_.bind(function(){window.clearInterval(this.intervalId);},this));if(p&&(o.DisplayCustomReport||o.PrintCustomReport)){this.view.$el.css("visibility","hidden");b.instance().showSpinner();$.ajax("/FirstAccess/PrintSignIn",{data:{__RequestVerificationToken:$("[name=__RequestVerificationToken]").val(),appt:p.ApptId,order:k,profileId:o.Profile},type:"POST",dataType:"html"}).done(_.bind(function(t,r,s){this.displayReport(o,t);},this)).fail(function(t,r,s){b.instance().router.navigate("/FirstAccess/error");}).always(function(){b.instance().hideSpinner();});}else{this.timeout();}},setPatientStatus:function(k){if(k&&k.length>0){$.ajax("/FirstAccess/SetPatientStatus",{type:"POST",data:{__RequestVerificationToken:$("[name=__RequestVerificationToken]").val(),status:k}});}},displayMessages:function(n,m,l,o){var k=new j();k.launch({parent:this.view,record:null,messages:n});this.listenToOnce(k.view,"view:close",function(){k.close();if(m===true){this.displayReport(l,o);}else{this.timeout();}});},displayReport:function(m,n){var l=n.indexOf("wrapper-error")>=0;if(l){var k=$("<div/>").html(n);k.find(".error-orange").html(i.localize(this,["error.somethingWrong"]));n=k.html();}this.reportController.launch({parent:this.view,report:n,display:m.DisplayCustomReport,print:m.PrintCustomReport,error:l});this.listenTo(this.reportController.view,"view:close",this.timeout);}});return c;});