(function(){"use strict";var e=250;u8.Crm.VisitPlanningSidebarModel=function(e){$assert(e instanceof u8.Crm.VisitPlanningModel,"No correct model set.");this._bindings=[];this._create(e)};$.extend(u8.Crm.VisitPlanningSidebarModel.prototype,{dispose:function(){if(this._isDisposed){return}this.unbind();u8.tools.dispose(this._baseModel);u8.tools.dispose(this._bindings);this._isDisposed=true},get:function(e){return this._baseModel.get(e)},set:function(e,t){this._baseModel.set(e,t);return this},execute:function(e,t){var s=this._visitPlanningModel;if(s[e]){return s[e].apply(s,Array.prototype.slice.call(arguments,1))}return undefined},setAsyncStatus:function(e){var t=this._baseModel.get("asyncStatus");if((t&&t.status)==(e&&e.status)){return}this._baseModel.set("asyncStatus",e)},_create:function(t){var s=this,n={customerFilterSet:false,rep:false,date:true,repId:false,selection:false,defaultSuggestionStart:false,defaultSuggestionDuration:false,visits:{converter:{to:u8._.id}},isBusy:true},i;this._visitPlanningModel=t;i=this._baseModel=u8.create("Model",{onPropertyChange:function(e,t){s.raise("PropertyChange",t)}});for(var r in n){var a=n[r];if(typeof a=="boolean"){a={targetToSource:a}}var o=u8.create("Binding",$.extend({source:t,sourcePath:"@"+r,target:i,targetPath:"#"+r,isDynamic:true,sourceToTarget:true,targetToSource:false},a));o.init();this._bindings.push(o)}var u=function(e){i.set("selectedUid",e)}.despam(e);var d=function(e){i.set("accountUid",e)}.despam(e*3);var c=function(e){i.set("relatedUid",e)}.despam(e*5);t.bind("SelectionChange",function(e){var t=e.getSelection("uid");var s=e.getSelection("accountUid");var n=s;if(u8.equalsRecordUid(s,t)){s=null}i.set("selectedUid",null);i.set("accountUid",null);i.set("relatedUid",null);if(t){u(t)}else{u.cancel()}if(s){d(s)}else{d.cancel()}if(n){c(n)}else{c.cancel()}});i.property("suggestions",{dependsOn:["visits"],compute:function(e){return(e||[]).filter(function(e){return e&&u8.isValidRecordUid(e.uid)&&!u8.isValidRecordUid(e.contactUid)&&!e.isVirtualOrigin})}});i.property("hasSelection",{dependsOn:["selectedUid"],compute:function(e){return!!e}});i.property("asyncInProgress",{dependsOn:["asyncStatus"],compute:function(e){return e&&(e.status=="progress"||e.status=="started")?true:false}});i.property("asyncText",{dependsOn:["asyncStatus"],compute:function(e){return e&&e.text||""}});i.property("isBusy",{dependsOn:["asyncInProgress"]});i.property("hasSuggestions",{dependsOn:["suggestions"],compute:function(e){return!!(e&&e.length)}});i.property("suggestionParameters",{dependsOn:["suggestions"],compute:function(e){if(!e){return{}}var t="",s="",n="";if(e.length){t=e.map(u8._.attr("startDate")).min();s=e.map(u8._.attr("endDate")).max();var i=u8.session.webConfigValues.get("VisitPlanning.SuggestionsDateFormat");if(typeof i!=="undefined"){n=u8.services.typeConverter.formatDate(t,i);if(!t.toDate().equals(s.toDate())){n+=" - "+u8.services.typeConverter.formatDate(s,i)}}else{n=u8.Base.DateRange(t,s).toDateString({monthName:"short-name"})}t=u8.services.typeConverter.dateToString(t);s=u8.services.typeConverter.dateToString(s)}return{count:e.length,startDate:t,endDate:s,dateRange:n}}});i.property("showNoSuggestions",{dependsOn:["hasSuggestions","asyncInProgress"],compute:function(e,t){return!e&&!t}});i.property("showSuggestions",{dependsOn:["hasSuggestions","asyncInProgress"],compute:function(e,t){return e&&!t}})}});u8.Crm.VisitPlanningSidebarModel.makeClass({name:"VisitPlanningSidebarModel",events:["PropertyChange"]})})();