UNPKG

@ilamy/calendar

Version:

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

1 lines 586 kB
import{RRule as YX}from"rrule";import{RRule as E2}from"rrule";import W0 from"dayjs";import b2 from"dayjs/plugin/isBetween.js";import I2 from"dayjs/plugin/isSameOrAfter.js";import w2 from"dayjs/plugin/isSameOrBefore.js";import H2 from"dayjs/plugin/localeData.js";import T2 from"dayjs/plugin/minMax.js";import k2 from"dayjs/plugin/timezone.js";import h2 from"dayjs/plugin/utc.js";import g2 from"dayjs/plugin/weekday.js";import C2 from"dayjs/plugin/weekOfYear.js";W0.extend(g2);W0.extend(C2);W0.extend(I2);W0.extend(w2);W0.extend(b2);W0.extend(T2);W0.extend(k2);W0.extend(h2);W0.extend(H2);var F=W0;import{clsx as D2}from"clsx";import{twMerge as y2}from"tailwind-merge";function U(...P){return y2(D2(P))}function PP(P){if(P===void 0)return;if(F.isDayjs(P))return P;let f=F(P);return f.isValid()?f:void 0}var Hf=(P,f)=>{let $={...P};for(let J of f)delete $[J];return $};function kP(P){if(!P||!P.length)return[];return P.map((f)=>{return{...f,start:F.isDayjs(f.start)?f.start:F(f.start),end:F.isDayjs(f.end)?f.end:F(f.end)}})}var hP=(P)=>{return new Date(Date.UTC(P.year(),P.month(),P.date(),P.hour(),P.minute(),P.second(),P.millisecond()))},j2=(P,f)=>{return f.year(P.getUTCFullYear()).month(P.getUTCMonth()).date(P.getUTCDate()).hour(P.getUTCHours()).minute(P.getUTCMinutes()).second(P.getUTCSeconds()).millisecond(P.getUTCMilliseconds())},fP=(P)=>{return Boolean(P.rrule||P.recurrenceId||P.uid)},O0=(P)=>{return P.uid||`${P.id}@ilamy.calendar`},Jf=({event:P,currentEvents:f,startDate:$,endDate:J})=>{if(!P.rrule)return[];try{let X=hP(P.start),z=P.rrule.until?hP(F(P.rrule.until)):void 0,Q={...P.rrule,dtstart:X,until:z},Y=new E2(Q),Z=O0(P),q=f.filter((_)=>_.recurrenceId&&O0(_)===Z),G=P.end.diff(P.start),p=hP($.subtract(G,"millisecond")),O=hP(J);return Y.between(p,O,!0).map((_,N)=>{let L=j2(_,P.start),W=q.find((h)=>PP(h.recurrenceId)?.isSame(L));if(W)return{...P,...W};let V=P.end.diff(P.start),B=L.add(V,"millisecond"),R=`${P.id}_${N}`,S=O0(P);return{...P,id:R,start:L,end:B,uid:S,rrule:void 0}}).filter((_)=>{if(P.exdates&&P.exdates.length>0){let W=_.start.toISOString();if(P.exdates.includes(W))return!1}return _.start.isSameOrBefore(J)&&_.end.isSameOrAfter($)})}catch(X){throw Error(`Invalid RRULE options: ${JSON.stringify(P.rrule)}. Error: ${X instanceof Error?X.message:"Unknown error"}`)}},Tf=({targetEvent:P,updates:f,currentEvents:$,scope:J})=>{let X=[...$],z=O0(P),Q=X.findIndex((Z)=>{return O0(Z)===z&&Z.rrule&&!Z.recurrenceId});if(Q===-1)throw Error("Base recurring event not found");let Y=X[Q];switch(J){case"this":{let Z=P.start.toISOString(),G=[...Y.exdates||[],Z],p={...Y,exdates:G};X[Q]=p;let O=`${P.id}_modified_${Date.now()}`,A={...Hf(P,["width","height","top","left","right"]),...f,id:O,recurrenceId:Z,uid:O0(Y),rrule:void 0};X.push(A);break}case"following":{let q=P.start.subtract(1,"day").endOf("day").toDate(),G={...Y,rrule:{...Y.rrule,until:q}};X[Q]=G;let p=Y.end.diff(Y.start),O=f.start||P.start,A=f.end||O.add(p),K=`${Y.id}_following`,_=`${K}@ilamy.calendar`,N={...Y,...f,rrule:{...Y.rrule,...f.rrule,dtstart:O.toDate()},id:K,uid:_,start:O,end:A,recurrenceId:void 0};X.push(N);break}case"all":{let Z={...Y,...f};X[Q]=Z;break}default:throw Error(`Invalid scope: ${J}. Must be 'this', 'following', or 'all'`)}return X},kf=({targetEvent:P,currentEvents:f,scope:$})=>{let J=[...f],X=O0(P),z=J.findIndex((Y)=>{return O0(Y)===X&&Y.rrule&&!Y.recurrenceId});if(z===-1)throw Error("Base recurring event not found");let Q=J[z];switch($){case"this":{let Y=P.start.toISOString(),q=[...Q.exdates||[],Y],G={...Q,exdates:q};J[z]=G;break}case"following":{let Z=P.start.subtract(1,"day").endOf("day").toDate(),q={...Q,rrule:{...Q.rrule,until:Z}};J[z]=q;break}case"all":{let Y=O0(P);return J.filter((q)=>O0(q)!==Y)}default:throw Error(`Invalid scope: ${$}. Must be 'this', 'following', or 'all'`)}return J};import{AnimatePresence as x2,motion as v2}from"motion/react";import{jsx as hf}from"react/jsx-runtime";var i2={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}})},y=({children:P,transitionKey:f,delay:$=0,className:J,direction:X="vertical",layout:z,layoutId:Q,"data-testid":Y,ref:Z,...q})=>hf(x2,{mode:"wait",children:hf(v2.div,{animate:"visible",className:U("inline-block w-full",J),custom:{delay:$,direction:X},"data-testid":Y,exit:"exit",initial:"hidden",layout:z,layoutId:Q,ref:Z,variants:i2,...q,children:P},f)});y.displayName="AnimatedSection";import{DndContext as J1,MouseSensor as X1,pointerWithin as q1,TouchSensor as Q1,useSensor as nf,useSensors as Y1}from"@dnd-kit/core";import{useRef as tf,useState as _1}from"react";import{Slot as o2}from"@radix-ui/react-slot";import{cva as l2}from"class-variance-authority";import{jsx as c2}from"react/jsx-runtime";var gP=l2("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:f,size:$,asChild:J=!1,...X}){return c2(J?o2:"button",{className:U(gP({variant:f,size:$,className:P})),"data-slot":"button",...X})}import*as Z0 from"@radix-ui/react-dialog";import{XIcon as u2}from"lucide-react";import{jsx as F0,jsxs as Xf}from"react/jsx-runtime";function $P({...P}){return F0(Z0.Root,{"data-slot":"dialog",...P})}function d2({...P}){return F0(Z0.Portal,{"data-slot":"dialog-portal",...P})}function r2({className:P,...f}){return F0(Z0.Overlay,{className:U("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",...f})}function zP({className:P,children:f,...$}){return Xf(d2,{"data-slot":"dialog-portal",children:[F0(r2,{}),Xf(Z0.Content,{className:U("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",...$,children:[f,Xf(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:[F0(u2,{}),F0("span",{className:"sr-only",children:"Close"})]})]})]})}function ZP({className:P,...f}){return F0("div",{className:U("flex flex-col gap-2 text-center sm:text-left",P),"data-slot":"dialog-header",...f})}function CP({className:P,...f}){return F0("div",{className:U("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",P),"data-slot":"dialog-footer",...f})}function JP({className:P,...f}){return F0(Z0.Title,{className:U("text-lg leading-none font-semibold",P),"data-slot":"dialog-title",...f})}function DP({className:P,...f}){return F0(Z0.Description,{className:U("text-muted-foreground text-sm",P),"data-slot":"dialog-description",...f})}import{useContext as uf}from"react";import{createContext as a2,useContext as gf}from"react";var XP=a2(void 0),U0=()=>{let P=gf(XP);if(P===void 0)throw Error("useCalendarContext must be used within a CalendarProvider");return P},n2=()=>{let P=gf(XP);if(P===void 0)throw Error("useIlamyCalendarContext must be used within a CalendarProvider");return{currentDate:P.currentDate,view:P.view,events:P.events,isEventFormOpen:P.isEventFormOpen,selectedEvent:P.selectedEvent,selectedDate:P.selectedDate,firstDayOfWeek:P.firstDayOfWeek,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,businessHours:P.businessHours}};import{createContext as t2,useContext as Cf}from"react";var qP=t2(void 0),o=()=>{let P=Cf(qP);if(P===void 0)throw Error("useResourceCalendarContext must be used within a ResourceCalendarProvider");return P},s2=()=>{let P=Cf(qP);if(P===void 0)throw Error("useIlamyResourceCalendarContext must be used within a ResourceCalendarProvider");return{currentDate:P.currentDate,view:P.view,events:P.events,resources:P.resources,isEventFormOpen:P.isEventFormOpen,selectedEvent:P.selectedEvent,selectedDate:P.selectedDate,firstDayOfWeek:P.firstDayOfWeek,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{useCallback as Y0,useMemo as e2,useState as of}from"react";import{useCallback as P0,useEffect as Qf,useMemo as xf,useState as a0}from"react";var qf={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",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 J0(P,f){let $=P.startOf("week").day(f),J=P.isBefore($)?$.subtract(1,"week"):$;return Array.from({length:7},(X,z)=>J.add(z,"day"))}function yP(P,f){let $=J0(P.startOf("month"),f);return Array.from({length:6},(J,X)=>{let z=$[0].add(X,"week");return J0(z,f)})}function Df(P){let f=P.daysInMonth();return Array.from({length:f},($,J)=>P.startOf("month").add(J,"day"))}function yf({referenceDate:P=F(),length:f=24}={}){return Array.from({length:f},($,J)=>P.hour(J).minute(0).second(0).millisecond(0))}var H0=1,Ef=24,G0=24,QP=4,jf="bg-secondary text-muted-foreground pointer-events-none",YP={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};var vf={day:"day",week:"week",month:"month",year:"year"},EP=(P)=>{let{events:f=[],firstDayOfWeek:$=0,initialView:J="month",initialDate:X=F(),businessHours:z,onEventAdd:Q,onEventUpdate:Y,onEventDelete:Z,onDateChange:q,onViewChange:G,locale:p,timezone:O,translations:A,translator:K}=P,[_,N]=a0(X),[L,W]=a0(J),[V,B]=a0(f),[R,S]=a0(!1),[k,h]=a0(null),[C,D]=a0(null),[l,u]=a0(p||"en"),d=xf(()=>{if(K)return K;if(A)return(M)=>A[M]||M;return(M)=>qf[M]||M},[A,K]),c=P0((M,H)=>{let j=[];for(let r of V)if(r.rrule)j.push(...Jf({event:r,currentEvents:V,startDate:M,endDate:H}));else{let r0=r.start.isSameOrAfter(M)&&r.start.isSameOrBefore(H),Zf=r.end.isSameOrAfter(M)&&r.end.isSameOrBefore(H),T=r.start.isBefore(M)&&r.end.isAfter(H);if(r0||Zf||T)j.push(r)}return j},[V]),w=P0(()=>{if(L==="day")return{start:_.startOf("day"),end:_.endOf("day")};if(L==="year")return{start:_.startOf("year"),end:_.endOf("year")};if(L==="week"){let H=J0(_,$);return{start:H[0].startOf("day"),end:H[6].endOf("day")}}let M=yP(_,$);return{start:M[0][0].startOf("day"),end:M[5][6].endOf("day")}},[_,L,$]),b=xf(()=>{let{start:M,end:H}=w();return c(M,H)},[c,w]);Qf(()=>{if(f)B(f)},[f]),Qf(()=>{if(p)u(p),F.locale(p),N((M)=>M.locale(p))},[p]),Qf(()=>{if(O)F.tz.setDefault(O)},[O]);let p0=P0((M)=>{N(M),q?.(M)},[q]),Q0=P0((M)=>{N((H)=>{let j=M===1?H.add(1,vf[L]):H.subtract(1,vf[L]);return q?.(j),j})},[L,q]),z0=P0(()=>Q0(1),[Q0]),N0=P0(()=>Q0(-1),[Q0]),t=P0(()=>{let M=F();N(M),q?.(M)},[q]),i=P0((M)=>{B((H)=>[...H,M]),Q?.(M)},[Q]),t0=P0((M,H)=>{B((j)=>j.map((r)=>{if(r.id!==M)return r;let r0={...r,...H};return Y?.(r0),r0}))},[Y]),s0=P0((M,H,j)=>{Y?.({...M,...H}),B(Tf({targetEvent:M,updates:H,currentEvents:V,scope:j.scope}))},[V,Y]),e0=P0((M,H)=>{Z?.(M),B(kf({targetEvent:M,currentEvents:V,scope:H.scope}))},[V,Z]),S0=P0((M)=>{B((H)=>{let j=H.find((r)=>r.id===M);if(j)Z?.(j);return H.filter((r)=>r.id!==M)})},[Z]),c0=P0((M)=>{if(M?.start)D(M.start);let H=M?.start??_;h({title:d("newEvent"),start:H,end:M?.end??H.add(1,"hour"),resourceId:M?.resourceId,description:"",allDay:M?.allDay??!1}),S(!0)},[_,d]),u0=P0(()=>{D(null),h(null),S(!1)},[]),d0=P0((M)=>{W(M),G?.(M)},[G]),m=P0((M)=>{let H=M.uid;return V.find((j)=>(j.uid||`${j.id}@ilamy.calendar`)===H&&j.rrule)||null},[V]);return{currentDate:_,view:L,events:b,rawEvents:V,isEventFormOpen:R,selectedEvent:k,selectedDate:C,firstDayOfWeek:$,dayMaxEvents:QP,currentLocale:l,businessHours:z,setCurrentDate:N,selectDate:p0,setView:d0,nextPeriod:z0,prevPeriod:N0,today:t,addEvent:i,updateEvent:t0,updateRecurringEvent:s0,deleteEvent:S0,deleteRecurringEvent:e0,openEventForm:c0,closeEventForm:u0,setSelectedEvent:h,setIsEventFormOpen:S,setSelectedDate:D,getEventsForDateRange:c,findParentRecurringEvent:m,t:d}};import{jsx as P1}from"react/jsx-runtime";var lf=(P)=>{if(P.resourceIds)return P.resourceIds;if(P.resourceId!==void 0)return[P.resourceId];return[]},cf=({children:P,events:f=[],resources:$=[],firstDayOfWeek:J=0,initialView:X="month",initialDate:z,renderEvent:Q,onEventClick:Y,onCellClick:Z,onViewChange:q,onEventAdd:G,onEventUpdate:p,onEventDelete:O,onDateChange:A,locale:K,timezone:_,disableCellClick:N,disableEventClick:L,disableDragAndDrop:W,dayMaxEvents:V,eventSpacing:B,stickyViewHeader:R=!0,viewHeaderClassName:S="",headerComponent:k,headerClassName:h,translations:C,translator:D,renderResource:l,renderEventForm:u,businessHours:d,timeFormat:c="12-hour",classesOverride:w,orientation:b="horizontal",renderCurrentTimeIndicator:p0,hideNonBusinessHours:Q0=!1})=>{let[z0]=of($),[N0,t]=of(new Set($.map((T)=>T.id))),i=EP({events:f,firstDayOfWeek:J,initialView:X,initialDate:z,businessHours:d,onEventAdd:G,onEventUpdate:p,onEventDelete:O,onDateChange:A,onViewChange:q,locale:K,timezone:_,translations:C,translator:D}),t0=Y0((T)=>{t((e)=>{let w0=new Set(e);if(w0.has(T))w0.delete(T);else w0.add(T);return w0})},[]),s0=Y0((T)=>{t((e)=>new Set(e).add(T))},[]),e0=Y0((T)=>{t((e)=>{let w0=new Set(e);return w0.delete(T),w0})},[]),S0=Y0(()=>{t(new Set(z0.map((T)=>T.id)))},[z0]),c0=Y0(()=>{t(new Set)},[]),u0=Y0((T)=>{return i.events.filter((e)=>{if(e.resourceIds)return e.resourceIds.includes(T);return e.resourceId===T})},[i.events]),d0=Y0((T)=>{return i.events.filter((e)=>{return lf(e).some((m2)=>T.includes(m2))})},[i.events]),m=Y0((T)=>{return z0.find((e)=>e.id===T)},[z0]),M=Y0(()=>{return z0.filter((T)=>N0.has(T.id))},[z0,N0]),H=Y0((T)=>{return Boolean(T.resourceIds&&T.resourceIds.length>1)},[]),j=Y0((T)=>{i.setSelectedEvent(T),i.setIsEventFormOpen(!0)},[i]),r=Y0((T)=>{if(L)return;if(Y)Y(T);else j(T)},[L,Y,j]),r0=Y0((T)=>{if(N)return;if(Z)Z(T);else{let e={title:i.t("newEvent"),start:T.start,end:T.end,description:"",allDay:!1};if(T.resourceId!==void 0)e.resourceId=T.resourceId;i.setSelectedEvent(e),i.setSelectedDate(T.start),i.setIsEventFormOpen(!0)}},[Z,N,i]),Zf=e2(()=>({...i,view:i.view,setView:i.setView,events:i.events,rawEvents:i.rawEvents,resources:z0,visibleResources:N0,toggleResourceVisibility:t0,showResource:s0,hideResource:e0,showAllResources:S0,hideAllResources:c0,getEventsForResource:u0,getEventsForResources:d0,getResourceById:m,getVisibleResources:M,isEventCrossResource:H,getEventResourceIds:lf,onEventClick:r,onCellClick:r0,headerComponent:k,headerClassName:h,renderEvent:Q,renderResource:l,renderEventForm:u,locale:K,timezone:_,disableCellClick:N,disableEventClick:L,disableDragAndDrop:W,dayMaxEvents:V,eventSpacing:B,stickyViewHeader:R,viewHeaderClassName:S,businessHours:d,timeFormat:c,classesOverride:w,orientation:b,renderCurrentTimeIndicator:p0,hideNonBusinessHours:Q0}),[i,z0,N0,t0,s0,e0,S0,c0,u0,d0,m,M,H,r,r0,Q,l,u,K,_,N,L,W,V,B,R,S,k,h,d,c,w,b,p0,Q0]);return P1(qP.Provider,{value:Zf,children:P})};function I(P){let f=uf(qP),$=uf(XP);if(f)return P(f);if($)return P($);throw Error("useSmartCalendarContext must be used within a CalendarProvider or ResourceCalendarProvider")}import{jsx as _0,jsxs as n0}from"react/jsx-runtime";function OP({isOpen:P,onClose:f,onConfirm:$,operationType:J,eventTitle:X}){let{t:z}=I((Z)=>({t:Z.t})),Q=(Z)=>{$(Z),f()},Y=J==="edit";return _0($P,{onOpenChange:f,open:P,children:n0(zP,{className:"max-w-md",children:[n0(ZP,{children:[_0(JP,{children:Y?z("editRecurringEvent"):z("deleteRecurringEvent")}),n0(DP,{children:['"',X,'"'," ",Y?z("editRecurringEventQuestion"):z("deleteRecurringEventQuestion")]})]}),n0("div",{className:"space-y-3",children:[_0(g,{className:"w-full justify-start h-auto p-4",onClick:()=>Q("this"),variant:"outline",children:n0("div",{className:"text-left",children:[_0("div",{className:"font-medium",children:z("thisEvent")}),_0("div",{className:"text-sm text-muted-foreground",children:Y?z("onlyChangeThis"):z("onlyDeleteThis")})]})}),_0(g,{className:"w-full justify-start h-auto p-4",onClick:()=>Q("following"),variant:"outline",children:n0("div",{className:"text-left",children:[_0("div",{className:"font-medium",children:z("thisAndFollowingEvents")}),_0("div",{className:"text-sm text-muted-foreground",children:Y?z("changeThisAndFuture"):z("deleteThisAndFuture")})]})}),_0(g,{className:"w-full justify-start h-auto p-4",onClick:()=>Q("all"),variant:"outline",children:n0("div",{className:"text-left",children:[_0("div",{className:"font-medium",children:z("allEvents")}),_0("div",{className:"text-sm text-muted-foreground",children:Y?z("changeEntireSeries"):z("deleteEntireSeries")})]})})]}),_0(CP,{children:_0(g,{onClick:f,variant:"outline",children:z("cancel")})})]})})}var df=(P,f)=>{let{active:$,over:J}=P;if(!$||!J||!f)return null;let X=J.data.current?.type==="time-cell",{resourceId:z,allDay:Q}=J.data.current||{},Y;if(X){let{date:p,hour:O=0,minute:A=0}=J.data.current;Y=F(p).hour(O).minute(A)}else{let{date:p}=J.data.current;Y=F(p)}let Z=f.end.diff(f.start,"second"),q=Y.add(Z,"second");if(q.isSame(q.startOf("day")))q=q.subtract(1,"day").endOf("day");let G={start:Y,end:q,resourceId:z,allDay:X?!1:Q??f.allDay};return{activeEvent:f,updates:G}};import{DragOverlay as f1}from"@dnd-kit/core";import{snapCenterToCursor as $1}from"@dnd-kit/modifiers";import{useImperativeHandle as z1,useState as Z1}from"react";import{jsx as rf}from"react/jsx-runtime";var af=({ref:P})=>{let[f,$]=Z1(null);return z1(P,()=>({setActiveEvent:$})),rf(f1,{modifiers:[$1],children:f&&rf("div",{className:U("cursor-grab truncate rounded bg-amber-200 p-2 text-[10px] shadow-lg sm:text-xs w-20",f.backgroundColor||"bg-blue-500",f.color||"text-white"),children:f?.title})})};import{jsx as sf,jsxs as ef,Fragment as K1}from"react/jsx-runtime";function jP({children:P}){let f=tf(null),$=tf(null),{updateEvent:J,updateRecurringEvent:X,disableDragAndDrop:z}=I((L)=>({updateEvent:L.updateEvent,updateRecurringEvent:L.updateRecurringEvent,disableDragAndDrop:L.disableDragAndDrop})),[Q,Y]=_1({isOpen:!1,event:null,updates:null}),Z=nf(X1,{activationConstraint:{distance:2}}),q=nf(Q1,{activationConstraint:{delay:100,tolerance:5}}),G=Y1(Z,q),p=(L,W)=>{if(!L||!L.id)return;if(!W||Object.keys(W).length===0)return;if(fP(L))Y({isOpen:!0,event:L,updates:W});else J(L.id,W)},O=(L)=>{if(!Q.event||!Q.updates){Y({isOpen:!1,event:null,updates:null});return}try{X(Q.event,Q.updates,{scope:L,eventDate:Q.event.start})}catch{}finally{Y({isOpen:!1,event:null,updates:null})}},A=()=>{Y({isOpen:!1,event:null,updates:null})},K=(L)=>{let{active:W}=L;if(W.data.current?.type==="calendar-event")$.current?.setActiveEvent(W.data.current.event),f.current=W.data.current.event},_=(L)=>{let W=df(L,f.current);if(W){let{activeEvent:V,updates:B}=W;p(V,B)}f.current=null,$.current?.setActiveEvent(null)},N=(L)=>{f.current=null};if(z)return P;return ef(K1,{children:[ef(J1,{collisionDetection:q1,onDragCancel:N,onDragEnd:_,onDragStart:K,sensors:G,children:[P,sf(af,{ref:$})]}),sf(OP,{eventTitle:Q.event?.title||"",isOpen:Q.isOpen,onClose:A,onConfirm:O,operationType:"edit"})]})}import{useEffect as x1,useMemo as v1,useState as y0}from"react";import*as xP from"@radix-ui/react-checkbox";import{CheckIcon as p1}from"lucide-react";import{jsx as Yf}from"react/jsx-runtime";function T0({className:P,...f}){return Yf(xP.Root,{className:U("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",...f,children:Yf(xP.Indicator,{className:"flex items-center justify-center text-current transition-none","data-slot":"checkbox-indicator",children:Yf(p1,{className:"size-3.5"})})})}import{PopoverClose as W1}from"@radix-ui/react-popover";import{Calendar as O1}from"lucide-react";import{useEffect as F1,useRef as V1,useState as B1}from"react";import{ChevronDownIcon as U1,ChevronLeftIcon as L1,ChevronRightIcon as G1}from"lucide-react";import*as vP from"react";import{DayPicker as A1,getDefaultClassNames as P5}from"react-day-picker";import{jsx as k0}from"react/jsx-runtime";function f5({className:P,classNames:f,showOutsideDays:$=!0,captionLayout:J="label",buttonVariant:X="ghost",formatters:z,components:Q,...Y}){let Z=P5();return k0(A1,{captionLayout:J,className:U("bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,P),classNames:{root:U("w-fit",Z.root),months:U("flex gap-4 flex-col md:flex-row relative",Z.months),month:U("flex flex-col w-full gap-4",Z.month),nav:U("flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",Z.nav),button_previous:U(gP({variant:X}),"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",Z.button_previous),button_next:U(gP({variant:X}),"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",Z.button_next),month_caption:U("flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",Z.month_caption),dropdowns:U("w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",Z.dropdowns),dropdown_root:U("relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",Z.dropdown_root),dropdown:U("absolute bg-popover inset-0 opacity-0",Z.dropdown),caption_label:U("select-none font-medium",J==="label"?"text-sm":"rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",Z.caption_label),table:"w-full border-collapse",weekdays:U("flex",Z.weekdays),weekday:U("text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",Z.weekday),week:U("flex w-full mt-2",Z.week),week_number_header:U("select-none w-(--cell-size)",Z.week_number_header),week_number:U("text-[0.8rem] select-none text-muted-foreground",Z.week_number),day:U("relative w-full h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",Y.showWeekNumber?"[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"[&:first-child[data-selected=true]_button]:rounded-l-md",Z.day),range_start:U("rounded-l-md bg-accent",Z.range_start),range_middle:U("rounded-none",Z.range_middle),range_end:U("rounded-r-md bg-accent",Z.range_end),today:U("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",Z.today),outside:U("text-muted-foreground aria-selected:text-muted-foreground",Z.outside),disabled:U("text-muted-foreground opacity-50",Z.disabled),hidden:U("invisible",Z.hidden),...f},components:{Root:({className:q,rootRef:G,...p})=>{return k0("div",{className:U(q),"data-slot":"calendar",ref:G,...p})},Chevron:({className:q,orientation:G,...p})=>{if(G==="left")return k0(L1,{className:U("size-4",q),...p});if(G==="right")return k0(G1,{className:U("size-4",q),...p});return k0(U1,{className:U("size-4",q),...p})},DayButton:N1,WeekNumber:({children:q,...G})=>{return k0("td",{...G,children:k0("div",{className:"flex size-(--cell-size) items-center justify-center text-center",children:q})})},...Q},formatters:{formatMonthDropdown:(q)=>q.toLocaleString("default",{month:"short"}),...z},showOutsideDays:$,...Y})}function N1({className:P,day:f,modifiers:$,...J}){let X=P5(),z=vP.useRef(null);return vP.useEffect(()=>{if($.focused)z.current?.focus()},[$.focused]),k0(g,{className:U("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",X.day,P),"data-day":f.date.toLocaleDateString(),"data-range-end":$.range_end,"data-range-middle":$.range_middle,"data-range-start":$.range_start,"data-selected-single":$.selected&&!$.range_start&&!$.range_end&&!$.range_middle,ref:z,size:"icon",variant:"ghost",...J})}import*as R0 from"@radix-ui/react-popover";import{jsx as iP}from"react/jsx-runtime";function h0({...P}){return iP(R0.Root,{"data-slot":"popover",...P})}function g0({...P}){return iP(R0.Trigger,{"data-slot":"popover-trigger",...P})}function C0({className:P,align:f="center",sideOffset:$=4,...J}){return iP(R0.Portal,{children:iP(R0.Content,{align:f,className:U("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:$,...J})})}import{jsx as _P,jsxs as _f}from"react/jsx-runtime";function FP({date:P,closeOnSelect:f,onChange:$,label:J="Pick a date",className:X,disabled:z}){let Q=V1(null),[Y,Z]=B1(P);F1(()=>{Z(P)},[P]);let q=(G)=>{if(Z(G),f)Q.current?.click();$?.(G)};return _P("div",{className:X,children:_f(h0,{children:[_P(g0,{asChild:!0,children:_f(g,{className:U("data-[empty=true]:text-muted-foreground w-full justify-start text-left font-normal"),"data-empty":!P,variant:"outline",children:[_P(O1,{}),Y?F(Y).format("MMM D, YYYY"):_P("span",{children:J})]})}),_f(C0,{align:"start",className:"w-auto p-0",children:[_P(W1,{ref:Q}),_P(f5,{captionLayout:"dropdown",defaultMonth:Y,disabled:z,mode:"single",onSelect:q,selected:Y})]})]})})}import{jsx as M1}from"react/jsx-runtime";function m0({className:P,type:f,...$}){return M1("input",{className:U("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:f,...$})}import*as $5 from"@radix-ui/react-label";import{jsx as S1}from"react/jsx-runtime";function a({className:P,...f}){return S1($5.Root,{className:U("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",...f})}import*as V0 from"@radix-ui/react-scroll-area";import{jsx as VP,jsxs as R1}from"react/jsx-runtime";function B0({className:P,children:f,viewPortProps:$,...J}){return R1(V0.Root,{className:U("relative",P),"data-slot":"scroll-area",...J,children:[VP(V0.Viewport,{...$,className:U("focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",$?.className),"data-slot":"scroll-area-viewport",children:f}),VP(b0,{}),VP(V0.Corner,{})]})}function b0({className:P,orientation:f="vertical",...$}){return VP(V0.ScrollAreaScrollbar,{className:U("flex touch-none p-px transition-colors select-none",f==="vertical"&&"h-full w-2.5 border-l border-l-transparent",f==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent",P),"data-slot":"scroll-area-scrollbar",orientation:f,...$,children:VP(V0.ScrollAreaThumb,{className:"bg-border relative flex-1 rounded-full","data-slot":"scroll-area-thumb"})})}import{Clock as b1}from"lucide-react";import{useEffect as I1,useRef as Z5,useState as Kf}from"react";import{useMemo as m1}from"react";function z5({timeFormat:P="12-hour",minTime:f="00:00",maxTime:$="23:45"}){return{timeOptions:m1(()=>{let z=[],[Q,Y]=f.split(":").map(Number),[Z,q]=$.split(":").map(Number),G=Q*60+Y,p=Z*60+q;for(let O=G;O<=p;O+=15){let A=Math.floor(O/60),K=O%60,_=`${A.toString().padStart(2,"0")}:${K.toString().padStart(2,"0")}`;z.push(_)}return z},[f,$]),formatTime:(z)=>{let[Q,Y]=z.split(":").map(Number),Z=Q>=12?"PM":"AM",q=Q===0?12:Q>12?Q-12:Q;if(P==="24-hour")return`${Q.toString().padStart(2,"0")}:${Y.toString().padStart(2,"0")}`;return`${q}:${Y.toString().padStart(2,"0")} ${Z}`}}}import{jsx as D0,jsxs as pf}from"react/jsx-runtime";var w1=(P)=>{P.stopPropagation()};function Uf({value:P,onChange:f,minTime:$="00:00",maxTime:J="23:45",timeFormat:X="12-hour",placeholder:z="Select time...",className:Q,disabled:Y=!1,name:Z}){let[q,G]=Kf(!1),[p,O]=Kf(""),A=Z5(null),K=Z5(null),[_,N]=Kf(0),{timeOptions:L,formatTime:W}=z5({timeFormat:X,minTime:$,maxTime:J}),V=L.filter((S)=>{return W(S).toLowerCase().includes(p.toLowerCase())}),B=(S)=>{f(S),G(!1),O("")};I1(()=>{if(q){if(K.current)N(K.current.offsetWidth);setTimeout(()=>{A.current?.focus()},0)}},[q]);let R=P?W(P):z;return pf(h0,{onOpenChange:G,open:q,children:[D0(g0,{asChild:!0,children:pf(g,{"aria-controls":"time-picker-listbox","aria-expanded":q,className:U("w-full justify-start",Q),"data-testid":`time-picker-${Z}`,disabled:Y,ref:K,role:"combobox",variant:"outline",children:[D0(b1,{className:"mr-2 h-4 w-4"}),R]})}),pf(C0,{align:"start",className:"p-0",style:{width:_},children:[D0("div",{className:"p-2 border-b",children:D0(m0,{className:"h-8",onChange:(S)=>O(S.target.value),placeholder:"Search time...",ref:A,value:p})}),D0(B0,{className:"h-[200px]",onWheel:w1,children:D0("div",{className:"p-1",children:V.length===0?D0("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"N/A"}):V.map((S)=>{let k=W(S);return D0("button",{className:U("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:()=>B(S),type:"button",children:k},S)})})})]})]})}var Lf=(P,f)=>{if(!f)return!0;let $=!1;return KP(f,{date:P,onMatch:()=>{$=!0}}),$},J5=({date:P,hour:f,minute:$=0,businessHours:J})=>{if(!J)return!0;if(f===void 0)return Lf(P,J);let X=!1,z=f*60+$;return KP(J,{date:P,onMatch:(Q)=>{let Y=Q.startTime??9,Z=Q.endTime??17,q=Y*60,G=Z*60;if(z>=q&&z<G)X=!0}}),X},KP=(P,f)=>{let{date:$,onMatch:J}=f;if(!P)return;let X=Array.isArray(P)?P:[P];for(let z of X)if($&&z.daysOfWeek){let Q=$.day();if(z.daysOfWeek.some((Y)=>YP[Y]===Q))J(z)}else J(z)},oP=(P)=>{let{allDates:f,businessHours:$,resourceBusinessHours:J=[],hideNonBusinessHours:X}=P,z=24,Q=0,Y=!1,Z=(q)=>{Y=!0,z=Math.min(z,q.startTime??9),Q=Math.max(Q,q.endTime??17)};for(let q of f){KP($,{date:q,onMatch:Z});for(let G of J)KP(G,{date:q,onMatch:Z})}if(!Y&&X){KP($,{onMatch:Z});for(let q of J)KP(q,{onMatch:Z});if(!Y)z=9,Q=17,Y=!0}return{minStart:z,maxEnd:Q,hasBusinessHours:Y}};var Gf=(P,f,$)=>{let[J,X]=f.split(":").map(Number),z=F(P).hour(J).minute(X);return $?z.hour(0).minute(0):z},X5=(P,f,$)=>{let[J,X]=f.split(":").map(Number),z=F(P).hour(J).minute(X);return $?z.hour(23).minute(59):z},Af=(P,f)=>{if(!f)return{min:"00:00",max:"23:59"};let $=F(P),{minStart:J,maxEnd:X,hasBusinessHours:z}=oP({allDates:[$],businessHours:f,hideNonBusinessHours:!1});if(!z)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 g1,useMemo as C1,useState as N5}from"react";import{RRule as q0}from"rrule";import{jsx as lP}from"react/jsx-runtime";function q5({className:P,...f}){return lP("div",{className:U("text-card-foreground flex flex-col gap-6 rounded-xl border shadow-sm",P),"data-slot":"card",...f})}function Q5({className:P,...f}){return lP("div",{className:U("@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",...f})}function Y5({className:P,...f}){return lP("div",{className:U("leading-none font-semibold",P),"data-slot":"card-title",...f})}function _5({className:P,...f}){return lP("div",{className:U("p-4 pt-0",P),"data-slot":"card-content",...f})}import*as E from"@radix-ui/react-select";import{CheckIcon as H1,ChevronDownIcon as K5,ChevronUpIcon as T1}from"lucide-react";import{jsx as f0,jsxs as Nf}from"react/jsx-runtime";function p5({...P}){return f0(E.Root,{"data-slot":"select",...P})}function U5({...P}){return f0(E.Value,{"data-slot":"select-value",...P})}function L5({className:P,size:f="default",children:$,...J}){return Nf(E.Trigger,{className:U("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":f,"data-slot":"select-trigger",...J,children:[$,f0(E.Icon,{asChild:!0,children:f0(K5,{className:"size-4 opacity-50"})})]})}function G5({className:P,children:f,position:$="popper",align:J="center",...X}){return f0(E.Portal,{children:Nf(E.Content,{align:J,className:U("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-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",$==="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:$,...X,children:[f0(k1,{}),f0(E.Viewport,{className:U("p-1",$==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:f}),f0(h1,{})]})})}function A5({className:P,children:f,...$}){return Nf(E.Item,{className:U("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",...$,children:[f0("span",{className:"absolute right-2 flex size-3.5 items-center justify-center",children:f0(E.ItemIndicator,{children:f0(H1,{className:"size-4"})})}),f0(E.ItemText,{children:f})]})}function k1({className:P,...f}){return f0(E.ScrollUpButton,{className:U("flex cursor-default items-center justify-center py-1",P),"data-slot":"select-scroll-up-button",...f,children:f0(T1,{className:"size-4"})})}function h1({className:P,...f}){return f0(E.ScrollDownButton,{className:U("flex cursor-default items-center justify-center py-1",P),"data-slot":"select-scroll-down-button",...f,children:f0(K5,{className:"size-4"})})}import{jsx as x,jsxs as X0}from"react/jsx-runtime";var Wf={DAILY:q0.DAILY,WEEKLY:q0.WEEKLY,MONTHLY:q0.MONTHLY,YEARLY:q0.YEARLY},D1=Object.fromEntries(Object.entries(Wf).map(([P,f])=>[f,P])),W5=[q0.SU,q0.MO,q0.TU,q0.WE,q0.TH,q0.FR,q0.SA],y1=["sun","mon","tue","wed","thu","fri","sat"],O5=(P)=>Math.max(1,Number.parseInt(P,10)||1),E1=(P,f)=>{if(!P)return f("customRecurrence");try{let $=new q0(P).toText();return $&&!$.toLowerCase().includes("error")?$.charAt(0).toUpperCase()+$.slice(1):f("customRecurrence")}catch{return f("customRecurrence")}},F5=({value:P,onChange:f})=>{let{t:$}=I((_)=>({t:_.t})),[J,X]=N5(!!P),[z,Q]=N5(()=>P||null),Y=C1(()=>y1.map((_,N)=>({value:W5[N],label:$(_)})),[$]);g1(()=>{if(X(!!P),P)Q(P)},[P]);let Z=(_)=>{if(!z)return;let N={...z,..._};Q(N),f(J?N:null)},q=(_)=>{if(X(_),!_){f(null);return}if(z){f(z);return}let N={freq:q0.DAILY,interval:1};Q(N),f(N)},G=(_)=>{let N=z?.byweekday||[],L=W5[_],W=N.includes(L)?N.filter((V)=>V!==L):[...N,L];Z({byweekday:W.length?W:void 0})},p=(_)=>{let N={count:void 0,until:void 0};if(_==="count")N.count=z?.count||1;if(_==="until")N.until=z?.until||F().add(1,"month").endOf("day").toDate();Z(N)},O=z?.until?"until":z?.count?"count":"never",A=D1[z?.freq??q0.DAILY]||"DAILY",K=Array.isArray(z?.byweekday)?z.byweekday:z?.byweekday?[z.byweekday]:[];return X0(q5,{"data-testid":"recurrence-editor",children:[X0(Q5,{className:"pb-3",children:[X0("div",{className:"flex items-center space-x-2",children:[x(T0,{checked:J,"data-testid":"toggle-recurrence",id:"recurring",onCheckedChange:q}),x(Y5,{className:"text-sm",children:$("repeat")})]}),J&&P&&x("p",{className:"text-xs text-muted-foreground",children:E1(P,$)})]}),J&&x(_5,{className:"pt-0",children:X0("div",{className:"space-y-4",children:[X0("div",{className:"grid grid-cols-2 gap-4",children:[X0("div",{children:[x(a,{className:"text-xs",htmlFor:"frequency",children:$("repeats")}),X0(p5,{onValueChange:(_)=>Z({freq:Wf[_]}),value:A,children:[x(L5,{className:"h-8","data-testid":"frequency-select",id:"frequency",children:x(U5,{})}),x(G5,{children:Object.keys(Wf).map((_)=>x(A5,{value:_,children:$(_.toLowerCase())},_))})]})]}),X0("div",{children:[x(a,{className:"text-xs",htmlFor:"interval",children:$("every")}),x(m0,{className:"h-8",id:"interval",min:"1",onChange:(_)=>Z({interval:O5(_.target.value)}),type:"number",value:z?.interval||1})]})]}),z?.freq===q0.WEEKLY&&X0("div",{children:[x(a,{className:"text-xs",children:$("repeatOn")}),x("div",{className:"flex flex-wrap gap-1 mt-1",children:Y.map((_,N)=>X0("div",{className:"flex items-center space-x-1",children:[x(T0,{checked:K.includes(_.value),id:`day-${N}`,onCheckedChange:()=>G(N)}),x(a,{className:"text-xs cursor-pointer",htmlFor:`day-${N}`,children:_.label})]},_.label))})]}),X0("div",{children:[x(a,{className:"text-xs",children:$("ends")}),X0("div",{className:"space-y-2 mt-1",children:[X0("div",{className:"flex items-center space-x-2",children:[x(T0,{checked:O==="never",id:"never",onCheckedChange:()=>p("never")}),x(a,{className:"text-xs",htmlFor:"never",children:$("never")})]}),X0("div",{className:"flex items-center space-x-2",children:[x(T0,{checked:O==="count",id:"after",onCheckedChange:()=>p("count")}),x(a,{className:"text-xs",htmlFor:"after",children:$("after")}),O==="count"&&x(m0,{className:"h-6 w-16 text-xs","data-testid":"count-input",min:"1",onChange:(_)=>Z({count:O5(_.target.value)}),type:"number",value:z?.count||1}),x("span",{className:"text-xs",children:$("occurrences")})]}),X0("div",{className:"flex items-center space-x-2",children:[x(T0,{checked:O==="until",id:"on",onCheckedChange:()=>p("until")}),x(a,{className:"text-xs",htmlFor:"on",children:$("on")}),O==="until"&&x(FP,{className:"h-6",date:z?.until,onChange:(_)=>Z({until:_?F(_).endOf("day").toDate():void 0})})]})]})]})]})})]})};import{useCallback as cP,useState as j1}from"react";function V5(P){let{updateRecurringEvent:f,deleteRecurringEvent:$}=I((q)=>({updateRecurringEvent:q.updateRecurringEvent,deleteRecurringEvent:q.deleteRecurringEvent})),[J,X]=j1({isOpen:!1,operationType:"edit",event:null}),z=cP((q,G)=>{X({isOpen:!0,operationType:"edit",event:q,updates:G,onConfirm:(p)=>{f(q,G,{scope:p,eventDate:q.start})}})},[f]),Q=cP((q)=>{X({isOpen:!0,operationType:"delete",event:q,onConfirm:(G)=>{$(q,{scope:G,eventDate:q.start})}})},[$]),Y=cP(()=>{X({isOpen:!1,operationType:"edit",event:null})},[]),Z=cP((q)=>{if(J.onConfirm)J.onConfirm(q);Y(),P?.()},[J,Y,P]);return{dialogState:J,openEditDialog:z,openDeleteDialog:Q,closeDialog:Y,handleConfirm:Z}}import{jsx as v,jsxs as $0,Fragment as i1}from"react/jsx-runtime";var B5=[{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"}],M5=({selectedEvent:P,onClose:f,onUpdate:$,onDelete:J,onAdd:X})=>{let{dialogState:z,openEditDialog:Q,openDeleteDialog:Y,closeDialog:Z,handleConfirm:q}=V5(f),{findParentRecurringEvent:G,t:p,businessHours:O,timeFormat:A,getResourceById:K}=I((m)=>({findParentRecurringEvent:m.findParentRecurringEvent,t:m.t,businessHours:m.businessHours,timeFormat:m.timeFormat,getResourceById:m.getResourceById})),_=P?.start??F(),N=P?.end??F().add(1,"hour"),L=P?G(P):null,[W,V]=y0(_.toDate()),[B,R]=y0(N.toDate()),[S,k]=y0(P?.allDay||!1),[h,C]=y0(P?.color||B5[0].value),[D,l]=y0(_.format("HH:mm")),[u,d]=y0(N.format("HH:mm")),[c,w]=y0({title:P?.title||"",description:P?.description||"",location:P?.location||""}),[b,p0]=y0(()=>{return P?.rrule||L?.rrule||null}),Q0=(m)=>{if(V(m),m&&F(m).isAfter(F(B)))R(m)},z0=(m)=>{if(R(m),m&&F(m).isBefore(F(W)))V(m)},N0=(m)=>{if(l(m),F(W).isSame(F(B),"day")&&m>u)d(m)},t=(m)=>{if(d(m),F(W).isSame(F(B),"day")&&m<D)l(m)},i=(m)=>{let{name:M,value:H}=m.target;w((j)=>({...j,[M]:H}))};x1(()=>{if(S)d("23:59")},[S]);let t0=(m)=>{m.preventDefault();let M=Gf(W,D,S),H=X5(B,u,S),j={id:P?.id||F().format("YYYYMMDDHHmmss"),title:c.title,start:M,end:H,resourceId:P?.resourceId,description:c.description,location:c.location,allDay:S,color:h,rrule:b||void 0};if(P?.id&&fP(P)){Q(P,{title:c.title,start:M,end:H,description:c.description,location:c.location,allDay:S,color:h,rrule:b||void 0});return}if(P?.id)$?.(j);else X?.(j);f()},s0=()=>{if(P?.id){if(fP(P)){Y(P);return}J?.(P),f()}},e0=(m)=>{if(!m){p0(null);return}let M=Gf(W,D,S);p0({...m,dtstart:M.toDate()})},S0=v1(()=>{let m=P?.resourceId;if(m&&K){let M=K(m);if(M?.businessHours)return M.businessHours}return O},[P?.resourceId,K,O]),c0=S0?(m)=>!Lf(F(m),S0):void 0,u0=Af(W,S0),d0=Af(B,S0);return $0(i1,{children:[$0("form",{className:"flex flex-col flex-1 min-h-0",onSubmit:t0,children:[v(B0,{className:"flex-1 min-h-0",children:$0("div",{className:"grid gap-3 sm:gap-4 p-1",children:[$0("div",{className:"grid gap-2",children:[v(a,{className:"text-xs sm:text-sm",htmlFor:"title",children:p("title")}),v(m0,{className:"h-8 text-sm sm:h-9",id:"title",name:"title",onChange:i,placeholder:p("eventTitlePlaceholder"),required:!0,value:c.title})]}),$0("div",{className:"grid gap-1 sm:gap-2",children:[v(a,{className:"text-xs sm:text-sm",htmlFor:"description",children:p("description")}),v(m0,{className:"h-8 text-sm sm:h-9",id:"description",name:"description",onChange:i,placeholder:p("eventDescriptionPlaceholder"),value:c.description})]}),$0("div",{className:"flex items-center space-x-2",children:[v(T0,{checked:S,id:"allDay",onCheckedChange:(m)=>k(m===!0)}),v(a,{className:"text-xs sm:text-sm",htmlFor:"allDay",children:p("allDay")})]}),$0("div",{className:"grid grid-cols-2 gap-2 sm:gap-4",children:[$0("div",{children:[v(a,{className:"text-xs sm:text-sm",children:p("startDate")}),v(FP,{className:"mt-1",closeOnSelect:!0,date:W,disabled:c0,onChange:Q0})]}),$0("div",{children:[v(a,{className:"text-xs sm:text-sm",children:p("endDate")}),v(FP,{className:"mt-1",closeOnSelect:!0,date:B,disabled:c0,onChange:z0})]})]}),!S&&$0("div",{className:"grid grid-cols-2 gap-2 sm:gap-4",children:[$0("div",{children:[v(a,{className:"text-xs sm:text-sm",children:p("startTime")}),v(Uf,{className:"mt-1 h-8 text-sm sm:h-9",maxTime:u0.max,minTime:u0.min,name:"start-time",onChange:N0,timeFormat:A,value:D})]}),$0("div",{children:[v(a,{className:"text-xs sm:text-sm",children:p("endTime")}),v(Uf,{className:"mt-1 h-8 text-sm sm:h-9",maxTime:d0.max,minTime:d0.min,name:"end-time",onChange:t,timeFormat:A,value:u})]})]}),$0("div",{className:"grid gap-1 sm:gap-2",children:[v(a,{className:"text-xs sm:text-sm",children:p("color")}),v("div",{className:"flex flex-wrap gap-2",children:B5.map((m)=>v(g,{"aria-label":m.label,className:U(`${m.value} h-6 w-6 rou