(function(){"use strict";u8.Crm.Widgets.CalendarLegend=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.CalendarLegend.defaults,t));$assert(this.colorType,"The required property 'colorType' has not been set.");this._create()};u8.Crm.Widgets.CalendarLegend.makeClass({name:"CalendarLegend",deriveFrom:u8.Base.Widgets.Widget,events:["Create"]});u8.Crm.Widgets.CalendarLegend.defaults={theme:{css:{root:"u8-calendarlegend",header:"u8-calendarlegend-header",label:"u8-calendarlegend-label",colorType:"u8-calendarlegend-colortype",legendItems:"u8-calendarlegend-legenditems",legendItem:"u8-calendarlegend-legenditem",calendarItem:"u8-calendarlegend-calendaritem"}},colorTypesId:"calendar"};$.extend(u8.Crm.Widgets.CalendarLegend.prototype,{_create:function(){this._isCreated=false;Function.chain(Function.chain.onDisposedAbort,Function.join(this._using,u8.tools.ready.curry(u8.services.collaboration.calendar)),this._createModel.async(),this._createView).call(this,u8.tools.createdWhenReady.curry(this))},_using:function(e){u8.using({templates:[{name:"u8-calendar-legend",url:"~/crm/CalendarLegend.utml.htm"}]},e)},_createModel:function(){this._viewModel={colorTypeName:this.colorType.text,legendItems:this._createLegendItems(),css:this.theme.css}},_createLegendItems:function(){var e=this.colorType.key;var t=this.colorTypesId;return u8.services.collaboration.calendar.getColorCalendarItems(e,t,this.infoAreaIds).map(function(n){var a=u8.Crm.Widgets.CalendarItemView.getClassNames(n,e,t);return{text:n.caption,cssClass:a}})},_createView:function(e){this.$(this.element).utml({name:"u8-calendar-legend",itemOptions:{parent:this},data:this._viewModel},e)}});u8.Crm.Widgets.CalendarLegend.openInPopup=function(e,t){if(!e){e={}}var n=$.extend({title:$t("TXT_net_calendar_16"),sizing:"fit",position:"center-top",modal:true,autoClose:true},e.popupOptions);var a=e.widgetOptions||{};if(e.colorTypeKey){var r=e.widgetOptions&&e.widgetOptions.colorTypesId;var d=u8.services.collaboration.calendar.getColorTypesModel(r);a.colorType=d.find(u8._.eq("key",e.colorTypeKey))}u8.Base.Widgets.Popup.openWidgetPopup({type:"CalendarLegend",popupOptions:n,widgetOptions:a},t)}})();