function CMSPluginCalendar(id,calendarId,dateDefault,eventData,eventListURL,calendarModal){let $this=this;this.create=function(){let options={dateDefault:dateDefault,onChangeMonthYear:function(year,month){if(month.length===1){month="0"+month}dateDefault=year+"-"+month+"-15";let categoriesId=0,calendar=$("."+id);if(calendar){categoriesId=calendar.attr("data-categories-id").trim()}$.ajax({type:"POST",url:URL_CLIENT_REQUEST,data:{PluginName:"calendar",Action:"CHANGE_DATE",CalendarYear:year,CalendarMonth:month,CalendarId:calendarId,csrf_token:getCsrfTokenJs(),Id:id,CategoriesId:categoriesId},success:function(result){$this.changeResponse(JSON.parse(result))},error:ajaxErrorResponse})}};let langCode=getLanguageCode(false);$("."+id).datepicker(options).datepicker("option",$.datepicker.regional[langCode]);$this.bindEventData();$("."+id+" table thead tr th").addClass("notranslate");$("#modal-"+id).on("hidden.bs.modal",function(){let $this=$(this);$this.find(".modal-body").html("")})};this.changeDate=function(date){$("."+id).datepicker("setDate",date)};this.changeResponse=function(data){id=data.id;eventData=data.eventData;calendarId=data.calendarId;this.bindEventData()};this.bindEventData=function(){let cell=$("."+id+" table tbody tr td");cell.addClass("ui-datepicker-unselectable ui-state-disabled");cell.children("a").removeClass("ui-datepicker-date-event");cell.tooltip({tooltipClass:"ui-tooltip-dark",show:false,hide:false});cell.each(function(){let link=$(this).children("a");if(link.length===1){let index=parseInt(link.text());if(typeof eventData[index]!="undefined"){link.parent("td").removeClass("ui-state-disabled");link.addClass("ui-datepicker-date-event ui-state-hover");let title=link.attr("title");if(typeof title==="undefined")title="";if(jQuery.trim(title)!=="")title+="\n";link.attr("title",title+eventData[index].eventName);$(this).bind("click",{day:index},function(event){let date=dateDefault.split("-");let month=date[1];if(1*date[1]<10){date[1]="0"+date[1]}if(date[1].length===3){date[1]=month}event.data.day=parseInt(event.data.day);if(event.data.day<10){event.data.day="0"+event.data.day}if(calendarModal){dateDefault=date[0]+"-"+date[1]+"-"+event.data.day;$.ajax({type:"POST",url:URL_CLIENT_REQUEST,data:{PluginName:"calendar",Action:"EVENT_LIST",Date:dateDefault,CalendarId:calendarId,csrf_token:getCsrfTokenJs(),Id:id},success:function(result){const parsedResult=JSON.parse(result);const dayEvents=parsedResult["modalData"];let html="";$.each(dayEvents,function(index,dayEventData){let imgUrl=dayEventData.page_image_url;html+='
';if(!!dayEventData.page_url){let linkTitle=dayEventData.name.replace('"',"");html+='

'+''+dayEventData.name+""+"

"}else{html+='

'+dayEventData.name+"

"}html+='
'+dayEventData.date_formatted+"
";if(!!dayEventData.description){html+='

'+dayEventData.description+"

"}if(imgUrl==="0")imgUrl=0;if(!!imgUrl){let imgName=imgUrl.substring(imgUrl.lastIndexOf("/")+1,imgUrl.length);html+='
'+imgName+'
'}html+="
"});let modal=$("#modal-"+id);modal.find(".modal-body").html('
'+html+"
");modal.find(".modal-calendar-date").html(event.data.day+"-"+date[1]+"-"+date[0]);modal.modal("show")},error:ajaxErrorResponse})}else{if(eventData[index].eventLink!==""){window.location.href=eventData[index].eventLink}else{window.location.href=eventListURL+"?Date="+date[0]+"-"+date[1]+"-"+event.data.day+"&CalendarId="+calendarId}}})}else{let span=$("");span.attr("class","ui-state-default").html(link.html());$(this).html(span)}}});$("."+id+" table thead th").addClass("notranslate")}}