UNPKG

@ilamy/calendar

Version:

A full-featured React calendar component library built with Shadcn-Ui, Tailwind CSS, and TypeScript.

3 lines 598 kB
import{RRule as LU}from"rrule";import{AnimatePresence as f4,motion as A4}from"motion/react";import{clsx as G4}from"clsx";import{twMerge as L4}from"tailwind-merge";import N0 from"dayjs";import Z4 from"dayjs/plugin/isBetween.js";import J4 from"dayjs/plugin/isSameOrAfter.js";import X4 from"dayjs/plugin/isSameOrBefore.js";import Q4 from"dayjs/plugin/localeData.js";import Y4 from"dayjs/plugin/minMax.js";import q4 from"dayjs/plugin/timezone.js";import U4 from"dayjs/plugin/utc.js";import z4 from"dayjs/plugin/weekday.js";import K4 from"dayjs/plugin/weekOfYear.js";var s2,_4=(P,$,Z)=>{let J=$.prototype,X=Z.tz.setDefault;Z.tz.setDefault=(q)=>{return s2=q,X(q)};let{startOf:Q,endOf:Y}=J;function U(q,_){let L=q.$x?.$timezone||s2;if(!L)return _;let z=Z.tz(_.format("YYYY-MM-DDTHH:mm:ss"),L).utcOffset();if(_.utcOffset()!==z)return _.tz(L,!0);return _}J.startOf=function(q,_){let L=Q.call(this,q,_);return U(this,L)},J.endOf=Y};N0.extend(z4);N0.extend(K4);N0.extend(J4);N0.extend(X4);N0.extend(Z4);N0.extend(Y4);N0.extend(q4);N0.extend(U4);N0.extend(Q4);N0.extend(_4);var e2=(...P)=>{return N0.tz(...P)};Object.assign(e2,N0);var I=e2;var j0=1,P5=24,R0=24,YP=4,$5="bg-secondary text-muted-foreground pointer-events-none",x0={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function A(...P){return L4(G4(P))}var CP=(P)=>{if(!P||P.length===0)return;return new Set(P.map(($)=>x0[$]))};function qP(P){if(P===void 0)return;if(I.isDayjs(P))return P;let $=I(P);return $.isValid()?$:void 0}var Z5=(P,$)=>{let Z={...P};for(let J of $)delete Z[J];return Z};function EP(P){if(!P||!P.length)return[];return P.map(($)=>{return{...$,start:I.isDayjs($.start)?$.start:I($.start),end:I.isDayjs($.end)?$.end:I($.end)}})}import{jsx as J5}from"react/jsx-runtime";var N4={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}})},E=({children:P,transitionKey:$,delay:Z=0,className:J,direction:X="vertical",layout:Q,layoutId:Y,"data-testid":U,ref:q,..._})=>J5(f4,{mode:"wait",children:J5(A4.div,{animate:"visible",className:A("inline-block w-full",J),custom:{delay:Z,direction:X},"data-testid":U,exit:"exit",initial:"hidden",layout:Q,layoutId:Y,ref:q,variants:N4,..._,children:P},$)});E.displayName="AnimatedSection";import{DndContext as E4,MouseSensor as D4,pointerWithin as j4,TouchSensor as x4,useSensor as F5,useSensors as v4}from"@dnd-kit/core";import{useRef as O5,useState as y4}from"react";import{Slot as W4}from"@radix-ui/react-slot";import{cva as F4}from"class-variance-authority";import{jsx as V4}from"react/jsx-runtime";var O4=F4("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 h({className:P,variant:$,size:Z,asChild:J=!1,...X}){return V4(J?W4:"button",{className:A(O4({variant:$,size:Z,className:P})),"data-slot":"button",...X})}import*as Z0 from"@radix-ui/react-dialog";import{XIcon as B4}from"lucide-react";import{jsx as I0,jsxs as V2}from"react/jsx-runtime";function UP({...P}){return I0(Z0.Root,{"data-slot":"dialog",...P})}function M4({...P}){return I0(Z0.Portal,{"data-slot":"dialog-portal",...P})}function p4({className:P,...$}){return I0(Z0.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 zP({className:P,children:$,...Z}){return V2(M4,{"data-slot":"dialog-portal",children:[I0(p4,{}),V2(Z0.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(Z0.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:[I0(B4,{}),I0("span",{className:"sr-only",children:"Close"})]})]})]})}function KP({className:P,...$}){return I0("div",{className:A("flex flex-col gap-2 text-center sm:text-left",P),"data-slot":"dialog-header",...$})}function DP({className:P,...$}){return I0("div",{className:A("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",P),"data-slot":"dialog-footer",...$})}function _P({className:P,...$}){return I0(Z0.Title,{className:A("text-lg leading-none font-semibold",P),"data-slot":"dialog-title",...$})}function jP({className:P,...$}){return I0(Z0.Description,{className:A("text-muted-foreground text-sm",P),"data-slot":"dialog-description",...$})}import{useContext as f5}from"react";import{createContext as R4}from"react";var xP=R4(void 0);import{createContext as I4}from"react";var vP=I4(void 0);import{useCallback as Y0,useMemo as H4,useState as G5}from"react";import{useCallback as s,useEffect as p2,useMemo as K5,useRef as R2,useState as e0}from"react";import{RRule as S4}from"rrule";var yP=(P)=>{return new Date(Date.UTC(P.year(),P.month(),P.date(),P.hour(),P.minute(),P.second(),P.millisecond()))},T4=(P,$)=>{return $.year(P.getUTCFullYear()).month(P.getUTCMonth()).date(P.getUTCDate()).hour(P.getUTCHours()).minute(P.getUTCMinutes()).second(P.getUTCSeconds()).millisecond(P.getUTCMilliseconds())},GP=(P)=>{return Boolean(P.rrule||P.recurrenceId||P.uid)},v0=(P)=>{return P.uid||`${P.id}@ilamy.calendar`},X5=(P,$)=>{let Z=v0($),J=P.findIndex((X)=>v0(X)===Z&&X.rrule&&!X.recurrenceId);if(J===-1)throw Error("Base recurring event not found");return J},Q5=(P)=>P.start.subtract(1,"day").endOf("day").toDate(),B2=({event:P,currentEvents:$,startDate:Z,endDate:J})=>{if(!P.rrule)return[];try{let X=yP(P.start),Q=P.rrule.until?yP(I(P.rrule.until)):void 0,Y={...P.rrule,dtstart:X,until:Q},U=new S4(Y),q=v0(P),_=$.filter((K)=>K.recurrenceId&&v0(K)===q),L=P.end.diff(P.start),z=yP(Z.subtract(L,"millisecond")),W=yP(J);return U.between(z,W,!0).map((K,N)=>{let G=T4(K,P.start),O=_.find((g)=>qP(g.recurrenceId)?.isSame(G));if(O)return{...P,...O};let M=P.end.diff(P.start),p=G.add(M,"millisecond"),S=`${P.id}_${N}`,R=v0(P);return{...P,id:S,start:G,end:p,uid:R,rrule:void 0}}).filter((K)=>{if(P.exdates&&P.exdates.length>0){let O=K.start.toISOString();if(P.exdates?.includes(O))return!1}return K.start.isSameOrBefore(J)&&K.end.isSameOrAfter(Z)})}catch(X){throw Error(`Invalid RRULE options: ${JSON.stringify(P.rrule)}. Error: ${X instanceof Error?X.message:"Unknown error"}`)}},Y5=({targetEvent:P,updates:$,currentEvents:Z,scope:J})=>{let X=[...Z],Q=X5(X,P),Y=X[Q];switch(J){case"this":{let U=P.start.toISOString(),_=[...Y.exdates||[],U],L={...Y,exdates:_};X[Q]=L;let z=`${P.id}_modified_${Date.now()}`,W={...Z5(P,["width","height","top","left","right"]),...$,id:z,recurrenceId:U,uid:v0(Y),rrule:void 0};X.push(W);break}case"following":{let U=Q5(P),q={...Y,rrule:{...Y.rrule,until:U}};X[Q]=q;let _=Y.end.diff(Y.start),L=$.start||P.start,z=$.end||L.add(_),W=`${Y.id}_following`,F=`${W}@ilamy.calendar`,f={...Y,...$,rrule:{...Y.rrule,...$.rrule,dtstart:L.toDate()},id:W,uid:F,start:L,end:z,recurrenceId:void 0};X.push(f);break}case"all":{let U={...Y,...$};X[Q]=U;break}default:throw Error(`Invalid scope: ${J}. Must be 'this', 'following', or 'all'`)}return X},q5=({targetEvent:P,currentEvents:$,scope:Z})=>{let J=[...$],X=X5(J,P),Q=J[X];switch(Z){case"this":{let Y=P.start.toISOString(),q=[...Q.exdates||[],Y],_={...Q,exdates:q};J[X]=_;break}case"following":{let Y={...Q,rrule:{...Q.rrule,until:Q5(P)}};J[X]=Y;break}case"all":{let Y=v0(P);return J.filter((q)=>v0(q)!==Y)}default:throw Error(`Invalid scope: ${Z}. Must be 'this', 'following', or 'all'`)}return J};var M2={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",sunday:"Sunday",monday:"Monday",tuesday:"Tuesday",wednesday:"Wednesday",thursday:"Thursday",friday:"Friday",saturday:"Saturday",sun:"Sun",mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",january:"January",february:"February",march:"March",april:"April",may:"May",june:"June",july:"July",august:"August",september:"September",october:"October",november:"November",december:"December"};function t(P){return P.isSame(I(),"day")}function r(P){return P.format("YYYY-MM-DD")}function U0(P,$){let Z=P.startOf("week").day($),J=P.isBefore(Z)?Z.subtract(1,"week"):Z;return Array.from({length:7},(X,Q)=>J.add(Q,"day"))}function LP(P,$){let Z=U0(P.startOf("month"),$);return Array.from({length:6},(J,X)=>{let Q=Z[0].add(X,"week");return U0(Q,$)})}function U5(P){let $=P.daysInMonth(),Z=P.startOf("month");return Array.from({length:$},(J,X)=>Z.add(X,"day"))}function z5({referenceDate:P=I(),length:$=24}={}){let Z=P.startOf("day");return Array.from({length:$},(J,X)=>Z.hour(X).minute(0).second(0).millisecond(0))}function fP(P,$){let Z=new Set($.map((J)=>String(J.id)));return P.filter((J)=>Z.has(String(J.id)))}function cP(P,$,Z){let J=P.start.isSameOrAfter($)&&P.start.isSameOrBefore(Z),X=P.end.isSameOrAfter($)&&P.end.isSameOrBefore(Z),Q=P.start.isBefore($)&&P.end.isAfter(Z);return J||X||Q}var _5={day:"day",week:"week",month:"month",year:"year"},I2=(P,$,Z)=>{if($==="day"||$==="year")return{start:P.startOf($),end:P.endOf($)};if($==="week"){let X=U0(P,Z);return{start:X[0].startOf("day"),end:X[6].endOf("day")}}let J=LP(P,Z);return{start:J[0][0].startOf("day"),end:J[5][6].endOf("day")}},oP=(P)=>{let{events:$=[],firstDayOfWeek:Z=0,initialView:J="month",initialDate:X=I(),businessHours:Q,onEventAdd:Y,onEventUpdate:U,onEventDelete:q,onDateChange:_,onViewChange:L,locale:z,timezone:W,translations:F,translator:f}=P,[K,N]=e0(I.isDayjs(X)?X:I(X)),[G,O]=e0(J),[M,p]=e0($),[S,R]=e0(!1),[b,g]=e0(null),[D,u]=e0(null),[c,P0]=e0(z||"en"),j=R2($),k=R2(W),o=R2(z),G0=K5(()=>{if(f)return f;let H=F||M2;return(w)=>H[w]||w},[F,f]),F0=s((H,w)=>{let y=[];for(let f0 of M)if(f0.rrule)y.push(...B2({event:f0,currentEvents:M,startDate:H,endDate:w}));else if(cP(f0,H,w))y.push(f0);return y},[M]),M0=s(()=>{return I2(K,G,Z)},[K,G,Z]),X0=K5(()=>{let{start:H,end:w}=M0();return F0(H,w)},[F0,M0]);p2(()=>{if($!==j.current)p($),j.current=$},[$]),p2(()=>{if(z&&z!==o.current)P0(z),I.locale(z),N((H)=>H.locale(z)),o.current=z},[z]),p2(()=>{if(W&&W!==k.current)I.tz.setDefault(W),N((H)=>H.tz(W)),p((H)=>H.map((w)=>({...w,start:w.start.tz(W),end:w.end.tz(W)}))),k.current=W},[W]);let q0=s((H)=>{N(H);let w=I2(H,G,Z);_?.(H,w)},[_,G,Z]),m0=q0,L0=s((H)=>{let w=H===1?K.add(1,_5[G]):K.subtract(1,_5[G]);q0(w)},[K,G,q0]),Q0=s(()=>L0(1),[L0]),a=s(()=>L0(-1),[L0]),s0=s(()=>q0(I()),[q0]),i=s((H)=>{p((w)=>[...w,H]),Y?.(H)},[Y]),p0=s((H,w)=>{let y=M.find((QP)=>QP.id===H);if(!y)return;let f0={...y,...w};p((QP)=>QP.map((IP)=>IP.id===H?f0:IP)),U?.(f0)},[M,U]),D0=s((H,w,y)=>{U?.({...H,...w}),p(Y5({targetEvent:H,updates:w,currentEvents:M,scope:y.scope}))},[M,U]),JP=s((H,w)=>{q?.(H),p(q5({targetEvent:H,currentEvents:M,scope:w.scope}))},[M,q]),XP=s((H)=>{let w=M.find((y)=>y.id===H);if(!w)return;p((y)=>y.filter((f0)=>f0.id!==H)),q?.(w)},[M,q]),T=s((H)=>{if(H?.start)u(H.start);let w=H?.start??K;g({title:G0("newEvent"),start:w,end:H?.end??w.add(1,"hour"),resourceId:H?.resourceId,description:"",allDay:H?.allDay??!1}),R(!0)},[K,G0]),d=s(()=>{u(null),g(null),R(!1)},[]),$0=s((H)=>{O(H),L?.(H);let w=I2(K,H,Z);_?.(K,w)},[L,_,K,Z]),O0=s((H)=>{let w=H.uid;return M.find((y)=>(y.uid||`${y.id}@ilamy.calendar`)===w&&y.rrule)||null},[M]);return{currentDate:K,view:G,events:X0,rawEvents:M,isEventFormOpen:S,selectedEvent:b,selectedDate:D,firstDayOfWeek:Z,dayMaxEvents:YP,currentLocale:c,businessHours:Q,setCurrentDate:N,selectDate:m0,setView:$0,nextPeriod:Q0,prevPeriod:a,today:s0,addEvent:i,updateEvent:p0,updateRecurringEvent:D0,deleteEvent:XP,deleteRecurringEvent:JP,openEventForm:T,closeEventForm:d,setSelectedEvent:g,setIsEventFormOpen:R,setSelectedDate:u,getEventsForDateRange:F0,findParentRecurringEvent:O0,t:G0}};import{jsx as b4}from"react/jsx-runtime";var S2=(P)=>{if(P.resourceIds)return P.resourceIds;if(P.resourceId!==void 0)return[P.resourceId];return[]},L5=({children:P,events:$=[],resources:Z=[],firstDayOfWeek:J=0,initialView:X="month",initialDate:Q,renderEvent:Y,onEventClick:U,onCellClick:q,onViewChange:_,onEventAdd:L,onEventUpdate:z,onEventDelete:W,onDateChange:F,locale:f,timezone:K,disableCellClick:N,disableEventClick:G,disableDragAndDrop:O,dayMaxEvents:M,eventSpacing:p=1,eventHeight:S=R0,stickyViewHeader:R=!0,viewHeaderClassName:b="",headerComponent:g,headerClassName:D,translations:u,translator:c,renderResource:P0,renderEventForm:j,businessHours:k,timeFormat:o="12-hour",classesOverride:G0,orientation:F0="horizontal",renderCurrentTimeIndicator:M0,renderHour:X0,hideNonBusinessHours:q0=!1,hiddenDays:m0,weekViewGranularity:L0="hourly"})=>{let[Q0]=G5(Z),[a,s0]=G5(new Set(Z.map((m)=>m.id))),i=oP({events:$,firstDayOfWeek:J,initialView:X,initialDate:Q,businessHours:k,onEventAdd:L,onEventUpdate:z,onEventDelete:W,onDateChange:F,onViewChange:_,locale:f,timezone:K,translations:u,translator:c}),p0=Y0((m,A0)=>{s0((O2)=>{let hP=new Set(O2);if(m==="show"||m==="toggle"&&!hP.has(A0))hP.add(A0);else hP.delete(A0);return hP})},[]),D0=Y0((m)=>p0("show",m),[p0]),JP=Y0((m)=>p0("hide",m),[p0]),XP=Y0((m)=>p0("toggle",m),[p0]),T=Y0(()=>s0(new Set(Q0.map((m)=>m.id))),[Q0]),d=Y0(()=>s0(new Set),[]),$0=Y0((m)=>i.events.filter((A0)=>S2(A0).includes(m)),[i.events]),O0=Y0((m)=>i.events.filter((A0)=>S2(A0).some((O2)=>m.includes(O2))),[i.events]),H=Y0((m)=>{return Q0.find((A0)=>A0.id===m)},[Q0]),w=Y0(()=>{return Q0.filter((m)=>a.has(m.id))},[Q0,a]),y=Y0((m)=>{return Boolean(m.resourceIds&&m.resourceIds.length>1)},[]),f0=Y0((m)=>{i.setSelectedEvent(m),i.setIsEventFormOpen(!0)},[i]),QP=Y0((m)=>{if(G)return;if(U)U(m);else f0(m)},[G,U,f0]),IP=Y0((m)=>{if(N)return;if(q)q(m);else{let A0={title:i.t("newEvent"),start:m.start,end:m.end,description:"",allDay:!1};if(m.resourceId!==void 0)A0.resourceId=m.resourceId;i.setSelectedEvent(A0),i.setSelectedDate(m.start),i.setIsEventFormOpen(!0)}},[q,N,i]),$4=H4(()=>({...i,resources:Q0,visibleResources:a,toggleResourceVisibility:XP,showResource:D0,hideResource:JP,showAllResources:T,hideAllResources:d,getEventsForResource:$0,getEventsForResources:O0,getResourceById:H,getVisibleResources:w,isEventCrossResource:y,getEventResourceIds:S2,onEventClick:QP,onCellClick:IP,renderEvent:Y,renderResource:P0,renderEventForm:j,headerComponent:g,headerClassName:D,locale:f,timezone:K,disableCellClick:N,disableEventClick:G,disableDragAndDrop:O,dayMaxEvents:M,eventSpacing:p,eventHeight:S,stickyViewHeader:R,viewHeaderClassName:b,businessHours:k,timeFormat:o,classesOverride:G0,orientation:F0,renderCurrentTimeIndicator:M0,renderHour:X0,hideNonBusinessHours:q0,hiddenDays:m0,weekViewGranularity:L0}),[i,Q0,a,XP,D0,JP,T,d,$0,O0,H,w,y,QP,IP,Y,P0,j,f,K,N,G,O,M,p,S,R,b,g,D,k,o,G0,F0,M0,X0,q0,m0,L0]);return b4(vP.Provider,{value:$4,children:P})};function B(P){let $=f5(vP),Z=f5(xP),J=$||Z;if(!J)throw Error("useSmartCalendarContext must be used within a CalendarProvider or ResourceCalendarProvider");return P?P(J):J}function w4(){let P=B();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 y0,jsxs as iP}from"react/jsx-runtime";var m4=[{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 SP({isOpen:P,onClose:$,onConfirm:Z,operationType:J,eventTitle:X}){let{t:Q}=B((q)=>({t:q.t})),Y=(q)=>{Z(q),$()},U=J==="edit";return y0(UP,{onOpenChange:$,open:P,children:iP(zP,{className:"max-w-md",children:[iP(KP,{children:[y0(_P,{children:U?Q("editRecurringEvent"):Q("deleteRecurringEvent")}),iP(jP,{children:['"',X,'"'," ",U?Q("editRecurringEventQuestion"):Q("deleteRecurringEventQuestion")]})]}),y0("div",{className:"space-y-3",children:m4.map(({scope:q,title:_,editKey:L,deleteKey:z})=>y0(h,{className:"w-full justify-start h-auto p-4",onClick:()=>Y(q),variant:"outline",children:iP("div",{className:"text-left",children:[y0("div",{className:"font-medium",children:Q(_)}),y0("div",{className:"text-sm text-muted-foreground",children:Q(U?L:z)})]})},q))}),y0(DP,{children:y0(h,{onClick:$,variant:"outline",children:Q("cancel")})})]})})}var A5=(P,$)=>{let{active:Z,over:J}=P;if(!Z||!J||!$)return null;let X=J.data.current||{},Q=X.type==="time-cell",{resourceId:Y,allDay:U}=X,q;if(Q){let{date:W,hour:F=0,minute:f=0}=X;q=I(W).hour(F).minute(f)}else{let{date:W}=X;q=I(W)}let _=$.end.diff($.start,"second"),L=q.add(_,"second");if(L.isSame(L.startOf("day")))L=L.subtract(1,"day").endOf("day");let z={start:q,end:L,resourceId:Y,allDay:Q?!1:U??$.allDay};return{activeEvent:$,updates:z}};import{DragOverlay as g4}from"@dnd-kit/core";import{snapCenterToCursor as k4}from"@dnd-kit/modifiers";import{useImperativeHandle as h4,useState as C4}from"react";import{jsx as N5}from"react/jsx-runtime";var W5=({ref:P})=>{let[$,Z]=C4(null);return h4(P,()=>({setActiveEvent:Z})),N5(g4,{modifiers:[k4],children:$&&N5("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 V5,jsxs as B5,Fragment as c4}from"react/jsx-runtime";var T2={isOpen:!1,event:null,updates:null};function lP({children:P}){let $=O5(null),Z=O5(null),{updateEvent:J,updateRecurringEvent:X,disableDragAndDrop:Q}=B((G)=>({updateEvent:G.updateEvent,updateRecurringEvent:G.updateRecurringEvent,disableDragAndDrop:G.disableDragAndDrop})),[Y,U]=y4({isOpen:!1,event:null,updates:null}),q=F5(D4,{activationConstraint:{distance:2}}),_=F5(x4,{activationConstraint:{delay:100,tolerance:5}}),L=v4(q,_),z=(G,O)=>{if(!G?.id||!O||Object.keys(O).length===0)return;if(GP(G))U({isOpen:!0,event:G,updates:O});else J(G.id,O)},W=(G)=>{if(!Y.event||!Y.updates){U(T2);return}try{X(Y.event,Y.updates,{scope:G,eventDate:Y.event.start})}catch{}finally{U(T2)}},F=()=>{U(T2)},f=(G)=>{let{active:O}=G;if(O.data.current?.type==="calendar-event")Z.current?.setActiveEvent(O.data.current.event),$.current=O.data.current.event},K=(G)=>{let O=A5(G,$.current);if(O){let{activeEvent:M,updates:p}=O;z(M,p)}$.current=null,Z.current?.setActiveEvent(null)},N=(G)=>{$.current=null};if(Q)return P;return B5(c4,{children:[B5(E4,{collisionDetection:j4,onDragCancel:N,onDragEnd:K,onDragStart:f,sensors:L,children:[P,V5(W5,{ref:Z})]}),V5(SP,{eventTitle:Y.event?.title||"",isOpen:Y.isOpen,onClose:F,onConfirm:W,operationType:"edit"})]})}import{useEffect as V$,useState as u0}from"react";import*as uP from"@radix-ui/react-checkbox";import{CheckIcon as o4}from"lucide-react";import{jsx as H2}from"react/jsx-runtime";function AP({className:P,...$}){return H2(uP.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:H2(uP.Indicator,{className:"flex items-center justify-center text-current transition-none","data-slot":"checkbox-indicator",children:H2(o4,{className:"size-3.5"})})})}import{PopoverClose as r4}from"@radix-ui/react-popover";import{Calendar as n4}from"lucide-react";import{useEffect as a4,useRef as t4,useState as s4}from"react";import{ChevronLeftIcon as i4,ChevronRightIcon as l4}from"lucide-react";import{useState as u4}from"react";import{jsx as W0,jsxs as b2}from"react/jsx-runtime";var d4=["S","M","T","W","T","F","S"];function M5({selected:P,defaultMonth:$,onSelect:Z,disabled:J,firstDayOfWeek:X=0,className:Q}){let[Y,U]=u4(()=>I($??P??new Date).startOf("month")),q=LP(Y,X),_=P?I(P).format("YYYY-MM-DD"):void 0,L=Array.from({length:7},(z,W)=>d4[(X+W)%7]);return b2("div",{className:A("bg-background p-3 w-[280px]",Q),"data-slot":"calendar",children:[b2("div",{className:"flex items-center justify-between mb-2",children:[W0(h,{"aria-label":"Previous month",onClick:()=>U((z)=>z.subtract(1,"month")),size:"icon",variant:"ghost",children:W0(i4,{className:"size-4"})}),W0("div",{className:"text-sm font-medium select-none",children:Y.format("MMMM YYYY")}),W0(h,{"aria-label":"Next month",onClick:()=>U((z)=>z.add(1,"month")),size:"icon",variant:"ghost",children:W0(l4,{className:"size-4"})})]}),b2("table",{className:"w-full border-collapse",role:"grid",children:[W0("thead",{children:W0("tr",{children:L.map((z,W)=>W0("th",{className:"text-muted-foreground text-xs font-medium select-none py-1",children:z},W))})}),W0("tbody",{children:q.map((z,W)=>W0("tr",{children:z.map((F)=>{let f=!F.isSame(Y,"month"),K=F.format("YYYY-MM-DD")===_,N=J?.(F.toDate())??!1;return W0("td",{className:"p-0 text-center","data-disabled":N,"data-outside":f,"data-selected":K,role:"gridcell",tabIndex:-1,children:W0("button",{"aria-disabled":N,"aria-hidden":f,className:A("w-full aspect-square rounded-md text-sm select-none",!N&&"hover:bg-accent cursor-pointer",f&&"text-muted-foreground/50",t(F)&&!K&&"bg-accent text-accent-foreground",K&&"bg-primary text-primary-foreground font-medium",N&&"opacity-50 cursor-not-allowed"),"data-disabled":N,"data-selected":K,disabled:N||f,onClick:()=>Z?.(F.toDate()),tabIndex:f?-1:0,type:"button",children:F.format("D")})},F.toISOString())})},W))})]})]})}import*as g0 from"@radix-ui/react-popover";import{jsx as dP}from"react/jsx-runtime";function c0({...P}){return dP(g0.Root,{"data-slot":"popover",...P})}function o0({...P}){return dP(g0.Trigger,{"data-slot":"popover-trigger",...P})}function i0({className:P,align:$="center",sideOffset:Z=4,...J}){return dP(g0.Portal,{children:dP(g0.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,...J})})}import{jsx as NP,jsxs as w2}from"react/jsx-runtime";function rP({date:P,closeOnSelect:$,onChange:Z,label:J="Pick a date",className:X,disabled:Q}){let Y=t4(null),[U,q]=s4(P);a4(()=>{q(P)},[P]);let _=(L)=>{if(q(L),$)Y.current?.click();Z?.(L)};return NP("div",{className:X,children:w2(c0,{children:[NP(o0,{asChild:!0,children:w2(h,{className:A("data-[empty=true]:text-muted-foreground w-full justify-start text-left font-normal"),"data-empty":!P,variant:"outline",children:[NP(n4,{}),U?I(U).format("MMM D, YYYY"):NP("span",{children:J})]})}),w2(i0,{align:"start",className:"w-auto p-0",children:[NP(r4,{ref:Y,style:{display:"none"}}),NP(M5,{defaultMonth:U,disabled:Q,onSelect:_,selected:U})]})]})})}import{jsx as e4}from"react/jsx-runtime";function PP({className:P,type:$,...Z}){return e4("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 p5 from"@radix-ui/react-label";import{jsx as P$}from"react/jsx-runtime";function z0({className:P,...$}){return P$(p5.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 S0 from"@radix-ui/react-scroll-area";import{jsx as TP,jsxs as $$}from"react/jsx-runtime";function T0({className:P,children:$,viewPortProps:Z,...J}){return $$(S0.Root,{className:A("relative",P),"data-slot":"scroll-area",...J,children:[TP(S0.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:$}),TP(k0,{}),TP(S0.Corner,{})]})}function k0({className:P,orientation:$="vertical",...Z}){return TP(S0.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:TP(S0.ScrollAreaThumb,{className:"bg-border relative flex-1 rounded-full","data-slot":"scroll-area-thumb"})})}import{Clock as X$}from"lucide-react";import{useEffect as Q$,useRef as I5,useState as m2}from"react";import{useMemo as Z$}from"react";function R5({timeFormat:P="12-hour",minTime:$="00:00",maxTime:Z="23:45"}){return{timeOptions:Z$(()=>{let Q=[],[Y,U]=$.split(":").map(Number),[q,_]=Z.split(":").map(Number),L=Y*60+U,z=q*60+_;for(let W=L;W<=z;W+=15){let F=Math.floor(W/60),f=W%60,K=`${F.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}`;Q.push(K)}return Q},[$,Z]),formatTime:(Q)=>{let[Y,U]=Q.split(":").map(Number),q=Y>=12?"PM":"AM",_=Y===0?12:Y>12?Y-12:Y;if(P==="24-hour")return`${Y.toString().padStart(2,"0")}:${U.toString().padStart(2,"0")}`;return`${_}:${U.toString().padStart(2,"0")} ${q}`}}}var WP=(P)=>String(P).padStart(2,"0"),J$=(P)=>typeof P==="number"?WP(P):P,V={col:{time:"time-col",date:"date-col",day:(P,$)=>{let Z=`day-col-${r(P)}`;return $!=null?`${Z}-resource-${$}`:Z},resource:(P,$)=>`${P}-col-resource-${$}`,allDay:(P,$)=>`all-day-col-${r(P)}-${$}`},cell:{day:(P,$,Z=0)=>{let J=r(P);return $!=null?`day-cell-${J}-${WP($)}-${WP(Z)}`:`day-cell-${J}`},verticalTime:(P)=>`vertical-time-${WP(P)}`,vertical:(P,$,Z,J)=>{let X=`vertical-cell-${r(P)}-${WP($)}-${WP(Z)}`;return J!=null?`${X}-resource-${J}`:X}},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)=>t(P)?"day-number-today":`day-number-${P.format("D")}`,timePicker:(P)=>`time-picker-${P??""}`,droppable:{dayCell:(P,$)=>{let Z=P.toISOString(),J=$?.allDay?"-allday":"",X=$?.resourceId!=null?`-resource-${$.resourceId}`:"";return`drop-day-cell-${Z}${J}${X}`}}};import{jsx as l0,jsxs as g2}from"react/jsx-runtime";var Y$=(P)=>{P.stopPropagation()};function S5({value:P,onChange:$,minTime:Z="00:00",maxTime:J="23:45",timeFormat:X="12-hour",placeholder:Q="Select time...",className:Y,disabled:U=!1,name:q}){let[_,L]=m2(!1),[z,W]=m2(""),F=I5(null),f=I5(null),[K,N]=m2(0),{timeOptions:G,formatTime:O}=R5({timeFormat:X,minTime:Z,maxTime:J}),M=G.filter((R)=>{return O(R).toLowerCase().includes(z.toLowerCase())}),p=(R)=>{$(R),L(!1),W("")};Q$(()=>{if(_){if(f.current)N(f.current.offsetWidth);setTimeout(()=>{F.current?.focus()},0)}},[_]);let S=P?O(P):Q;return g2(c0,{onOpenChange:L,open:_,children:[l0(o0,{asChild:!0,children:g2(h,{"aria-controls":"time-picker-listbox","aria-expanded":_,className:A("w-full justify-start",Y),"data-testid":V.timePicker(q),disabled:U,ref:f,role:"combobox",variant:"outline",children:[l0(X$,{className:"mr-2 h-4 w-4"}),S]})}),g2(i0,{align:"start",className:"p-0",style:{width:K},children:[l0("div",{className:"p-2 border-b",children:l0(PP,{className:"h-8",onChange:(R)=>W(R.target.value),placeholder:"Search time...",ref:F,value:z})}),l0(T0,{className:"h-[200px]",onWheel:Y$,children:l0("div",{className:"p-1",children:M.length===0?l0("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"N/A"}):M.map((R)=>{let b=O(R);return l0("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",R===P&&"bg-accent text-accent-foreground"),onClick:()=>p(R),type:"button",children:b},R)})})})]})]})}var k2=(P,$)=>{if(!$)return!0;let Z=!1;return nP($,{date:P,onMatch:()=>{Z=!0}}),Z},T5=({date:P,hour:$,minute:Z=0,businessHours:J})=>{if(!J)return!0;if($===void 0)return k2(P,J);let X=!1,Q=$*60+Z;return nP(J,{date:P,onMatch:(Y)=>{let U=Y.startTime??9,q=Y.endTime??17,_=U*60,L=q*60;if(Q>=_&&Q<L)X=!0}}),X},nP=(P,$)=>{let{date:Z,onMatch:J}=$;if(!P)return;let X=Array.isArray(P)?P:[P];for(let Q of X)if(Z&&Q.daysOfWeek){let Y=Z.day();if(Q.daysOfWeek.some((U)=>x0[U]===Y))J(Q)}else J(Q)},aP=(P)=>{let{allDates:$,businessHours:Z,resourceBusinessHours:J=[],hideNonBusinessHours:X}=P,Q=24,Y=0,U=!1,q=(L)=>{U=!0,Q=Math.min(Q,L.startTime??9),Y=Math.max(Y,L.endTime??17)},_=(L)=>{nP(Z,{date:L,onMatch:q});for(let z of J)nP(z,{date:L,onMatch:q})};for(let L of $)_(L);if(!U&&X){if(_(),!U)Q=9,Y=17,U=!0}return{minStart:Q,maxEnd:Y,hasBusinessHours:U}};var h2=(P,$,Z)=>{let[J,X]=$.split(":").map(Number),Q=I(P).hour(J).minute(X);return Z?Q.hour(0).minute(0):Q},H5=(P,$,Z)=>{let[J,X]=$.split(":").map(Number),Q=I(P).hour(J).minute(X);return Z?Q.hour(23).minute(59):Q},C2=(P,$)=>{if(!$)return{min:"00:00",max:"23:59"};let Z=I(P),{minStart:J,maxEnd:X,hasBusinessHours:Q}=aP({allDates:[Z],businessHours:$,hideNonBusinessHours:!1});if(!Q)return{min:"00:00",max:"23:59"};return{min:`${J.toString().padStart(2,"0")}:00`,max:`${(X-1).toString().padStart(2,"0")}:45`}};import{useEffect as _$,useMemo as G$,useState as x5}from"react";import{RRule as J0}from"rrule";import{jsx as tP}from"react/jsx-runtime";function b5({className:P,...$}){return tP("div",{className:A("text-card-foreground flex flex-col gap-6 rounded-xl border shadow-sm",P),"data-slot":"card",...$})}function w5({className:P,...$}){return tP("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 m5({className:P,...$}){return tP("div",{className:A("leading-none font-semibold",P),"data-slot":"card-title",...$})}function g5({className:P,...$}){return tP("div",{className:A("p-4 pt-0",P),"data-slot":"card-content",...$})}import*as C from"@radix-ui/react-select";import{CheckIcon as q$,ChevronDownIcon as k5,ChevronUpIcon as U$}from"lucide-react";import{jsx as e,jsxs as E2}from"react/jsx-runtime";function h5({...P}){return e(C.Root,{"data-slot":"select",...P})}function C5({...P}){return e(C.Value,{"data-slot":"select-value",...P})}function E5({className:P,size:$="default",children:Z,...J}){return E2(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",...J,children:[Z,e(C.Icon,{asChild:!0,children:e(k5,{className:"size-4 opacity-50"})})]})}function D5({className:P,children:$,position:Z="popper",align:J="center",...X}){return e(C.Portal,{children:E2(C.Content,{align:J,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,...X,children:[e(z$,{}),e(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:$}),e(K$,{})]})})}function j5({className:P,children:$,...Z}){return E2(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:[e("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:e(C.ItemIndicator,{children:e(q$,{className:"size-4"})})}),e(C.ItemText,{children:$})]})}function z$({className:P,...$}){return e(C.ScrollUpButton,{className:A("flex cursor-default items-center justify-center py-1",P),"data-slot":"select-scroll-up-button",...$,children:e(U$,{className:"size-4"})})}function K$({className:P,...$}){return e(C.ScrollDownButton,{className:A("flex cursor-default items-center justify-center py-1",P),"data-slot":"select-scroll-down-button",...$,children:e(k5,{className:"size-4"})})}import{jsx as x,jsxs as K0,Fragment as W$}from"react/jsx-runtime";var D2={DAILY:J0.DAILY,WEEKLY:J0.WEEKLY,MONTHLY:J0.MONTHLY,YEARLY:J0.YEARLY},L$=Object.fromEntries(Object.entries(D2).map(([P,$])=>[$,P])),v5=[J0.SU,J0.MO,J0.TU,J0.WE,J0.TH,J0.FR,J0.SA],f$=["sun","mon","tue","wed","thu","fri","sat"],A$=[{type:"never",id:"never",labelKey:"never"},{type:"count",id:"after",labelKey:"after"},{type:"until",id:"on",labelKey:"on"}],y5=(P)=>Math.max(1,Number.parseInt(P,10)||1),N$=(P,$)=>{if(!P)return $("customRecurrence");try{let Z=new J0(P).toText();return Z&&!Z.toLowerCase().includes("error")?Z.charAt(0).toUpperCase()+Z.slice(1):$("customRecurrence")}catch{return $("customRecurrence")}},c5=({value:P,onChange:$})=>{let{t:Z}=B((K)=>({t:K.t})),[J,X]=x5(!!P),[Q,Y]=x5(()=>P||null),U=G$(()=>f$.map((K,N)=>({value:v5[N],label:Z(K)})),[Z]);_$(()=>{if(X(!!P),P)Y(P)},[P]);let q=(K)=>{if(!Q)return;let N={...Q,...K};Y(N),$(J?N:null)},_=(K)=>{if(X(K),!K){$(null);return}if(Q){$(Q);return}let N={freq:J0.DAILY,interval:1};Y(N),$(N)},L=(K)=>{let N=Q?.byweekday||[],G=v5[K],O=N.includes(G)?N.filter((M)=>M!==G):[...N,G];q({byweekday:O.length?O:void 0})},z=(K)=>{let N={count:void 0,until:void 0};if(K==="count")N.count=Q?.count||1;if(K==="until")N.until=Q?.until||I().add(1,"month").endOf("day").toDate();q(N)},W=Q?.until?"until":Q?.count?"count":"never",F=L$[Q?.freq??J0.DAILY]||"DAILY",f=Array.isArray(Q?.byweekday)?Q.byweekday:Q?.byweekday?[Q.byweekday]:[];return K0(b5,{"data-testid":"recurrence-editor",children:[K0(w5,{className:"pb-3",children:[K0("div",{className:"flex items-center space-x-2",children:[x(AP,{checked:J,"data-testid":"toggle-recurrence",id:"recurring",onCheckedChange:_}),x(m5,{className:"text-sm",children:Z("repeat")})]}),J&&P&&x("p",{className:"text-xs text-muted-foreground",children:N$(P,Z)})]}),J&&x(g5,{className:"pt-0",children:K0("div",{className:"space-y-4",children:[K0("div",{className:"grid grid-cols-2 gap-4",children:[K0("div",{children:[x(z0,{className:"text-xs",htmlFor:"frequency",children:Z("repeats")}),K0(h5,{onValueChange:(K)=>q({freq:D2[K]}),value:F,children:[x(E5,{className:"h-8","data-testid":"frequency-select",id:"frequency",children:x(C5,{})}),x(D5,{children:Object.keys(D2).map((K)=>x(j5,{value:K,children:Z(K.toLowerCase())},K))})]})]}),K0("div",{children:[x(z0,{className:"text-xs",htmlFor:"interval",children:Z("every")}),x(PP,{className:"h-8",id:"interval",min:"1",onChange:(K)=>q({interval:y5(K.target.value)}),type:"number",value:Q?.interval||1})]})]}),Q?.freq===J0.WEEKLY&&K0("div",{children:[x(z0,{className:"text-xs",children:Z("repeatOn")}),x("div",{className:"flex flex-wrap gap-1 mt-1",children:U.map((K,N)=>K0("div",{className:"flex items-center space-x-1",children:[x(AP,{checked:f.includes(K.value),id:V.listKey("day",N),onCheckedChange:()=>L(N)}),x(z0,{className:"text-xs cursor-pointer",htmlFor:V.listKey("day",N),children:K.label})]},K.label))})]}),K0("div",{children:[x(z0,{className:"text-xs",children:Z("ends")}),x("div",{className:"space-y-2 mt-1",children:A$.map(({type:K,id:N,labelKey:G})=>K0("div",{className:"flex items-center space-x-2",children:[x(AP,{checked:W===K,id:N,onCheckedChange:()=>z(K)}),x(z0,{className:"text-xs",htmlFor:N,children:Z(G)}),K==="count"&&W==="count"&&K0(W$,{children:[x(PP,{className:"h-6 w-16 text-xs","data-testid":"count-input",min:"1",onChange:(O)=>q({count:y5(O.target.value)}),type:"number",value:Q?.count||1}),x("span",{className:"text-xs",children:Z("occurrences")})]}),K==="until"&&W==="until"&&x(rP,{className:"h-6",date:Q?.until??void 0,onChange:(O)=>q({until:O?I(O).endOf("day").toDate():void 0})})]},K))})]})]})})]})};import{useCallback as sP,useState as F$}from"react";var o5={isOpen:!1,operationType:"edit",event:null};function i5(P){let{updateRecurringEvent:$,deleteRecurringEvent:Z}=B((_)=>({updateRecurringEvent:_.updateRecurringEvent,deleteRecurringEvent:_.deleteRecurringEvent})),[J,X]=F$(o5),Q=sP((_,L)=>{X({isOpen:!0,operationType:"edit",event:_,updates:L,onConfirm:(z)=>{$(_,L,{scope:z,eventDate:_.start})}})},[$]),Y=sP((_)=>{X({isOpen:!0,operationType:"delete",event:_,onConfirm:(L)=>{Z(_,{scope:L,eventDate:_.start})}})},[Z]),U=sP(()=>X(o5),[]),q=sP((_)=>{if(J.onConfirm)J.onConfirm(_);U(),P?.()},[J,U,P]);return{dialogState:J,openEditDialog:Q,openDeleteDialog:Y,closeDialog:U,handleConfirm:q}}import{useMemo as O$}from"react";var eP=(P)=>{let{businessHours:$,getResourceById:Z}=B((J)=>({businessHours:J.businessHours,getResourceById:J.getResourceById}));return O$(()=>{if(P!=null&&Z){let J=Z(P);if(J?.businessHours)return J.businessHours}return $},[P,Z,$])};import{jsx as v,jsxs as H0,Fragment as B$}from"react/jsx-runtime";var l5=[{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"}],u5=({selectedEvent:P,onClose:$,onUpdate:Z,onDelete:J,onAdd:X})=>{let{dialogState:Q,openEditDialog:Y,openDeleteDialog:U,closeDialog:q,handleConfirm:_}=i5($),{findParentRecurringEvent:L,t:z,timeFormat:W}=B((T)=>({findParentRecurringEvent:T.findParentRecurringEvent,t:T.t,timeFormat:T.timeFormat})),F=eP(P?.resourceId),f=P?.start??I(),K=P?.end??I().add(1,"hour"),N=P?L(P):null,[G,O]=u0(f.toDate()),[M,p]=u0(K.toDate()),[S,R]=u0(P?.allDay||!1),[b,g]=u0(P?.color||l5[0].value),[D,u]=u0(f.format("HH:mm")),[c,P0]=u0(K.format("HH:mm")),[j,k]=u0({title:P?.title||"",description:P?.description||"",location:P?.location||""}),[o,G0]=u0(()=>{return P?.rrule||N?.rrule||null}),F0=(T)=>{if(!T)return;if(O(T),I(T).isAfter(I(M)))p(T)},M0=(T)=>{if(!T)return;if(p(T),T&&I(T).isBefore(I(G)))O(T)},X0=(T)=>{if(u(T),I(G).isSame(I(M),"day")&&T>c)P0(T)},q0=(T)=>{if(P0(T),I(G).isSame(I(M),"day")&&T<D)u(T)},m0=(T)=>{let{name:d,value:$0}=T.target;k((O0)=>({...O0,[d]:$0}))};V$(()=>{if(S)P0("23:59")},[S]);let L0=(T)=>{T.preventDefault();let d=h2(G,D,S),$0=H5(M,c,S),O0={id:P?.id||I().format("YYYYMMDDHHmmss"),title:j.title,start:d,end:$0,resourceId:P?.resourceId,description:j.description,location:j.location,allDay:S,color:b,rrule:o||void 0};if(P?.id&&GP(P)){Y(P,{title:j.title,start:d,end:$0,description:j.description,location:j.location,allDay:S,color:b,rrule:o||void 0});return}if(P?.id)Z?.(O0);else X?.(O0);$()},Q0=()=>{if(P?.id){if(GP(P)){U(P);return}J?.(P),$()}},a=(T)=>{if(!T){G0(null);return}let d=h2(G,D,S);G0({...T,dtstart:d.toDate()})},s0=F?(T)=>!k2(I(T),F):void 0,i=C2(G,F),p0=C2(M,F),D0=({name:T,placeholder:d,required:$0=!1})=>H0("div",{className:"grid gap-1 sm:gap-2",children:[v(z0,{className:"text-xs sm:text-sm",htmlFor:T,children:z(T)}),v(PP,{className:"h-8 text-sm sm:h-9",id:T,name:T,onChange:m0,placeholder:d,required:$0,value:j[T]})]}),JP=[["startDate",G,F0],["endDate",M,M0]],XP=[["startTime","start-time",D,X0,i],["endTime","end-time",c,q0,p0]];return H0(B$,{children:[H0("form",{className:"flex flex-col flex-1 min-h-0",onSubmit:L0,children:[v(T0,{className:"flex-1 min-h-0",children:H0("div",{className:"grid gap-3 sm:gap-4 p-1",children:[v(D0,{name:"title",placeholder:z("eventTitlePlaceholder"),required:!0}),v(D0,{name:"description",placeholder:z("eventDescriptionPlaceholder")}),H0("div",{className:"flex items-center space-x-2",children:[v(AP,{checked:S,id:"allDay",onCheckedChange:(T)=>R(T===!0)}),v(z0,{className:"text-xs sm:text-sm",htmlFor:"allDay",children:z("allDay")})]}),v("div",{className:"grid grid-cols-2 gap-2 sm:gap-4",children:JP.map(([T,d,$0])=>H0("div",{children:[v(z0,{className:"text-xs sm:text-sm",children:z(T)}),v(rP,{className:"mt-1",closeOnSelect:!0,date:d,disabled:s0,onChange:$0})]},T))}),!S&&v("div",{className:"grid grid-cols-2 gap-2 sm:gap-4",children:XP.map(([T,d,$0,O0,H])=>H0("div",{children:[v(z0,{className:"text-xs sm:text-sm",children:z(T)}),v(S5,{className:"mt-1 h-8 text-sm sm:h-9",maxTime:H.max,minTime:H.min,name:d,onChange:O0,placeholder:z("searchTime"),timeFormat:W,value:$0})]},T))}),H0("div",{className:"grid gap-1 sm:gap-2",children:[v(z0,{className:"text-xs sm:text-sm",children:z("color")}),v("div",{className:"flex flex-wrap gap-2",children:l5.map((T)=>v(h,{"aria-label":T.label,className:A(`${T.value} h-6 w-6 rounded-full sm:h-8 sm:w-8`,b===T.value&&"ring-2 ring-black ring-offset-1 sm:ring-offset-2"),onClick:()=>g(T.value),type:"button",variant:"ghost"},T.value))})]}),v(D0,{name:"location",placeholder:z("eventLocationPlaceholder")}),v(c5,{onChange:a,value:o})]})}),H0(DP,{className:"mt-4 shrink-0 flex flex-col-reverse gap-2 sm:flex-row sm:gap-0",children:[P?.id&&v(h,{className:"w-full sm:mr-auto sm:w-auto",onClick:Q0,size:"sm",type:"button",variant:"destructive",children:z("delete")}),H0("div",{className:"flex w-full gap-2 sm:w-auto",children:[v(h,{className:"flex-1 sm:flex-none",onClick:$,size:"sm",type:"button",variant:"outline",children:z("cancel")}),v(h,{className:"flex-1 sm:flex-none",size:"sm",type:"submit",children:P?.id?z("update"):z("create")})]})]})]}),v(SP,{eventTitle:Q.event?.title||"",isOpen:Q.isOpen,onClose:q,onConfirm:_,operationType:Q.operationType})]})};import{jsx as P2,jsxs as d5}from"react/jsx-runtime";var $2=()=>{let{t:P,selectedEvent:$,isEventFormOpen:Z,closeEventForm:J,addEvent:X,updateEvent:Q,deleteEvent:Y,renderEventForm:U}=B((z)=>({t:z.t,selectedEvent:z.selectedEvent,isEventFormOpen:z.isEventFormOpen,closeEventForm:z.closeEventForm,addEvent:z.addEvent,updateEvent:z.updateEvent,deleteEvent:z.deleteEvent,renderEventForm:z.renderEventForm})),L={open:Z,onClose:J,selectedEvent:$,onAdd:X,onUpdate:(z)=>{Q(z.id,z)},onDelete:(z)=>{Y(z.id)}};if(U)return U(L);return P2(UP,{onOpenChange:J,open:Z,children:d5(zP,{className:"flex flex-col h-[90vh] w-[90vw] max-w-[500px] p-4 sm:p-6 overflow-hidden gap-0",children:[d5(KP,{className:"mb-2 sm:mb-4 shrink-0",children:[P2(_P,{className:"text-base sm:text-lg",children:$?.id?P("editEvent"):P("createEvent")}),P2(jP,{className:"text-xs sm:text-sm",children:$?.id?P("editEventDetails"):P("addNewEvent")})]}),P2(u5,{...L})]})})};import{Calendar as j$,Download as x$,Menu as v$,Plus as y$}from"lucide-react";import{useState as c$}from"react";import{RRule as M$}from"rrule";var j2=`\r `,p$=["BEGIN:VTIMEZONE","TZID:UTC","BEGIN:STANDARD","DTSTART:19700101T000000","TZNAME:UTC","TZOFFSETFROM:+0000","TZOFFSETTO:+0000","END:STANDARD","END:VTIMEZONE"].join(j2),J2=(P)=>{return P.replaceAll("\\","\\\\").replaceAll(";","\\;").replaceAll(",","\\,").replaceAll(` `,"\\n").replaceAll("\r","")},Z2=(P,$=!1)=>{return $?P.format("YYYYMMDD"):P.utc().format("YYYYMMDD[T]HHmmss[Z]")},r5=(P)=>{return P.uid||`${P.id}@ilamy.calendar`},R$=(P)=>{try{return new M$(P).toString(