1import{r as l}from"./rolldown-runtime-b3L32Ng1.js";import{et as u,tt as f}from"./vendor-react-39KtS5Vb.js";import{t as c}from"./module.esm-FJM1oHJF.js";import{n as m,t as g}from"./timezone-CLPoR1SU.js";import{a as v,i as p,n as y,o as b,r as S,t as E}from"./fr-B8bsP9p4.js";import{a as C,i as w,o as I,s as L}from"./vendor-fullcalendar-DmC2Zd20.js";var n=l(f(),1),P=l(u(),1),F=l(m(),1),A=l(g(),1),$=b(),O=v(),B=p(),U=S(),j=y(),H=E(),i=(function(t){return t.LIST="list",t.CALENDAR="calendar",t})({}),_=class{constructor(t,e){this.url=t,this.articleStore=e}async fetchFullCalendarEvents(t){const e=this.getDynamicallyPricedArticlesFromStore(),r=JSON.stringify(e.map(a=>({id:a.id,quantity:a.quantity})));this.url.searchParams.set("articles",r),this.url.searchParams.set("start",t.start.toISOString()),this.url.searchParams.set("end",t.end.toISOString());const s=await fetch(this.url);if(s.ok)return await s.json();throw new Error(`Could not fetch calendar data (response status ${s.status} )`)}getDynamicallyPricedArticlesFromStore(){const t=Object.keys(this.articleStore.items),e=[];return t.forEach(r=>{this.articleStore.items[r].reslingEventId?.length!==0&&this.articleStore.items[r].dynamicallyPriced==="1"&&parseInt(this.articleStore.items[r].quantity,10)>0&&e.push(this.articleStore.items[r])}),e}},T=class{constructor(t,e){this.requestPath=t,this.articleStore=e,this.requestPath.endsWith("/")&&(this.requestPath=this.requestPath.slice(0,-1))}async fetchFullCalendarEvents(t){const e=this.getReslingArticlesFromStore(),r=e[0].reslingEventId??"",s=e.reduce((d,h)=>d+parseInt(h.quantity,10),0),a=new URL(`${this.requestPath}/${r}/${s}`,document.URL);a.searchParams.set("start",t.start.toISOString()),a.searchParams.set("end",t.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 t=Object.keys(this.articleStore.items),e=[];return t.forEach(r=>{this.articleStore.items[r].reslingEventId?.length!==0&&this.articleStore.items[r].dynamicallyPriced?.length===0&&e.push(this.articleStore.items[r])}),e}},M=()=>({$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.noEventsContent=t.noEventsContent,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 _(new URL(this.baseUrl,document.URL),this.articleStore),e="fullcalendar.dynamic_prices.fetch"):(this.getEventsForMonthView=()=>this.fullCalendarStore.getEvents(),this.eventFetcher=new T(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",r=>{this.keyDownHandler(r)},!1)},keyDownHandler(t){if(!this.listViewOpen)return;const{target:e}=t,r=this.getTabbableButtonsInListView(),s=t.shiftKey?r[0]:r[r.length-1];t.key.toLowerCase()==="tab"&&e===s&&(t.preventDefault(),this.focusButton(t.shiftKey?"last":"first"))},selectReslingEvent(t){const e=this.fullCalendarStore.getEvents().map(r=>{let s;return r.extendedProps.selected=t.start===r.start&&t.end===r.end,this.isDynamicPricing&&this.showMethod===i.CALENDAR?s=t.start.substring(0,10)===r.start.substring(0,10)&&t.end.substring(0,10)===r.end.substring(0,10):s=r.extendedProps.selected,r.classNames=s?["fc-event-selected"]:["fc-event-unselected"],r});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 r=null;switch(t){case"first":r=e[0];break;case"second":r=e[1];break;case"last":r=e[e.length-1];break}r instanceof HTMLElement&&r.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 L(this.calendarRoot,{locales:I,locale:this.locale,plugins:[C,w],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 r={start:t.start,end:t.end};r.end<new Date||(this.isTimeRangeLoaded(r)?e(this.getEventsForMonthView()):(this.fullCalendarStore.setEventsLoading(!0),this.fetchFullCalendarEvents(r).then(()=>{e(this.getEventsForMonthView())}).catch(s=>{console.log(s)}).finally(()=>
1{this.loadedTimeRanges.push(r),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(r=>r.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=`${(0,n.default)(t.event.start).format("HH:mm")} − ${(0,n.default)(t.event.end).format("HH:mm")}`,r=`<span class="list-event-title">${t.event.title}</span> <span class="list-event-timespan">${e}</span>`;return{html:`<a href="${t.event.url}">${r}</a>`}},noEventsContent:this.noEventsContent}}),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,r){if(typeof t>"u")return"";n.default.locale(this.locale),n.default.extend(P.default),n.default.extend(F.default),n.default.extend(A.default),n.default.tz.setDefault("Europe/Berlin");const s=n.default.tz(t,"Europe/Berlin").format(e);return typeof r=="string"?`${s} ${r}`:s},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(r=>{this.articleStore.items[r].reslingEventId?.length!==0&&this.articleStore.items[r].dynamicallyPriced==="1"&&e.push(this.articleStore.items[r])}),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 r=(0,n.default)(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-${r}`,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{M as fullCalendarService};
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.