1class w{constructor(e){this.ctrl=e,this.rangePickers=[],this.popupShowMonths=2}get inline(){return this.ctrl.inline}get popup(){return this.ctrl.popup}get form(){return this.ctrl.form}init(){typeof window.flatpickr=="function"&&(this.inline&&(this.inline.querySelectorAll("[data-cpl-datepicker]").forEach(e=>{const t=window.flatpickr(e,{dateFormat:"Y-m-d",altInput:!0,altInputClass:"cpl-ctrl__input",altFormat:"d/m/Y",locale:window.globals.current_locale});this.setupCalendarA11y(t,e,!1);const l=e.parentElement.querySelector("[data-cpl-datepicker-clear-single]");l&&l.addEventListener("click",()=>{t.clear(),e.dispatchEvent(new Event("change",{bubbles:!0}))})}),this.inline.querySelectorAll("[data-cpl-datepicker-range]").forEach(e=>{this.setupRangePicker(e,this.inline,"data-cpl-mirror",!1)})),this.popup&&(this.popupShowMonths=this.getPopupShowMonths(),this.popup.querySelectorAll("[data-cpl-datepicker]").forEach(e=>{const t=window.flatpickr(e,{dateFormat:"Y-m-d",inline:!0,showMonths:this.popupShowMonths,locale:window.globals.current_locale});this.setupCalendarA11y(t,e,!0)}),this.popup.querySelectorAll("[data-cpl-datepicker-range]").forEach(e=>{this.setupRangePicker(e,this.form,"data-cpl-field",!0)}),window.addEventListener("resize",()=>{const e=this.getPopupShowMonths();e!==this.popupShowMonths&&(this.popupShowMonths=e,this.popup.querySelectorAll("[data-cpl-datepicker], [data-cpl-datepicker-range]").forEach(t=>{t._flatpickr&&t._flatpickr.set("showMonths",e)}))})))}getPopupShowMonths(){return window.matchMedia("(max-width: 639px)").matches?1:2}setupRangePicker(e,t,l,a){const r=t.querySelector("["+l+'="'+e.getAttribute("data-cpl-datepicker-range-from")+'"]'),n=t.querySelector("["+l+'="'+e.getAttribute("data-cpl-datepicker-range-to")+'"]'),p=[r&&r.value,n&&n.value].filter(Boolean),h=(o,s)=>{const[c,u]=o.map(f=>s.formatDate(f,"Y-m-d"));r&&(r.value=c||"",r.dispatchEvent(new Event("change",{bubbles:!0}))),n&&(n.value=u||"",n.dispatchEvent(new Event("change",{bubbles:!0}))),this.syncRangePickers(s,c,u)},i=window.flatpickr(e,{mode:"range",inline:a,showMonths:a?this.popupShowMonths:1,dateFormat:"Y-m-d",defaultDate:p.length?p:void 0,locale:window.globals.current_locale,[a?"onChange":"onClose"]:(o,s,c)=>h(o,c)});this.rangePickers.push(i),this.setupCalendarA11y(i,e,a);const d=e.parentElement.querySelector("[data-cpl-datepicker-clear]");d&&d.addEventListener("click",()=>{i.clear(),h([],i)})}setupCalendarA11y(e,t,l){const a=e&&e.calendarContainer;if(!a||(a.classList.add("cpl-flatpickr"),!l))return;a.setAttribute("tabindex","0");const r=t.parentElement.querySelector(".cpl-ctrl__label"),n=r&&r.textContent.trim()||t.getAttribute("placeholder")||"";n&&a.setAttribute("aria-label",n)}syncRangePickers(e,t,l){const a=[t,l].filter(Boolean);this.rangePickers.forEach(r=>{r!==e&&r.setDate(a,!1)})}clear(){this.rangePickers.forEach(e=>e.clear())}}export{w as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.