@ilamy/calendar
Version:
A full-featured React calendar component library built with Shadcn-Ui, Tailwind CSS, and TypeScript.
4 lines • 614 kB
JavaScript
import{RRule as gU}from"rrule";import{AnimatePresence as N4,motion as V4}from"motion/react";import{clsx as L4}from"clsx";import{twMerge as A4}from"tailwind-merge";import Y0 from"dayjs";import Z4 from"dayjs/plugin/isBetween.js";import X4 from"dayjs/plugin/isSameOrAfter.js";import J4 from"dayjs/plugin/isSameOrBefore.js";import Q4 from"dayjs/plugin/localeData.js";import Y4 from"dayjs/plugin/localizedFormat.js";import q4 from"dayjs/plugin/minMax.js";import U4 from"dayjs/plugin/timezone.js";import z4 from"dayjs/plugin/utc.js";import _4 from"dayjs/plugin/weekday.js";import K4 from"dayjs/plugin/weekOfYear.js";var P5,G4=(P,$,Z)=>{let X=$.prototype,J=Z.tz.setDefault;Z.tz.setDefault=(_)=>{return P5=_,J(_)};let{startOf:Y,endOf:Q}=X;function q(_,z){let G=_.$x?.$timezone||P5;if(!G)return z;let K=Z.tz(z.format("YYYY-MM-DDTHH:mm:ss"),G).utcOffset();if(z.utcOffset()!==K)return z.tz(G,!0);return z}X.startOf=function(_,z){let G=Y.call(this,_,z);return q(this,G)},X.endOf=Q};Y0.extend(_4);Y0.extend(K4);Y0.extend(X4);Y0.extend(J4);Y0.extend(Z4);Y0.extend(q4);Y0.extend(U4);Y0.extend(z4);Y0.extend(Q4);Y0.extend(Y4);Y0.extend(G4);var $5=(...P)=>{return Y0.tz(...P)};Object.assign($5,Y0);var T=$5;var h0=1,Z5=24,F0=24,ZP=4,X5="bg-secondary text-muted-foreground pointer-events-none",E0={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function A(...P){return A4(L4(P))}var kP=(P)=>{if(!P||P.length===0)return;return new Set(P.map(($)=>E0[$]))};function XP(P){if(P===void 0)return;if(T.isDayjs(P))return P;let $=T(P);return $.isValid()?$:void 0}var J5=(P,$)=>{let Z={...P};for(let X of $)delete Z[X];return Z};function mP(P){if(!P||!P.length)return[];return P.map(($)=>{return{...$,start:T.isDayjs($.start)?$.start:T($.start),end:T.isDayjs($.end)?$.end:T($.end)}})}import{jsx as Q5}from"react/jsx-runtime";var W4={hidden:({direction:P})=>({opacity:0,x:P==="horizontal"?10:0,y:P==="vertical"?-10:0}),visible:({delay:P})=>({opacity:1,x:0,y:0,transition:{duration:0.2,ease:[0.4,0,0.2,1],delay:P}}),exit:({direction:P})=>({opacity:0,x:P==="horizontal"?-10:0,y:P==="vertical"?-10:0,transition:{duration:0.15}})},D=({children:P,transitionKey:$,delay:Z=0,className:X,direction:J="vertical",layout:Y,layoutId:Q,"data-testid":q,ref:_,...z})=>Q5(N4,{mode:"wait",children:Q5(V4.div,{animate:"visible",className:A("inline-block w-full",X),custom:{delay:Z,direction:J},"data-testid":q,exit:"exit",initial:"hidden",layout:Y,layoutId:Q,ref:_,variants:W4,...z,children:P},$)});D.displayName="AnimatedSection";import{DndContext as j4,MouseSensor as x4,pointerWithin as v4,TouchSensor as y4,useSensor as B5,useSensors as c4}from"@dnd-kit/core";import{useRef as O5,useState as i4}from"react";import{Slot as F4}from"@radix-ui/react-slot";import{cva as M4}from"class-variance-authority";import{jsx as O4}from"react/jsx-runtime";var B4=M4("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function g({className:P,variant:$,size:Z,asChild:X=!1,...J}){return O4(X?F4:"button",{className:A(B4({variant:$,size:Z,className:P})),"data-slot":"button",...J})}import*as $0 from"@radix-ui/react-dialog";import{XIcon as f4}from"lucide-react";import{jsx as M0,jsxs as V2}from"react/jsx-runtime";function JP({...P}){return M0($0.Root,{"data-slot":"dialog",...P})}function I4({...P}){return M0($0.Portal,{"data-slot":"dialog-portal",...P})}function R4({className:P,...$}){return M0($0.Overlay,{className:A("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",P),"data-slot":"dialog-overlay",...$})}function QP({className:P,children:$,...Z}){return V2(I4,{"data-slot":"dialog-portal",children:[M0(R4,{}),V2($0.Content,{className:A("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg max-h-[90%]",P),"data-slot":"dialog-content",...Z,children:[$,V2($0.Close,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[M0(f4,{}),M0("span",{className:"sr-only",children:"Close"})]})]})]})}function YP({className:P,...$}){return M0("div",{className:A("flex flex-col gap-2 text-center sm:text-left",P),"data-slot":"dialog-header",...$})}function gP({className:P,...$}){return M0("div",{className:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",P),"data-slot":"dialog-footer",...$})}function qP({className:P,...$}){return M0($0.Title,{className:A("text-lg leading-none font-semibold",P),"data-slot":"dialog-title",...$})}function CP({className:P,...$}){return M0($0.Description,{className:A("text-muted-foreground text-sm",P),"data-slot":"dialog-description",...$})}import{useContext as V5}from"react";import{createContext as S4}from"react";var hP=S4(void 0);import{createContext as p4}from"react";var EP=p4(void 0);import{useCallback as a0,useMemo as w4}from"react";import{useCallback as t,useEffect as M2,useMemo as L5,useRef as B2,useState as n0}from"react";import{RRule as T4}from"rrule";var DP=(P)=>{return new Date(Date.UTC(P.year(),P.month(),P.date(),P.hour(),P.minute(),P.second(),P.millisecond()))},H4=(P,$)=>{return $.year(P.getUTCFullYear()).month(P.getUTCMonth()).date(P.getUTCDate()).hour(P.getUTCHours()).minute(P.getUTCMinutes()).second(P.getUTCSeconds()).millisecond(P.getUTCMilliseconds())},UP=(P)=>{return Boolean(P.rrule||P.recurrenceId||P.uid)},D0=(P)=>{return P.uid||`${P.id}@ilamy.calendar`},q5=(P,$)=>{let Z=D0($),X=P.findIndex((J)=>D0(J)===Z&&J.rrule&&!J.recurrenceId);if(X===-1)throw Error("Base recurring event not found");return X},U5=(P)=>P.start.subtract(1,"day").endOf("day").toDate(),Y5=(P,$)=>{let Z=$.diff($.startOf("day"),"millisecond");return P.startOf("day").add(Z,"millisecond")},b4=(P,$)=>{let Z=P.start;if($.start)Z=Y5(P.start,$.start);let X=P.end;if($.start&&$.end)X=Z.add($.end.diff($.start),"millisecond");else if($.start)X=Z.add(P.end.diff(P.start),"millisecond");else if($.end)X=Y5(P.end,$.end);let J=$.rrule??P.rrule,Y;if(J)Y={...J,dtstart:Z.toDate()};return{start:Z,end:X,rrule:Y}},W2=({event:P,currentEvents:$,startDate:Z,endDate:X})=>{if(!P.rrule)return[];try{let J=DP(P.start),Y=P.rrule.until?DP(T(P.rrule.until)):void 0,Q={...P.rrule,dtstart:J,until:Y},q=new T4(Q),_=D0(P),z=$.filter((f)=>f.recurrenceId&&D0(f)===_),G=P.end.diff(P.start),K=DP(Z.subtract(G,"millisecond")),V=DP(X);return q.between(K,V,!0).map((f,F)=>{let U=H4(f,P.start),L=z.find((k)=>XP(k.recurrenceId)?.isSame(U));if(L)return{...P,...L};let W=P.end.diff(P.start),I=U.add(W,"millisecond"),R=`${P.id}_${F}`,S=D0(P);return{...P,id:R,start:U,end:I,uid:S,rrule:void 0}}).filter((f)=>{if(P.exdates&&P.exdates.length>0){let L=f.start.toISOString();if(P.exdates?.includes(L))return!1}return f.start.isSameOrBefore(X)&&f.end.isSameOrAfter(Z)})}catch(J){throw Error(`Invalid RRULE options: ${JSON.stringify(P.rrule)}. Error: ${J instanceof Error?J.message:"Unknown error"}`)}},z5=({targetEvent:P,updates:$,currentEvents:Z,scope:X})=>{let J=[...Z],Y=q5(J,P),Q=J[Y];switch(X){case"this":{let q=P.start.toISOString(),z=[...Q.exdates||[],q],G={...Q,exdates:z};J[Y]=G;let K=`${P.id}_modified_${Date.now()}`,V={...J5(P,["width","height","top","left","right"]),...$,id:K,recurrenceId:q,uid:D0(Q),rrule:void 0};J.push(V);break}case"following":{let q=U5(P),_={...Q,rrule:{...Q.rrule,until:q}};J[Y]=_;let z=Q.end.diff(Q.start),G=$.start||P.start,K=$.end||G.add(z),V=`${Q.id}_following`,M=`${V}@ilamy.calendar`,N={...Q,...$,rrule:{...Q.rrule,...$.rrule,dtstart:G.toDate()},id:V,uid:M,start:G,end:K,recurrenceId:void 0};J.push(N);break}case"all":{let q=b4(Q,$);J[Y]={...Q,...$,start:q.start,end:q.end,rrule:q.rrule};break}default:throw Error(`Invalid scope: ${X}. Must be 'this', 'following', or 'all'`)}return J},_5=({targetEvent:P,currentEvents:$,scope:Z})=>{let X=[...$],J=q5(X,P),Y=X[J];switch(Z){case"this":{let Q=P.start.toISOString(),_=[...Y.exdates||[],Q],z={...Y,exdates:_};X[J]=z;break}case"following":{let Q={...Y,rrule:{...Y.rrule,until:U5(P)}};X[J]=Q;break}case"all":{let Q=D0(P);return X.filter((_)=>D0(_)!==Q)}default:throw Error(`Invalid scope: ${Z}. Must be 'this', 'following', or 'all'`)}return X};var F2={today:"Today",create:"Create",new:"New",update:"Update",delete:"Delete",cancel:"Cancel",export:"Export",event:"Event",events:"Events",newEvent:"New Event",title:"Title",description:"Description",location:"Location",allDay:"All day",startDate:"Start Date",endDate:"End Date",startTime:"Start Time",searchTime:"Search time...",endTime:"End Time",color:"Color",createEvent:"Create Event",editEvent:"Edit Event",addNewEvent:"Add a new event to your calendar",editEventDetails:"Edit your event details",eventTitlePlaceholder:"Event title",eventDescriptionPlaceholder:"Event description (optional)",eventLocationPlaceholder:"Event location (optional)",repeat:"Repeat",repeats:"Repeats",customRecurrence:"Custom recurrence",daily:"Daily",weekly:"Weekly",monthly:"Monthly",yearly:"Yearly",interval:"Interval",repeatOn:"Repeat on",never:"Never",count:"Count",every:"Every",ends:"Ends",after:"After",occurrences:"occurrences",on:"On",editRecurringEvent:"Edit recurring event",deleteRecurringEvent:"Delete recurring event",editRecurringEventQuestion:"is a recurring event. How would you like to edit it?",deleteRecurringEventQuestion:"is a recurring event. How would you like to delete it?",thisEvent:"This event",thisEventDescription:"Only change this specific occurrence",thisAndFollowingEvents:"This and following events",thisAndFollowingEventsDescription:"Edit this and all future occurrences",allEvents:"All events",allEventsDescription:"Edit the entire recurring series",onlyChangeThis:"Only change this specific occurrence",changeThisAndFuture:"Change this and all future occurrences",changeEntireSeries:"Change the entire recurring series",onlyDeleteThis:"Only delete this specific occurrence",deleteThisAndFuture:"Delete this and all future occurrences",deleteEntireSeries:"Delete the entire recurring series",month:"Month",week:"Week",day:"Day",year:"Year",more:"more",resources:"Resources",resource:"Resource",time:"Time",date:"Date",noResourcesVisible:"No resources visible",addResourcesOrShowExisting:"Add resources or show existing ones"};function u(P){return P.isSame(T(),"day")}function n(P){return P.format("YYYY-MM-DD")}function r(P,$){let Z=P.startOf("week").day($),X=P.isBefore(Z)?Z.subtract(1,"week"):Z;return Array.from({length:7},(J,Y)=>X.add(Y,"day"))}function zP(P,$){let Z=r(P.startOf("month"),$);return Array.from({length:6},(X,J)=>{let Y=Z[0].add(J,"week");return r(Y,$)})}function K5(P){let $=P.daysInMonth(),Z=P.startOf("month");return Array.from({length:$},(X,J)=>Z.add(J,"day"))}function G5({referenceDate:P=T(),length:$=24}={}){let Z=P.startOf("day");return Array.from({length:$},(X,J)=>Z.hour(J).minute(0).second(0).millisecond(0))}function _P(P,$){let Z=new Set($.map((X)=>String(X.id)));return P.filter((X)=>Z.has(String(X.id)))}function jP(P,$,Z){let X=P.start.isSameOrAfter($)&&P.start.isSameOrBefore(Z),J=P.end.isSameOrAfter($)&&P.end.isSameOrBefore(Z),Y=P.start.isBefore($)&&P.end.isAfter(Z);return X||J||Y}var A5={day:"day",week:"week",month:"month",year:"year"},O2=(P,$,Z)=>{if($==="day"||$==="year")return{start:P.startOf($),end:P.endOf($)};if($==="week"){let J=r(P,Z);return{start:J[0].startOf("day"),end:J[6].endOf("day")}}let X=zP(P,Z);return{start:X[0][0].startOf("day"),end:X[5][6].endOf("day")}},xP=(P)=>{let{events:$=[],firstDayOfWeek:Z=0,initialView:X="month",initialDate:J=T(),businessHours:Y,onEventAdd:Q,onEventUpdate:q,onEventDelete:_,onDateChange:z,onViewChange:G,locale:K,timezone:V,translations:M,translator:N}=P,[f,F]=n0(T.isDayjs(J)?J:T(J)),[U,L]=n0(X),[W,I]=n0($),[R,S]=n0(!1),[w,k]=n0(null),[h,j]=n0(null),[c,e]=n0(K||"en"),E=B2($),m=B2(V),i=B2(void 0),_0=L5(()=>{if(N)return N;let p=M||F2;return(b)=>p[b]||b},[M,N]),G0=t((p,b)=>{let l=[];for(let b0 of W)if(b0.rrule)l.push(...W2({event:b0,currentEvents:W,startDate:p,endDate:b}));else if(jP(b0,p,b))l.push(b0);return l},[W]),W0=t(()=>{return O2(f,U,Z)},[f,U,Z]),S0=L5(()=>{let{start:p,end:b}=W0();return G0(p,b)},[G0,W0]);M2(()=>{if($!==E.current)I($),E.current=$},[$]),M2(()=>{if(K&&K!==i.current)e(K),T.locale(K),F((p)=>p.locale(K)),i.current=K},[K]),M2(()=>{if(V&&V!==m.current)T.tz.setDefault(V),F((p)=>p.tz(V)),I((p)=>p.map((b)=>({...b,start:b.start.tz(V),end:b.end.tz(V)}))),m.current=V},[V]);let J0=t((p)=>{F(p);let b=O2(p,U,Z);z?.(p,b)},[z,U,Z]),L0=J0,d=t((p)=>{let b=p===1?f.add(1,A5[U]):f.subtract(1,A5[U]);J0(b)},[f,U,J0]),p0=t(()=>d(1),[d]),T0=t(()=>d(-1),[d]),H0=t(()=>J0(T()),[J0]),y=t((p)=>{I((b)=>[...b,p]),Q?.(p)},[Q]),X0=t((p,b)=>{let l=W.find((N2)=>N2.id===p);if(!l)return;let b0={...l,...b};I((N2)=>N2.map((e2)=>e2.id===p?b0:e2)),q?.(b0)},[W,q]),e0=t((p,b,l)=>{q?.({...p,...b}),I(z5({targetEvent:p,updates:b,currentEvents:W,scope:l.scope}))},[W,q]),PP=t((p,b)=>{_?.(p),I(_5({targetEvent:p,currentEvents:W,scope:b.scope}))},[W,_]),H=t((p)=>{let b=W.find((l)=>l.id===p);if(!b)return;I((l)=>l.filter((b0)=>b0.id!==p)),_?.(b)},[W,_]),P0=t((p)=>{if(p?.start)j(p.start);let b=p?.start??f;k({title:_0("newEvent"),start:b,end:p?.end??b.add(1,"hour"),resourceId:p?.resourceId,description:"",allDay:p?.allDay??!1}),S(!0)},[f,_0]),Q0=t(()=>{j(null),k(null),S(!1)},[]),A0=t((p)=>{L(p),G?.(p);let b=O2(f,p,Z);z?.(f,b)},[G,z,f,Z]),$P=t((p)=>{let b=p.uid;return W.find((l)=>(l.uid||`${l.id}@ilamy.calendar`)===b&&l.rrule)||null},[W]);return{currentDate:f,view:U,events:S0,rawEvents:W,isEventFormOpen:R,selectedEvent:w,selectedDate:h,firstDayOfWeek:Z,dayMaxEvents:ZP,currentLocale:c,businessHours:Y,setCurrentDate:F,selectDate:L0,setView:A0,nextPeriod:p0,prevPeriod:T0,today:H0,addEvent:y,updateEvent:X0,updateRecurringEvent:e0,deleteEvent:H,deleteRecurringEvent:PP,openEventForm:P0,closeEventForm:Q0,setSelectedEvent:k,setIsEventFormOpen:S,setSelectedDate:j,getEventsForDateRange:G0,findParentRecurringEvent:$P,t:_0}};import{jsx as k4}from"react/jsx-runtime";var f2=(P)=>{if(P.resourceIds)return P.resourceIds;if(P.resourceId!==void 0)return[P.resourceId];return[]},N5=({children:P,events:$=[],resources:Z=[],firstDayOfWeek:X=0,initialView:J="month",initialDate:Y,renderEvent:Q,onEventClick:q,onCellClick:_,onViewChange:z,onEventAdd:G,onEventUpdate:K,onEventDelete:V,onDateChange:M,locale:N,timezone:f,disableCellClick:F,disableEventClick:U,disableDragAndDrop:L,dayMaxEvents:W,eventSpacing:I=1,eventHeight:R=F0,stickyViewHeader:S=!0,viewHeaderClassName:w="",headerComponent:k,headerClassName:h,translations:j,translator:c,renderResource:e,renderEventForm:E,businessHours:m,timeFormat:i="12-hour",classesOverride:_0,orientation:G0="horizontal",renderCurrentTimeIndicator:W0,renderHour:S0,hideNonBusinessHours:J0=!1,hideExportButton:L0=!1,hiddenDays:d,weekViewGranularity:p0="hourly",slotDuration:T0=60,scrollTime:H0})=>{let y=xP({events:$,firstDayOfWeek:X,initialView:J,initialDate:Y,businessHours:m,onEventAdd:G,onEventUpdate:K,onEventDelete:V,onDateChange:M,onViewChange:z,locale:N,timezone:f,translations:j,translator:c}),X0=a0((p)=>y.events.filter((b)=>f2(b).includes(p)),[y.events]),e0=a0((p)=>y.events.filter((b)=>f2(b).some((l)=>p.includes(l))),[y.events]),PP=a0((p)=>{return Z.find((b)=>b.id===p)},[Z]),H=a0((p)=>{return Boolean(p.resourceIds&&p.resourceIds.length>1)},[]),P0=a0((p)=>{y.setSelectedEvent(p),y.setIsEventFormOpen(!0)},[y]),Q0=a0((p)=>{if(U)return;if(q)q(p);else P0(p)},[U,q,P0]),A0=a0((p)=>{if(F)return;if(_)_(p);else{let b={title:y.t("newEvent"),start:p.start,end:p.end,description:"",allDay:!1};if(p.resourceId!==void 0)b.resourceId=p.resourceId;y.setSelectedEvent(b),y.setSelectedDate(p.start),y.setIsEventFormOpen(!0)}},[_,F,y]),$P=w4(()=>({...y,resources:Z,getEventsForResource:X0,getEventsForResources:e0,getResourceById:PP,isEventCrossResource:H,getEventResourceIds:f2,onEventClick:Q0,onCellClick:A0,renderEvent:Q,renderResource:e,renderEventForm:E,headerComponent:k,headerClassName:h,locale:N,timezone:f,disableCellClick:F,disableEventClick:U,disableDragAndDrop:L,dayMaxEvents:W,eventSpacing:I,eventHeight:R,stickyViewHeader:S,viewHeaderClassName:w,businessHours:m,timeFormat:i,classesOverride:_0,orientation:G0,renderCurrentTimeIndicator:W0,renderHour:S0,hideNonBusinessHours:J0,hideExportButton:L0,hiddenDays:d,weekViewGranularity:p0,slotDuration:T0,scrollTime:H0}),[y,Z,X0,e0,PP,H,Q0,A0,Q,e,E,N,f,F,U,L,W,I,R,S,w,k,h,m,i,_0,G0,W0,S0,J0,L0,d,p0,T0,H0]);return k4(EP.Provider,{value:$P,children:P})};function O(P){let $=V5(EP),Z=V5(hP),X=$||Z;if(!X)throw Error("useSmartCalendarContext must be used within a CalendarProvider or ResourceCalendarProvider");return P?P(X):X}function m4(){let P=O();return{currentDate:P.currentDate,view:P.view,events:P.events,isEventFormOpen:P.isEventFormOpen,selectedEvent:P.selectedEvent,selectedDate:P.selectedDate,firstDayOfWeek:P.firstDayOfWeek,resources:P.resources||[],setCurrentDate:P.setCurrentDate,selectDate:P.selectDate,setView:P.setView,nextPeriod:P.nextPeriod,prevPeriod:P.prevPeriod,today:P.today,addEvent:P.addEvent,updateEvent:P.updateEvent,deleteEvent:P.deleteEvent,openEventForm:P.openEventForm,closeEventForm:P.closeEventForm,getEventsForResource:P.getEventsForResource,businessHours:P.businessHours}}import{jsx as j0,jsxs as vP}from"react/jsx-runtime";var g4=[{scope:"this",title:"thisEvent",editKey:"onlyChangeThis",deleteKey:"onlyDeleteThis"},{scope:"following",title:"thisAndFollowingEvents",editKey:"changeThisAndFuture",deleteKey:"deleteThisAndFuture"},{scope:"all",title:"allEvents",editKey:"changeEntireSeries",deleteKey:"deleteEntireSeries"}];function fP({isOpen:P,onClose:$,onConfirm:Z,operationType:X,eventTitle:J}){let{t:Y}=O((_)=>({t:_.t})),Q=(_)=>{Z(_),$()},q=X==="edit";return j0(JP,{onOpenChange:$,open:P,children:vP(QP,{className:"max-w-md",children:[vP(YP,{children:[j0(qP,{children:q?Y("editRecurringEvent"):Y("deleteRecurringEvent")}),vP(CP,{children:['"',J,'"'," ",q?Y("editRecurringEventQuestion"):Y("deleteRecurringEventQuestion")]})]}),j0("div",{className:"space-y-3",children:g4.map(({scope:_,title:z,editKey:G,deleteKey:K})=>j0(g,{className:"w-full justify-start h-auto p-4",onClick:()=>Q(_),variant:"outline",children:vP("div",{className:"text-left",children:[j0("div",{className:"font-medium",children:Y(z)}),j0("div",{className:"text-sm text-muted-foreground",children:Y(q?G:K)})]})},_))}),j0(gP,{children:j0(g,{onClick:$,variant:"outline",children:Y("cancel")})})]})})}var W5=(P,$)=>{let{active:Z,over:X}=P;if(!Z||!X||!$)return null;let J=X.data.current||{},Y=J.type==="time-cell",{resourceId:Q,allDay:q}=J,_;if(Y){let{date:V,hour:M=0,minute:N=0}=J;_=T(V).hour(M).minute(N)}else{let{date:V}=J;_=T(V)}let z=$.end.diff($.start,"second"),G=_.add(z,"second");if(G.isSame(G.startOf("day")))G=G.subtract(1,"day").endOf("day");let K={start:_,end:G,resourceId:Q,allDay:Y?!1:q??$.allDay};return{activeEvent:$,updates:K}};import{DragOverlay as C4}from"@dnd-kit/core";import{snapCenterToCursor as h4}from"@dnd-kit/modifiers";import{useImperativeHandle as E4,useState as D4}from"react";import{jsx as F5}from"react/jsx-runtime";var M5=({ref:P})=>{let[$,Z]=D4(null);return E4(P,()=>({setActiveEvent:Z})),F5(C4,{modifiers:[h4],children:$&&F5("div",{className:A("cursor-grab truncate rounded bg-amber-200 p-2 text-[10px] shadow-lg sm:text-xs w-20",$.backgroundColor||"bg-blue-500",$.color||"text-white"),children:$?.title})})};import{jsx as f5,jsxs as I5,Fragment as l4}from"react/jsx-runtime";var I2={isOpen:!1,event:null,updates:null};function yP({children:P}){let $=O5(null),Z=O5(null),{updateEvent:X,updateRecurringEvent:J,disableDragAndDrop:Y}=O((U)=>({updateEvent:U.updateEvent,updateRecurringEvent:U.updateRecurringEvent,disableDragAndDrop:U.disableDragAndDrop})),[Q,q]=i4({isOpen:!1,event:null,updates:null}),_=B5(x4,{activationConstraint:{distance:2}}),z=B5(y4,{activationConstraint:{delay:100,tolerance:5}}),G=c4(_,z),K=(U,L)=>{if(!U?.id||!L||Object.keys(L).length===0)return;if(UP(U))q({isOpen:!0,event:U,updates:L});else X(U.id,L)},V=(U)=>{if(!Q.event||!Q.updates){q(I2);return}try{J(Q.event,Q.updates,{scope:U,eventDate:Q.event.start})}catch{}finally{q(I2)}},M=()=>{q(I2)},N=(U)=>{let{active:L}=U;if(L.data.current?.type==="calendar-event")Z.current?.setActiveEvent(L.data.current.event),$.current=L.data.current.event},f=(U)=>{let L=W5(U,$.current);if(L){let{activeEvent:W,updates:I}=L;K(W,I)}$.current=null,Z.current?.setActiveEvent(null)},F=(U)=>{$.current=null};if(Y)return P;return I5(l4,{children:[I5(j4,{collisionDetection:v4,onDragCancel:F,onDragEnd:f,onDragStart:N,sensors:G,children:[P,f5(M5,{ref:Z})]}),f5(fP,{eventTitle:Q.event?.title||"",isOpen:Q.isOpen,onClose:M,onConfirm:V,operationType:"edit"})]})}import{useEffect as M$,useState as i0}from"react";import*as cP from"@radix-ui/react-checkbox";import{CheckIcon as u4}from"lucide-react";import{jsx as R2}from"react/jsx-runtime";function KP({className:P,...$}){return R2(cP.Root,{className:A("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",P),"data-slot":"checkbox",...$,children:R2(cP.Indicator,{className:"flex items-center justify-center text-current transition-none","data-slot":"checkbox-indicator",children:R2(u4,{className:"size-3.5"})})})}import{PopoverClose as n4}from"@radix-ui/react-popover";import{Calendar as a4}from"lucide-react";import{useEffect as t4,useRef as s4,useState as e4}from"react";import{ChevronLeftIcon as o4,ChevronRightIcon as d4}from"lucide-react";import{useState as r4}from"react";import{jsx as K0,jsxs as S2}from"react/jsx-runtime";function R5({selected:P,defaultMonth:$,onSelect:Z,disabled:X,firstDayOfWeek:J=0,className:Y}){let[Q,q]=r4(()=>T($??P??new Date).startOf("month")),_=zP(Q,J),z=P?T(P).format("YYYY-MM-DD"):void 0,G=r(T(),J).map((K)=>K.format("dd"));return S2("div",{className:A("bg-background p-3 w-[280px]",Y),"data-slot":"calendar",children:[S2("div",{className:"flex items-center justify-between mb-2",children:[K0(g,{"aria-label":"Previous month",onClick:()=>q((K)=>K.subtract(1,"month")),size:"icon",variant:"ghost",children:K0(o4,{className:"size-4"})}),K0("div",{className:"text-sm font-medium select-none",children:Q.format("MMMM YYYY")}),K0(g,{"aria-label":"Next month",onClick:()=>q((K)=>K.add(1,"month")),size:"icon",variant:"ghost",children:K0(d4,{className:"size-4"})})]}),S2("table",{className:"w-full border-collapse",role:"grid",children:[K0("thead",{children:K0("tr",{children:G.map((K,V)=>K0("th",{className:"text-muted-foreground text-xs font-medium select-none py-1",children:K},V))})}),K0("tbody",{children:_.map((K,V)=>K0("tr",{children:K.map((M)=>{let N=!M.isSame(Q,"month"),f=M.format("YYYY-MM-DD")===z,F=X?.(M.toDate())??!1;return K0("td",{className:"p-0 text-center","data-disabled":F,"data-outside":N,"data-selected":f,role:"gridcell",tabIndex:-1,children:K0("button",{"aria-disabled":F,"aria-hidden":N,className:A("w-full aspect-square rounded-md text-sm select-none",!F&&"hover:bg-accent cursor-pointer",N&&"text-muted-foreground/50",u(M)&&!f&&"bg-accent text-accent-foreground",f&&"bg-primary text-primary-foreground font-medium",F&&"opacity-50 cursor-not-allowed"),"data-disabled":F,"data-selected":f,disabled:F||N,onClick:()=>Z?.(M.toDate()),tabIndex:N?-1:0,type:"button",children:M.format("D")})},M.toISOString())})},V))})]})]})}import*as w0 from"@radix-ui/react-popover";import{jsx as iP}from"react/jsx-runtime";function x0({...P}){return iP(w0.Root,{"data-slot":"popover",...P})}function v0({...P}){return iP(w0.Trigger,{"data-slot":"popover-trigger",...P})}function y0({className:P,align:$="center",sideOffset:Z=4,...X}){return iP(w0.Portal,{children:iP(w0.Content,{align:$,className:A("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",P),"data-slot":"popover-content",sideOffset:Z,...X})})}import{jsx as GP,jsxs as p2}from"react/jsx-runtime";function lP({date:P,closeOnSelect:$,onChange:Z,label:X="Pick a date",className:J,disabled:Y}){let Q=O((K)=>K.firstDayOfWeek),q=s4(null),[_,z]=e4(P);t4(()=>{z(P)},[P]);let G=(K)=>{if(z(K),$)q.current?.click();Z?.(K)};return GP("div",{className:J,children:p2(x0,{children:[GP(v0,{asChild:!0,children:p2(g,{className:A("data-[empty=true]:text-muted-foreground w-full justify-start text-left font-normal"),"data-empty":!P,variant:"outline",children:[GP(a4,{}),_?T(_).format("ll"):GP("span",{children:X})]})}),p2(y0,{align:"start",className:"w-auto p-0",children:[GP(n4,{ref:q,style:{display:"none"}}),GP(R5,{defaultMonth:_,disabled:Y,firstDayOfWeek:Q,onSelect:G,selected:_})]})]})})}import{jsx as P$}from"react/jsx-runtime";function t0({className:P,type:$,...Z}){return P$("input",{className:A("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",P),"data-slot":"input",type:$,...Z})}import*as S5 from"@radix-ui/react-label";import{jsx as $$}from"react/jsx-runtime";function q0({className:P,...$}){return $$(S5.Root,{className:A("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",P),"data-slot":"label",...$})}import*as B0 from"@radix-ui/react-scroll-area";import{jsx as IP,jsxs as Z$}from"react/jsx-runtime";function O0({className:P,children:$,viewPortProps:Z,...X}){return Z$(B0.Root,{className:A("relative",P),"data-slot":"scroll-area",...X,children:[IP(B0.Viewport,{...Z,className:A("focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",Z?.className),"data-slot":"scroll-area-viewport",children:$}),IP(k0,{}),IP(B0.Corner,{})]})}function k0({className:P,orientation:$="vertical",...Z}){return IP(B0.ScrollAreaScrollbar,{className:A("flex touch-none p-px transition-colors select-none",$==="vertical"&&"h-full w-2.5 border-l border-l-transparent",$==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",P),"data-slot":"scroll-area-scrollbar",orientation:$,...Z,children:IP(B0.ScrollAreaThumb,{className:"bg-border relative flex-1 rounded-full","data-slot":"scroll-area-thumb"})})}import{Clock as Q$}from"lucide-react";import{useEffect as Y$,useRef as T5,useState as T2}from"react";import{useMemo as X$}from"react";function p5({timeFormat:P="12-hour",minTime:$="00:00",maxTime:Z="23:45"}){return{timeOptions:X$(()=>{let Y=[],[Q,q]=$.split(":").map(Number),[_,z]=Z.split(":").map(Number),G=Q*60+q,K=_*60+z;for(let V=G;V<=K;V+=15){let M=Math.floor(V/60),N=V%60,f=`${M.toString().padStart(2,"0")}:${N.toString().padStart(2,"0")}`;Y.push(f)}return Y},[$,Z]),formatTime:(Y)=>{let[Q,q]=Y.split(":").map(Number),_=Q>=12?"PM":"AM",z=Q===0?12:Q>12?Q-12:Q;if(P==="24-hour")return`${Q.toString().padStart(2,"0")}:${q.toString().padStart(2,"0")}`;return`${z}:${q.toString().padStart(2,"0")} ${_}`}}}var LP=(P)=>String(P).padStart(2,"0"),J$=(P)=>typeof P==="number"?LP(P):P,B={col:{time:"time-col",date:"date-col",day:(P,$)=>{let Z=`day-col-${n(P)}`;return $!=null?`${Z}-resource-${$}`:Z},resource:(P,$)=>`${P}-col-resource-${$}`,allDay:(P,$)=>`all-day-col-${n(P)}-${$}`},cell:{day:(P,$,Z=0)=>{let X=n(P);return $!=null?`day-cell-${X}-${LP($)}-${LP(Z)}`:`day-cell-${X}`},verticalTime:(P)=>`vertical-time-${LP(P)}`,vertical:(P,$,Z,X)=>{let J=`vertical-cell-${n(P)}-${LP($)}-${LP(Z)}`;return X!=null?`${J}-resource-${X}`:J}},container:{vertical:{col:(P)=>`vertical-col-${P}`},horizontal:{row:(P)=>`horizontal-row-${P}`,rowLabel:(P)=>`horizontal-row-label-${P}`,event:(P)=>`horizontal-event-${P}`},eventsLayer:(P,$)=>`${P}-events-${$}`},header:{resource:{weekDay:"resource-week-day-header",timeLabel:(P,$)=>`resource-${P}-time-label-${J$($)}`},weekday:(P,$)=>`${P}-header-weekday-${$.toLowerCase()}`,week:{day:(P)=>`week-header-day-${P.toISOString()}`,hour:(P,$)=>`week-header-hour-${P.toISOString()}-${$}`,resource:(P)=>`week-header-resource-${P}`},year:{month:(P,$)=>$?`year-month-${$}-${P}`:`year-month-${P}`,day:(P,$)=>`year-day-${P}-${$}`}},allDayRow:(P)=>`allday-row-${P??"main"}`,listKey:(...P)=>P.join("-"),dayNumber:(P)=>u(P)?"day-number-today":`day-number-${P.format("D")}`,timePicker:(P)=>`time-picker-${P??""}`,droppable:{dayCell:(P,$)=>{let Z=P.toISOString(),X=$?.allDay?"-allday":"",J=$?.resourceId!=null?`-resource-${$.resourceId}`:"";return`drop-day-cell-${Z}${X}${J}`}}};import{jsx as c0,jsxs as H2}from"react/jsx-runtime";var q$=(P)=>{P.stopPropagation()};function H5({value:P,onChange:$,minTime:Z="00:00",maxTime:X="23:45",timeFormat:J="12-hour",placeholder:Y="Select time...",className:Q,disabled:q=!1,name:_}){let[z,G]=T2(!1),[K,V]=T2(""),M=T5(null),N=T5(null),[f,F]=T2(0),{timeOptions:U,formatTime:L}=p5({timeFormat:J,minTime:Z,maxTime:X}),W=U.filter((S)=>{return L(S).toLowerCase().includes(K.toLowerCase())}),I=(S)=>{$(S),G(!1),V("")};Y$(()=>{if(z){if(N.current)F(N.current.offsetWidth);setTimeout(()=>{M.current?.focus()},0)}},[z]);let R=P?L(P):Y;return H2(x0,{onOpenChange:G,open:z,children:[c0(v0,{asChild:!0,children:H2(g,{"aria-controls":"time-picker-listbox","aria-expanded":z,className:A("w-full justify-start",Q),"data-testid":B.timePicker(_),disabled:q,ref:N,role:"combobox",variant:"outline",children:[c0(Q$,{className:"mr-2 h-4 w-4"}),R]})}),H2(y0,{align:"start",className:"p-0",style:{width:f},children:[c0("div",{className:"p-2 border-b",children:c0(t0,{className:"h-8",onChange:(S)=>V(S.target.value),placeholder:"Search time...",ref:M,value:K})}),c0(O0,{className:"h-[200px]",onWheel:q$,children:c0("div",{className:"p-1",children:W.length===0?c0("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"N/A"}):W.map((S)=>{let w=L(S);return c0("button",{className:A("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground",S===P&&"bg-accent text-accent-foreground"),onClick:()=>I(S),type:"button",children:w},S)})})})]})]})}var b2=(P,$)=>{if(!$)return!0;let Z=!1;return uP($,{date:P,onMatch:()=>{Z=!0}}),Z},b5=({date:P,hour:$,minute:Z=0,businessHours:X})=>{if(!X)return!0;if($===void 0)return b2(P,X);let J=!1,Y=$*60+Z;return uP(X,{date:P,onMatch:(Q)=>{let q=Q.startTime??9,_=Q.endTime??17,z=q*60,G=_*60;if(Y>=z&&Y<G)J=!0}}),J},uP=(P,$)=>{let{date:Z,onMatch:X}=$;if(!P)return;let J=Array.isArray(P)?P:[P];for(let Y of J)if(Z&&Y.daysOfWeek){let Q=Z.day();if(Y.daysOfWeek.some((q)=>E0[q]===Q))X(Y)}else X(Y)},oP=(P)=>{let{allDates:$,businessHours:Z,resourceBusinessHours:X=[],hideNonBusinessHours:J}=P,Y=24,Q=0,q=!1,_=(G)=>{q=!0,Y=Math.min(Y,G.startTime??9),Q=Math.max(Q,G.endTime??17)},z=(G)=>{uP(Z,{date:G,onMatch:_});for(let K of X)uP(K,{date:G,onMatch:_})};for(let G of $)z(G);if(!q&&J){if(z(),!q)Y=9,Q=17,q=!0}return{minStart:Y,maxEnd:Q,hasBusinessHours:q}};var w2=(P,$,Z)=>{let[X,J]=$.split(":").map(Number),Y=T(P).hour(X).minute(J);return Z?Y.hour(0).minute(0):Y},w5=(P,$,Z)=>{let[X,J]=$.split(":").map(Number),Y=T(P).hour(X).minute(J);return Z?Y.hour(23).minute(59):Y},k2=(P,$)=>{if(!$)return{min:"00:00",max:"23:59"};let Z=T(P),{minStart:X,maxEnd:J,hasBusinessHours:Y}=oP({allDates:[Z],businessHours:$,hideNonBusinessHours:!1});if(!Y)return{min:"00:00",max:"23:59"};return{min:`${X.toString().padStart(2,"0")}:00`,max:`${(J-1).toString().padStart(2,"0")}:45`}};import{useEffect as G$,useState as y5}from"react";import{RRule as Z0}from"rrule";import{jsx as dP}from"react/jsx-runtime";function k5({className:P,...$}){return dP("div",{className:A("text-card-foreground flex flex-col gap-6 rounded-xl border shadow-sm",P),"data-slot":"card",...$})}function m5({className:P,...$}){return dP("div",{className:A("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 p-4 pb-0 has-data-[slot=card-action]:grid-cols-[1fr_auto]",P),"data-slot":"card-header",...$})}function g5({className:P,...$}){return dP("div",{className:A("leading-none font-semibold",P),"data-slot":"card-title",...$})}function C5({className:P,...$}){return dP("div",{className:A("p-4 pt-0",P),"data-slot":"card-content",...$})}import*as C from"@radix-ui/react-select";import{CheckIcon as U$,ChevronDownIcon as h5,ChevronUpIcon as z$}from"lucide-react";import{jsx as s,jsxs as m2}from"react/jsx-runtime";function E5({...P}){return s(C.Root,{"data-slot":"select",...P})}function D5({...P}){return s(C.Value,{"data-slot":"select-value",...P})}function j5({className:P,size:$="default",children:Z,...X}){return m2(C.Trigger,{className:A("border-input data-placeholder:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",P),"data-size":$,"data-slot":"select-trigger",...X,children:[Z,s(C.Icon,{asChild:!0,children:s(h5,{className:"size-4 opacity-50"})})]})}function x5({className:P,children:$,position:Z="popper",align:X="center",...J}){return s(C.Portal,{children:m2(C.Content,{align:X,className:A("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-32 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",Z==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",P),"data-slot":"select-content",position:Z,...J,children:[s(_$,{}),s(C.Viewport,{className:A("p-1",Z==="popper"&&"h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width) scroll-my-1"),children:$}),s(K$,{})]})})}function v5({className:P,children:$,...Z}){return m2(C.Item,{className:A("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",P),"data-slot":"select-item",...Z,children:[s("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:s(C.ItemIndicator,{children:s(U$,{className:"size-4"})})}),s(C.ItemText,{children:$})]})}function _$({className:P,...$}){return s(C.ScrollUpButton,{className:A("flex cursor-default items-center justify-center py-1",P),"data-slot":"select-scroll-up-button",...$,children:s(z$,{className:"size-4"})})}function K$({className:P,...$}){return s(C.ScrollDownButton,{className:A("flex cursor-default items-center justify-center py-1",P),"data-slot":"select-scroll-down-button",...$,children:s(h5,{className:"size-4"})})}import{jsx as x,jsxs as U0,Fragment as V$}from"react/jsx-runtime";var C2={DAILY:Z0.DAILY,WEEKLY:Z0.WEEKLY,MONTHLY:Z0.MONTHLY,YEARLY:Z0.YEARLY},L$=Object.fromEntries(Object.entries(C2).map(([P,$])=>[$,P])),g2=[Z0.SU,Z0.MO,Z0.TU,Z0.WE,Z0.TH,Z0.FR,Z0.SA],A$=[{type:"never",id:"never",labelKey:"never"},{type:"count",id:"after",labelKey:"after"},{type:"until",id:"on",labelKey:"on"}],c5=(P)=>Math.max(1,Number.parseInt(P,10)||1),N$=(P,$)=>{if(!P)return $("customRecurrence");try{let Z=new Z0(P).toText();return Z&&!Z.toLowerCase().includes("error")?Z.charAt(0).toUpperCase()+Z.slice(1):$("customRecurrence")}catch{return $("customRecurrence")}},i5=({value:P,onChange:$})=>{let{t:Z,firstDayOfWeek:X}=O((U)=>({t:U.t,firstDayOfWeek:U.firstDayOfWeek})),[J,Y]=y5(!!P),[Q,q]=y5(()=>P||null),_=g2.map((U,L)=>({value:U,label:T().day(L).format("ddd")})),z=g2.map((U,L)=>_[(L+X)%7]);G$(()=>{if(Y(!!P),P)q(P)},[P]);let G=(U)=>{if(!Q)return;let L={...Q,...U};q(L),$(J?L:null)},K=(U)=>{if(Y(U),!U){$(null);return}if(Q){$(Q);return}let L={freq:Z0.DAILY,interval:1};q(L),$(L)},V=(U)=>{let L=Q?.byweekday||[],W=g2[U],I=L.includes(W)?L.filter((R)=>R!==W):[...L,W];G({byweekday:I.length?I:void 0})},M=(U)=>{let L={count:void 0,until:void 0};if(U==="count")L.count=Q?.count||1;if(U==="until")L.until=Q?.until||T().add(1,"month").endOf("day").toDate();G(L)},N=Q?.until?"until":Q?.count?"count":"never",f=L$[Q?.freq??Z0.DAILY]||"DAILY",F=Array.isArray(Q?.byweekday)?Q.byweekday:Q?.byweekday?[Q.byweekday]:[];return U0(k5,{"data-testid":"recurrence-editor",children:[U0(m5,{className:"pb-3",children:[U0("div",{className:"flex items-center space-x-2",children:[x(KP,{checked:J,"data-testid":"toggle-recurrence",id:"recurring",onCheckedChange:K}),x(g5,{className:"text-sm",children:Z("repeat")})]}),J&&P&&x("p",{className:"text-xs text-muted-foreground",children:N$(P,Z)})]}),J&&x(C5,{className:"pt-0",children:U0("div",{className:"space-y-4",children:[U0("div",{className:"grid grid-cols-2 gap-4",children:[U0("div",{children:[x(q0,{className:"text-xs",htmlFor:"frequency",children:Z("repeats")}),U0(E5,{onValueChange:(U)=>G({freq:C2[U]}),value:f,children:[x(j5,{className:"h-8","data-testid":"frequency-select",id:"frequency",children:x(D5,{})}),x(x5,{children:Object.keys(C2).map((U)=>x(v5,{value:U,children:Z(U.toLowerCase())},U))})]})]}),U0("div",{children:[x(q0,{className:"text-xs",htmlFor:"interval",children:Z("every")}),x(t0,{className:"h-8",id:"interval",min:"1",onChange:(U)=>G({interval:c5(U.target.value)}),type:"number",value:Q?.interval||1})]})]}),Q?.freq===Z0.WEEKLY&&U0("div",{children:[x(q0,{className:"text-xs",children:Z("repeatOn")}),x("div",{className:"flex flex-wrap gap-1 mt-1",children:z.map((U,L)=>U0("div",{className:"flex items-center space-x-1",children:[x(KP,{checked:F.includes(U.value),id:B.listKey("day",L),onCheckedChange:()=>V(L)}),x(q0,{className:"text-xs cursor-pointer",htmlFor:B.listKey("day",L),children:U.label})]},B.listKey("weekday",L)))})]}),U0("div",{children:[x(q0,{className:"text-xs",children:Z("ends")}),x("div",{className:"space-y-2 mt-1",children:A$.map(({type:U,id:L,labelKey:W})=>U0("div",{className:"flex items-center space-x-2",children:[x(KP,{checked:N===U,id:L,onCheckedChange:()=>M(U)}),x(q0,{className:"text-xs",htmlFor:L,children:Z(W)}),U==="count"&&N==="count"&&U0(V$,{children:[x(t0,{className:"h-6 w-16 text-xs","data-testid":"count-input",min:"1",onChange:(I)=>G({count:c5(I.target.value)}),type:"number",value:Q?.count||1}),x("span",{className:"text-xs",children:Z("occurrences")})]}),U==="until"&&N==="until"&&x(lP,{className:"h-6",date:Q?.until??void 0,onChange:(I)=>G({until:I?T(I).endOf("day").toDate():void 0})})]},U))})]})]})})]})};import{useCallback as rP,useState as W$}from"react";var l5={isOpen:!1,operationType:"edit",event:null};function u5(P){let{updateRecurringEvent:$,deleteRecurringEvent:Z}=O((z)=>({updateRecurringEvent:z.updateRecurringEvent,deleteRecurringEvent:z.deleteRecurringEvent})),[X,J]=W$(l5),Y=rP((z,G)=>{J({isOpen:!0,operationType:"edit",event:z,updates:G,onConfirm:(K)=>{$(z,G,{scope:K,eventDate:z.start})}})},[$]),Q=rP((z)=>{J({isOpen:!0,operationType:"delete",event:z,onConfirm:(G)=>{Z(z,{scope:G,eventDate:z.start})}})},[Z]),q=rP(()=>J(l5),[]),_=rP((z)=>{if(X.onConfirm)X.onConfirm(z);q(),P?.()},[X,q,P]);return{dialogState:X,openEditDialog:Y,openDeleteDialog:Q,closeDialog:q,handleConfirm:_}}import{useMemo as F$}from"react";var nP=(P)=>{let{businessHours:$,getResourceById:Z}=O((X)=>({businessHours:X.businessHours,getResourceById:X.getResourceById}));return F$(()=>{if(P!=null&&Z){let X=Z(P);if(X?.businessHours)return X.businessHours}return $},[P,Z,$])};import{jsx as v,jsxs as f0,Fragment as B$}from"react/jsx-runtime";var o5=[{value:"bg-blue-100 text-blue-800",label:"Blue"},{value:"bg-green-100 text-green-800",label:"Green"},{value:"bg-purple-100 text-purple-800",label:"Purple"},{value:"bg-red-100 text-red-800",label:"Red"},{value:"bg-yellow-100 text-yellow-800",label:"Yellow"},{value:"bg-pink-100 text-pink-800",label:"Pink"},{value:"bg-indigo-100 text-indigo-800",label:"Indigo"},{value:"bg-amber-100 text-amber-800",label:"Amber"},{value:"bg-emerald-100 text-emerald-800",label:"Emerald"},{value:"bg-sky-100 text-sky-800",label:"Sky"},{value:"bg-violet-100 text-violet-800",label:"Violet"},{value:"bg-rose-100 text-rose-800",label:"Rose"},{value:"bg-teal-100 text-teal-800",label:"Teal"},{value:"bg-orange-100 text-orange-800",label:"Orange"}],h2=({name:P,label:$,placeholder:Z,value:X,required:J=!1,onChange:Y})=>f0("div",{className:"grid gap-1 sm:gap-2",children:[v(q0,{className:"text-xs sm:text-sm",htmlFor:P,children:$}),v(t0,{className:"h-8 text-sm sm:h-9",id:P,name:P,onChange:Y,placeholder:Z,required:J,value:X})]}),d5=({selectedEvent:P,onClose:$,onUpdate:Z,onDelete:X,onAdd:J})=>{let{dialogState:Y,openEditDialog:Q,openDeleteDialog:q,closeDialog:_,handleConfirm:z}=u5($),{findParentRecurringEvent:G,t:K,timeFormat:V}=O((H)=>({findParentRecurringEvent:H.findParentRecurringEvent,t:H.t,timeFormat:H.timeFormat})),M=nP(P?.resourceId),N=P?.start??T(),f=P?.end??T().add(1,"hour"),F=P?G(P):null,[U,L]=i0(N.toDate()),[W,I]=i0(f.toDate()),[R,S]=i0(P?.allDay||!1),[w,k]=i0(P?.color||o5[0].value),[h,j]=i0(N.format("HH:mm")),[c,e]=i0(f.format("HH:mm")),[E,m]=i0({title:P?.title||"",description:P?.description||"",location:P?.location||""}),[i,_0]=i0(()=>{return P?.rrule||F?.rrule||null}),G0=(H)=>{if(!H)return;if(L(H),T(H).isAfter(T(W)))I(H)},W0=(H)=>{if(!H)return;if(I(H),H&&T(H).isBefore(T(U)))L(H)},S0=(H)=>{if(j(H),T(U).isSame(T(W),"day")&&H>c)e(H)},J0=(H)=>{if(e(H),T(U).isSame(T(W),"day")&&H<h)j(H)},L0=(H)=>{let{name:P0,value:Q0}=H.target;m((A0)=>({...A0,[P0]:Q0}))};M$(()=>{if(R)e("23:59")},[R]);let d=(H)=>{H.preventDefault();let P0=w2(U,h,R),Q0=w5(W,c,R),A0={id:P?.id||T().format("YYYYMMDDHHmmss"),title:E.title,start:P0,end:Q0,resourceId:P?.resourceId,description:E.description,location:E.location,allDay:R,color:w,rrule:i||void 0};if(P?.id&&UP(P)){Q(P,{title:E.title,start:P0,end:Q0,description:E.description,location:E.location,allDay:R,color:w,rrule:i||void 0});return}if(P?.id)Z?.(A0);else J?.(A0);$()},p0=()=>{if(P?.id){if(UP(P)){q(P);return}X?.(P),$()}},T0=(H)=>{if(!H){_0(null);return}let P0=w2(U,h,R);_0({...H,dtstart:P0.toDate()})},H0=M?(H)=>!b2(T(H),M):void 0,y=k2(U,M),X0=k2(W,M),e0=[["startDate",U,G0],["endDate",W,W0]],PP=[["startTime","start-time",h,S0,y],["endTime","end-time",c,J0,X0]];return f0(B$,{children:[f0("form",{className:"flex flex-col flex-1 min-h-0",onSubmit:d,children:[v(O0,{className:"flex-1 min-h-0",children:f0("div",{className:"grid gap-3 sm:gap-4 p-1",children:[v(h2,{label:K("title"),name:"title",onChange:L0,placeholder:K("eventTitlePlaceholder"),required:!0,value:E.title}),v(h2,{label:K("description"),name:"description",onChange:L0,placeholder:K("eventDescriptionPlaceholder"),value:E.description}),f0("div",{className:"flex items-center space-x-2",children:[v(KP,{checked:R,id:"allDay",onCheckedChange:(H)=>S(H===!0)}),v(q0,{className:"text-xs sm:text-sm",htmlFor:"allDay",children:K("allDay")})]}),v("div",{className:"grid grid-cols-2 gap-2 sm:gap-4",children:e0.map(([H,P0,Q0])=>f0("div",{children:[v(q0,{className:"text-xs sm:text-sm",children:K(H)}),v(lP,{className:"mt-1",closeOnSelect:!0,date:P0,disabled:H0,onChange:Q0})]},H))}),!R&&v("div",{className:"grid grid-cols-2 gap-2 sm:gap-4",children:PP.map(([H,P0,Q0,A0,$P])=>f0("div",{children:[v(q0,{className:"text-xs sm:text-sm",children:K(H)}),v(H5,{className:"mt-1 h-8 text-sm sm:h-9",maxTime:$P.max,minTime:$P.min,name:P0,onChange:A0,placeholder:K("searchTime"),timeFormat:V,value:Q0})]},H))}),f0("div",{className:"grid gap-1 sm:gap-2",children:[v(q0,{className:"text-xs sm:text-sm",children:K("color")}),v("div",{className:"flex flex-wrap gap-2",children:o5.map((H)=>v(g,{"aria-label":H.label,className:A(`${H.value} h-6 w-6 rounded-full sm:h-8 sm:w-8`,w===H.value&&"ring-2 ring-black ring-offset-1 sm:ring-offset-2"),onClick:()=>k(H.value),type:"button",variant:"ghost"},H.value))})]}),v(h2,{label:K("location"),name:"location",onChange:L0,placeholder:K("eventLocationPlaceholder"),value:E.location}),v(i5,{onChange:T0,value:i})]})}),f0(gP,{className:"mt-4 shrink-0 flex flex-col-reverse gap-2 sm:flex-row sm:gap-0",children:[P?.id&&v(g,{className:"w-full sm:mr-auto sm:w-auto",onClick:p0,size:"sm",type:"button",variant:"destructive",children:K("delete")}),f0("div",{className:"flex w-full gap-2 sm:w-auto",children:[v(g,{className:"flex-1 sm:flex-none",onClick:$,size:"sm",type:"button",variant:"outline",children:K("cancel")}),v(g,{className:"flex-1 sm:flex-none",size:"sm",type:"submit",children:P?.id?K("update"):K("create")})]})]})]}),v(fP,{eventTitle:Y.event?.title||"",isOpen:Y.isOpen,onClose:_,onConfirm:z,operationType:Y.operationType})]})};import{jsx as aP,jsxs as r5}from"react/jsx-runtime";var tP=()=>{let{t:P,selectedEvent:$,isEventFormOpen:Z,closeEventForm:X,addEvent:J,updateEvent:Y,deleteEvent:Q,renderEventForm:q}=O((K)=>({t:K.t,selectedEvent:K.selectedEvent,isEventFormOpen:K.isEventFormOpen,closeEventForm:K.closeEventForm,addEvent:K.addEvent,updateEvent:K.updateEvent,deleteEvent:K.deleteEvent,renderEventForm:K.renderEventForm})),G={open:Z,onClose:X,selectedEvent:$,onAdd:J,onUpdate:(K)=>{Y(K.id,K)},onDelete:(K)=>{Q(K.id)}};if(q)return q(G);return aP(JP,{onOpenChange:X,open:Z,children:r5(QP,{className:"flex flex-col h-[90vh] w-[90vw] max-w-[500px] p-4 sm:p-6 overflow-hidden gap-0",children:[r5(YP,{className:"mb-2 sm:mb-4 shrink-0",children:[aP(qP,{className:"text-base sm:text-lg",children:$?.id?P("editEvent"):P("createEvent")}),aP(CP,{className:"text-xs sm:text-sm",children:$?.id?P("editEventDetails"):P("addNewEvent")})]}),aP(d5,{...G})]})})};import{Calendar as h$,Download as E$,Menu as D$,Plus as j$}from"lucide-react";import{useState as x$}from"react";import{RRule as O$}from"rrule";var E2=`\r
`,f$=["BEGIN:VTIMEZONE","TZID:UTC","BEGIN:STANDARD","DTSTART:19700101T000000","TZNAME:UTC","TZOFFSETFROM:+0000","TZOFFSETTO:+0000","END:STANDARD","END:VTIMEZONE"].join(E2),eP=(P)=>{return P.replaceAll("\\","\\\\").replaceAll(";","\\;").replaceAll(",","\\,").replaceAll(`
`,"\\n").replaceAll("\r","")},sP=(P,$=!1)=>{return $?P.format("YYYYMMDD"):P.utc().format("YYYYMMDD[T]HHmmss[Z]")},n5=(P)=>{return P.uid||`${P.id}@ilamy.calendar`},I$=(P)=>{try{return new O$(P).toString().split(`
`).find((Z)=>Z.startsWith("RRULE:"))||""}catch{return""}},R$=(P)=>{let $=T().utc().format("YYYYMMDD[T]HHmmss[Z]"),Z=P.allDay?";VALUE=DATE