window.tec=window.tec||{},tec.addEventToSeries=tec.addEventToSeries||{},function(e,t){"use strict";t.selectors={seriesToEventsSelect:"#_tec_relationship_series_to_events",resultTemplate:"#tec-events-pro-series__result-template",resultLabelTitle:".tec-events-pro-series__result-label-title",resultLabelCountEvents:".tec-events-pro-series__result-label-count-events",resultLabelStatus:".tec-events-pro-series__result-label-status",resultDate:".tec-events-pro-series__result-date",selection:".select2-selection__choice",selectionRemove:".select2-selection__choice__remove",selectionTemplate:"#tec-events-pro-series__selection-template",selectionTitle:".tec-events-pro-series__selection-title",selectionTitleText:".tec-events-pro-series__selection-title-text",selectionCountEvents:".tec-events-pro-series__selection-count-events",selectionsLabel:".tec-events-pro-series__selections-label",selectionsList:".tec-events-pro-series__selections-list",searchField:".select2-search__field"},t.classes={hidden:"hidden"},t.el={$instance:null},t.formatResultTemplate=function(s){if(!s.element)return s.text;if(s.selected)return;const n=e(t.selectors.resultTemplate).text(),l=e(n);l.find(t.selectors.resultLabelTitle).text(s.text);const c=l.find(t.selectors.resultLabelCountEvents),o=l.find(t.selectors.resultDate);"1"===s.element.dataset.recurring?(c.text(s.element.dataset.recurrenceCount),o.text(s.element.dataset.recurrenceFirstStartDate+" - "+s.element.dataset.recurrenceLastEndDate)):(l.find("svg").remove(),c.remove(),o.text(s.element.dataset.startDate));const i=l.find(t.selectors.resultLabelStatus);return e.inArray(s.element.dataset.status,["draft","pending"])>=0?i.text("– "+s.element.dataset.statusLabel):i.remove(),l},t.formatSelectionTemplate=function(s){if(!s.element)return s.text;const n=e(t.selectors.selectionTemplate).text(),l=e(n);l.find(t.selectors.selectionTitle).text(s.text);const c=l.find(t.selectors.selectionCountEvents);return"1"===s.element.dataset.recurring?(c.text(s.element.dataset.recurrenceCount),s.title=s.element.dataset.recurrenceFirstStartDate+" - "+s.element.dataset.recurrenceLastStartDate):(l.find("svg").remove(),c.remove(),s.title=s.element.dataset.startDate),l},t.moveSelections=function(){const s=t.el.$instance.parent(),n=s.find(t.selectors.selectionsList);n.empty();const l=s.find(t.selectors.selection);l.each((function(s,l){const c=e(l).addClass(t.classes.hidden);c.clone().appendTo(n).find(t.selectors.selectionRemove).on("click",(function(){c.find(t.selectors.selectionRemove).trigger("click")}))}));const c=s.find(t.selectors.selectionsLabel);l.length?c.removeClass(t.classes.hidden):c.addClass(t.classes.hidden)},t.setPlaceholder=function(){const e=t.el.$instance.data("placeholder");t.el.$instance.next().find(t.selectors.searchField).attr("placeholder",e)},t.handleSelect=function(){t.moveSelections(),t.setPlaceholder(),t.el.$instance.select2TEC("close")},t.handleUnselect=function(){t.moveSelections(),t.setPlaceholder()},t.handleUnselecting=function(){t.el.$instance.data("unselecting.tecEventsPro",!0)},t.handleOpening=function(e){t.el.$instance.data("unselecting.tecEventsPro")&&(t.el.$instance.removeData("unselecting.tecEventsPro"),e.preventDefault())},t.bindEvents=function(){t.el.$instance.on("select2:select",t.handleSelect).on("select2:unselect",t.handleUnselect).on("select2:unselecting",t.handleUnselecting).on("select2:opening",t.handleOpening)},t.setupDropdown=function(){const e=t.el.$instance.data("dropdown");e.closeOnSelect=!0,e.templateResult=t.formatResultTemplate,e.templateSelection=t.formatSelectionTemplate,t.el.$instance.data("dropdown",e),t.el.$instance.select2TEC(e)},t.ready=function(){t.el.$instance=e(t.selectors.seriesToEventsSelect),t.el.$instance.length&&(t.setupDropdown(),t.bindEvents(),t.moveSelections(),t.setPlaceholder())},e(t.ready)}(jQuery,tec.addEventToSeries),window.tec=window.tec||{},window.tec.eventsPro=window.tec.eventsPro||{},window.tec.eventsPro.customTablesV1=window.tec.eventsPro.customTablesV1||{},window.tec.eventsPro.customTablesV1.classicEditorAddEventToSeries={};