1import{m as c}from"./module.esm-CCyjftVT.js";import{d as n,a5 as u}from"./vendor-react-B6KoJ4Um.js";import{d as f,a as m}from"./timezone-Db1JuaCx.js";import"./fr-DSCL0Jw0.js";import{C as g,i as v,a as y,l as p}from"./vendor-fullcalendar-DYshs5sN.js";import"./vendor-bootstrap-4PcyVVVI.js";var i=(t=>(t.LIST="list",t.CALENDAR="calendar",t))(i||{});class S{constructor(e,s){this.url=e,this.articleStore=s}async fetchFullCalendarEvents(e){const s=this.getDynamicallyPricedArticlesFromStore(),r=JSON.stringify(s.map(a=>({id:a.id,quantity:a.quantity})));this.url.searchParams.set("articles",r),this.url.searchParams.set("start",e.start.toISOString()),this.url.searchParams.set("end",e.end.toISOString());const l=await fetch(this.url);if(l.ok)return await l.json();throw new Error(`Could not fetch calendar data (response status ${l.status} )`)}getDynamicallyPricedArticlesFromStore(){const e=Object.keys(this.articleStore.items),s=[];return e.forEach(r=>{this.articleStore.items[r].reslingEventId?.length!==0&&this.articleStore.items[r].dynamicallyPriced==="1"&&parseInt(this.articleStore.items[r].quantity,10)>0&&s.push(this.articleStore.items[r])}),s}}class b{constructor(e,s){this.requestPath=e,this.articleStore=s,this.requestPath.endsWith("/")&&(this.requestPath=this.requestPath.slice(0,-1))}async fetchFullCalendarEvents(e){const s=this.getReslingArticlesFromStore(),r=s[0].reslingEventId??"",l=s.reduce((d,h)=>d+parseInt(h.quantity,10),0),a=new URL(`${this.requestPath}/${r}/${l}`,document.URL);a.searchParams.set("start",e.start.toISOString()),a.searchParams.set("end",e.end.toISOString());const o=await fetch(a);if(o.ok)return await o.json();throw new Error(`Could not fetch calendar data (response status ${o.status} )`)}getReslingArticlesFromStore(){const e=Object.keys(this.articleStore.items),s=[];return e.forEach(r=>{this.articleStore.items[r].reslingEventId?.length!==0&&this.articleStore.items[r].dynamicallyPriced?.length===0&&s.push(this.articleStore.items[r])}),s}}const A=()=>({$nextTick:null,articleStore:c.store("cartArticleContents"),baseUrl:"/",calendarInstance:null,calendarRoot:document.getElementById("fullcalendar-root"),currentConsecutiveLoads:0,eventFetcher:null,eventsForListView:[],fullCalendarStore:c.store("fullCalendarStore"),getEventsForMonthView:()=>[],isDynamicPricing:!1,listViewOpen:!1,loadedTimeRanges:[],locale:"de",maxConsecutiveLoads:6,showMethod:null,initHandler(t){if(this.locale=t.locale.substring(0,2),this.showMethod=t.showMethod,this.buildCalendarInstance(),this.calendarInstance===null)throw new Error("Calendar could not be instantiated");this.baseUrl=t.baseUrl.substring(0,t.baseUrl.indexOf("%")),this.isDynamicPricing=this.getDynamicallyPricedArticlesFromStore().length>0;let e="";this.isDynamicPricing?(this.getEventsForMonthView=()=>this.showMethod===i.CALENDAR?this.fullCalendarStore.getEventsWithDailyLowestPrice():this.fullCalendarStore.getEvents(),this.eventFetcher=new S(new URL(this.baseUrl,document.URL),this.articleStore),e="fullcalendar.dynamic_prices.fetch"):(this.getEventsForMonthView=()=>this.fullCalendarStore.getEvents(),this.eventFetcher=new b(this.baseUrl,this.articleStore),e="fullcalendar.resling.fetch"),window.addEventListener(e,(()=>{this.fullCalendarStore.setEvents([]),this.loadedTimeRanges=[],this.calendarInstance?.removeAllEvents(),this.calendarInstance?.refetchEvents()})),document.addEventListener("keydown",s=>{this.keyDownHandler(s)},!1)},keyDownHandler(t){if(!this.listViewOpen)return;const{target:e}=t,s=this.getTabbableButtonsInListView(),r=t.shiftKey?s[0]:s[s.length-1];t.key.toLowerCase()==="tab"&&e===r&&(t.preventDefault(),this.focusButton(t.shiftKey?"last":"first"))},selectReslingEvent(t){const e=this.fullCalendarStore.getEvents().map(s=>{let r;return s.extendedProps.selected=t.start===s.start&&t.end===s.end,this.isDynamicPricing&&this.showMethod===i.CALENDAR?r=t.start.substring(0,10)===s.start.substring(0,10)&&t.end.substring(0,10)===s.end.substring(0,10):r=s.extendedProps.selected,s.classNames=r?["fc-event-selected"]:["fc-event-unselected"],s});this.fullCalendarStore.setEvents(e),this.articleStore.dynamicPriceTotal=t.extendedProps.price,this.calendarInstance?.refetchEvents(),this.$nextTick(()=>{document.getElementById("addToCart")?.focus()})},focusButton(t){const e=this.getTabbableButtonsInListView();if(e&&e.length>0){let s=null;switch(t){case"first":s=e[0];break;case"second":s=e[1];break;case"last":s=e[e.length-1];break}s instanceof HTMLElement&&s.focus()}},getSelectedReslingEvent(){const t=this.fullCalendarStore.getEvents().find(e=>e.extendedProps.selected);return typeof t!="object"&&(this.articleStore.dynamicPriceTotal=0),t},getDynamicPriceTotal(){const t=this.getSelectedReslingEvent();return typeof t=="object"?t?.extendedProps.price:0},buildCalendarInstance(){if(this.calendarRoot===null)throw new Error("Required `#fullcalendar-root` DOM element not found");this.calendarInstance=new g(this.calendarRoot,{locales:p,locale:this.locale,plugins:[v,y],themeSystem:"standard",contentHeight:"auto",firstDay:1,displayEventTime:!1,initialView:this.showMethod===i.LIST?"listYear":"dayGridMonth",headerToolbar:this.showMethod===i.LIST?{left:"prevYear",center:"title",right:"nextYear"}:{left:"prev",center:"title,today",right:"next"},titleFormat:{month:"short",year:"numeric"},buttonText:{today:"Reset"},events:c.debounce((t,e)=>{if(!this.articleStore.haveSellableArticlesPositiveQuantity())return;const s={start:t.start,end:t.end};s.end<new Date||(this.isTimeRangeLoaded(s)?e(this.getEventsForMonthView()):(this.fullCalendarStore.setEventsLoading(!0),this.fetchFullCalendarEvents(s).then(()=>{e(this.getEventsForMonthView())}).catch(r=>{console.log(r)}).finally(()=>
1{this.loadedTimeRanges.push(s),this.fullCalendarStore.setEventsLoading(!1)})))},300),eventClick:t=>{if(t.jsEvent.preventDefault(),this.showMethod===i.CALENDAR&&this.openListView(t.event),this.showMethod===i.LIST){const e=this.fullCalendarStore.getEvents().find(s=>s.id===t.event.id);this.selectReslingEvent(e)}},eventContent:function(t){return{...t,html:`<div class="fc-event-title fc-sticky">${t.event.title}</div>`}},...this.showMethod===i.LIST&&{eventContent:t=>{const e=`${n(t.event.start).format("HH:mm")} − ${n(t.event.end).format("HH:mm")}`,s=`<span class="list-event-title">${t.event.title}</span> <span class="list-event-timespan">${e}</span>`;return{html:`<a href="${t.event.url}">${s}</a>`}}}}),this.calendarInstance.render()},async fetchFullCalendarEvents(t){await this.eventFetcher?.fetchFullCalendarEvents(t).then(e=>{if(e.length===0&&this.fullCalendarStore.getEvents().length===0){if(this.currentConsecutiveLoads<this.maxConsecutiveLoads){this.currentConsecutiveLoads++,this.calendarInstance?.next();return}this.currentConsecutiveLoads=0,this.calendarInstance?.today();return}this.fullCalendarStore.addEvents(this.parseEventModelsIntoFullCalendarEvents(e))}).catch(e=>{console.error(e)})},openListView(t){this.listViewOpen=!0,this.eventsForListView=this.fullCalendarStore.getByDate(t.start?.toISOString().substring(0,10))},getFormattedDate(t,e,s){if(typeof t>"u")return"";n.locale(this.locale),n.extend(u),n.extend(f),n.extend(m),n.tz.setDefault("Europe/Berlin");const r=n.tz(t,"Europe/Berlin").format(e);return typeof s=="string"?`${r} ${s}`:r},getCurrentlyAvailable(t){return t==null?null:t.extendedProps.currentlyAvailable},getTotalAvailable(t){return t==null?null:t.extendedProps.totalAvailable},getDynamicallyPricedArticlesFromStore(){const t=Object.keys(this.articleStore.items),e=[];return t.forEach(s=>{this.articleStore.items[s].reslingEventId?.length!==0&&this.articleStore.items[s].dynamicallyPriced==="1"&&e.push(this.articleStore.items[s])}),e},isTimeRangeLoaded(t){return this.loadedTimeRanges.some(e=>e.start.getTime()===t.start.getTime()&&e.end.getTime()===t.end.getTime())},parseEventModelsIntoFullCalendarEvents(t){return t.map(e=>{const s=n(e.start).unix();return{start:e.start,end:e.end,title:e.title,id:e.id,borderColor:e.backgroundColor,backgroundColor:e.backgroundColor,textColor:e.textColor,display:"block",url:`#id-${s}`,extendedProps:{selected:!1,price:e.price,totalAvailable:e.totalAvailable,currentlyAvailable:e.currentlyAvailable}}})},getTabbableButtonsInListView(){const t=document.getElementById("listView");return!t||!this.listViewOpen?[]:Array.from(t.getElementsByClassName("tabbable-button"))}});export{A as f};
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.