"use strict";define(["app","handlebars","View","text!/v2/webapps/FirstAccess/AdminSettings/BlockedClinicPopup/Templates/BlockedClinicPopupTemplate.html","utils"],function(d,f,e,a,b){var c=e.extend({id:"blockedClinicPopup",overlay:null,origClinicExceptions:null,clinics:null,blockedClIds:null,blockedClinicPopupTemplate:f.compile(a),events:{"click .excpSave-btn":"Save","click .excpCancel-btn":"Cancel","click .confirmSave-btn":"SaveConfirmed","click .confirmCancel-btn":"CancelConfirmed"},Save:function(j){j.preventDefault();var i=[];this.blockedClIds=[];_.each(this.$el.find(".toggle-input"),_.bind(function(m){var l=$(m).prop("checked");var n=[];if(this.origClinicExceptions){n=$.grep(this.origClinicExceptions,function(o){return o.ClinicId.toString()===$(m).data("clinicid").toString();});}if(!l&&n.length){var k=$.grep(this.clinics,function(o){return o.Id.toString()===$(m).data("clinicid").toString();});if(k.length){i.push(k[0].Description);}}if(l){this.blockedClIds.push($(m).data("clinicid").toString());}},this));if(i.length){var h=i.join(", ");h=$("<div/>").text(h).html();var g=b.localize(this,["adminsetting.removeblockclinicInstruction"])+"<br/><br/>"+h;this.trigger("view:confirm",{header:b.localize(this,["adminsetting.removeblockclinic"]),message:g,action:"save"});}else{this.saveConfirmed();}},saveConfirmed:function(){this.trigger("view:setinfoForsave",{overlay:this.overlay,blockedClIds:this.blockedClIds});this.overlay.close();},Cancel:function(){var j=false;var g=this.$el.find(".toggle-input:checked");if(g.length){if(this.origClinicExceptions){var i=_.pluck(this.origClinicExceptions,"ClinicId");i=_.uniq(i);if(i.length!==g.length){j=true;}else{_.each(g,_.bind(function(k){var l=[];l=$.grep(i,function(m){return m.toString()===$(k).data("clinicid").toString();});if(l.length<=0){j=true;}},this));}}else{j=true;}}else{j=this.origClinicExceptions&&this.origClinicExceptions.length;}if(j){var h=b.localize(this,["adminsetting.cancelblockclinicInstruction"])+"<br/><br/>";this.trigger("view:confirm",{header:b.localize(this,["adminsetting.cancelblockclinic"]),message:h,action:"cancel"});}else{this.overlay.close();}},cancelConfirmed:function(){this.overlay.close();},initialize:function(g){e.prototype.initialize.apply(this,arguments);this.options=g||{};this.overlay=this.options.parent;},render:function(i){e.prototype.render.apply(this,arguments);this.setParent(i.parent);this.origClinicExceptions=i.clinicExceptions;this.clinics=i.clinics;var j=Math.ceil(i.clinics.length/2);var g=i.clinics.slice();var h=g.splice(0,j);_.extend(i,{leftsideclinics:h});_.extend(i,{rightsideclinics:g});this.$el.html(this.blockedClinicPopupTemplate(i));this.overlay.render().$el.find("#overlay").html(this.$el);i.parent.$el.append(this.overlay.$el);this.$el.find(".toggle-input").bootstrapToggle({on:b.localize(this,["adminsetting.block"]),off:b.localize(this,["adminsetting.allow"])});_.each(this.$el.find(".toggle-input"),function(k){var l=[];if(i.clinicExceptions){l=$.grep(i.clinicExceptions,function(m){return m.ClinicId.toString()===$(k).data("clinicid").toString();});}$(k).bootstrapToggle(l.length?"on":"off");});this.delegateEvents();return this;}});return c;});