@mlw-packages/react-components 1.7.18 → 1.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -12163,7 +12163,7 @@ function AgendaView({
12163
12163
  onEventSelect,
12164
12164
  showUndatedEvents = false
12165
12165
  }) {
12166
- const isValidDate3 = (d) => {
12166
+ const isValidDate6 = (d) => {
12167
12167
  try {
12168
12168
  const t = d instanceof Date ? d.getTime() : new Date(String(d)).getTime();
12169
12169
  return !isNaN(t);
@@ -12172,11 +12172,11 @@ function AgendaView({
12172
12172
  }
12173
12173
  };
12174
12174
  const datedEvents = useMemo9(
12175
- () => events.filter((e) => isValidDate3(e.start) && isValidDate3(e.end)),
12175
+ () => events.filter((e) => isValidDate6(e.start) && isValidDate6(e.end)),
12176
12176
  [events]
12177
12177
  );
12178
12178
  const undatedEvents = useMemo9(
12179
- () => events.filter((e) => !(isValidDate3(e.start) && isValidDate3(e.end))),
12179
+ () => events.filter((e) => !(isValidDate6(e.start) && isValidDate6(e.end))),
12180
12180
  [events]
12181
12181
  );
12182
12182
  const days = useMemo9(() => {
@@ -15410,14 +15410,2309 @@ function debounce(func, wait) {
15410
15410
  };
15411
15411
  }
15412
15412
 
15413
+ // src/components/event-calendar-view/Agenda.tsx
15414
+ import { addDays as addDays4, format as format11, isToday as isToday4 } from "date-fns";
15415
+ import { ptBR as ptBR10 } from "date-fns/locale";
15416
+ import { useMemo as useMemo19 } from "react";
15417
+ import { CalendarIcon as CalendarIcon5 } from "@phosphor-icons/react";
15418
+ import { twMerge as twMerge2 } from "tailwind-merge";
15419
+ import { Fragment as Fragment14, jsx as jsx86, jsxs as jsxs66 } from "react/jsx-runtime";
15420
+ function Agenda({
15421
+ currentDate,
15422
+ events,
15423
+ onEventSelect,
15424
+ showUndatedEvents = true
15425
+ }) {
15426
+ const isValidDate6 = (d) => {
15427
+ try {
15428
+ const t = d instanceof Date ? d.getTime() : new Date(String(d)).getTime();
15429
+ return !isNaN(t);
15430
+ } catch {
15431
+ return false;
15432
+ }
15433
+ };
15434
+ const datedEvents = useMemo19(
15435
+ () => events.filter(
15436
+ (e) => isValidDate6(e.start) && isValidDate6(e.end) || isValidDate6(e.attend_date)
15437
+ ),
15438
+ [events]
15439
+ );
15440
+ const undatedEvents = useMemo19(
15441
+ () => events.filter(
15442
+ (e) => !(isValidDate6(e.start) && isValidDate6(e.end)) && !isValidDate6(e.attend_date)
15443
+ ),
15444
+ [events]
15445
+ );
15446
+ const days = useMemo19(() => {
15447
+ console.log("Agenda view updating with date:", currentDate.toISOString());
15448
+ return Array.from(
15449
+ { length: AgendaDaysToShowAgenda },
15450
+ (_, i) => addDays4(new Date(currentDate), i)
15451
+ );
15452
+ }, [currentDate]);
15453
+ const handleEventClick = (event, e) => {
15454
+ e.stopPropagation();
15455
+ console.log("Agenda view event clicked:", event);
15456
+ if (onEventSelect) onEventSelect(event);
15457
+ };
15458
+ const hasEvents = days.some(
15459
+ (day) => getAgendaEventsForDayAgenda(datedEvents, day).length > 0
15460
+ );
15461
+ return /* @__PURE__ */ jsx86("div", { className: "border-border/70 border-t px-4", children: !hasEvents && !(showUndatedEvents && undatedEvents.length > 0) ? /* @__PURE__ */ jsxs66("div", { className: "flex min-h-[70svh] flex-col items-center justify-center py-16 text-center", children: [
15462
+ /* @__PURE__ */ jsx86(CalendarIcon5, { className: "mb-2 text-muted-foreground/50", size: 32 }),
15463
+ /* @__PURE__ */ jsx86("h3", { className: "font-medium text-lg", children: "Nenhum evento encontrado" }),
15464
+ /* @__PURE__ */ jsx86("p", { className: "text-muted-foreground", children: "N\xE3o h\xE1 eventos agendados para este per\xEDodo." })
15465
+ ] }) : /* @__PURE__ */ jsxs66(Fragment14, { children: [
15466
+ days.map((day) => {
15467
+ const dayEvents = getAgendaEventsForDayAgenda(datedEvents, day);
15468
+ if (dayEvents.length === 0) return null;
15469
+ return /* @__PURE__ */ jsxs66(
15470
+ "div",
15471
+ {
15472
+ className: twMerge2("relative my-12 border-border/70 border-t", isToday4(day) ? "border-blue-200" : ""),
15473
+ children: [
15474
+ /* @__PURE__ */ jsx86(
15475
+ "span",
15476
+ {
15477
+ className: twMerge2("-top-3 absolute left-0 flex h-6 items-center bg-background pe-4 uppercase data-today:font-extrabold sm:pe-4 text-lg font-bold", isToday4(day) ? "text-blue-500" : ""),
15478
+ "data-today": isToday4(day) || void 0,
15479
+ children: (() => {
15480
+ const s = format11(day, "d MMM, EEEE", { locale: ptBR10 });
15481
+ return s.split(" ").map((w) => w ? w[0].toUpperCase() + w.slice(1) : w).join(" ");
15482
+ })()
15483
+ }
15484
+ ),
15485
+ /* @__PURE__ */ jsx86("div", { className: "mt-6 space-y-2", children: dayEvents.map((event) => /* @__PURE__ */ jsx86(
15486
+ EventItemAgenda,
15487
+ {
15488
+ event,
15489
+ onClick: onEventSelect ? (e) => handleEventClick(event, e) : void 0,
15490
+ view: "agenda",
15491
+ className: onEventSelect ? void 0 : "cursor-default hover:shadow-none hover:scale-100"
15492
+ },
15493
+ event.id
15494
+ )) })
15495
+ ]
15496
+ },
15497
+ day.toString()
15498
+ );
15499
+ }),
15500
+ /* @__PURE__ */ jsx86(
15501
+ UndatedEvents,
15502
+ {
15503
+ events,
15504
+ onEventSelect,
15505
+ show: showUndatedEvents,
15506
+ className: "my-12"
15507
+ }
15508
+ )
15509
+ ] }) });
15510
+ }
15511
+
15512
+ // src/components/event-calendar-view/CalendarDND.tsx
15513
+ import {
15514
+ DndContext as DndContext2,
15515
+ DragOverlay as DragOverlay2,
15516
+ MouseSensor as MouseSensor2,
15517
+ PointerSensor as PointerSensor2,
15518
+ TouchSensor as TouchSensor2,
15519
+ useSensor as useSensor2,
15520
+ useSensors as useSensors2
15521
+ } from "@dnd-kit/core";
15522
+ import { addMinutes as addMinutes2, differenceInMinutes as differenceInMinutes5 } from "date-fns";
15523
+ import { useId as useId3, useRef as useRef15, useState as useState31 } from "react";
15524
+
15525
+ // src/components/event-calendar-view/hooks.ts
15526
+ import { createContext as createContext7, useContext as useContext8 } from "react";
15527
+ var CalendarDndContext2 = createContext7({
15528
+ activeEvent: null,
15529
+ activeId: null,
15530
+ activeView: null,
15531
+ currentTime: null,
15532
+ dragHandlePosition: null,
15533
+ eventHeight: null,
15534
+ isMultiDay: false,
15535
+ multiDayWidth: null
15536
+ });
15537
+ var useCalendarDndAgenda = () => useContext8(CalendarDndContext2);
15538
+
15539
+ // src/components/event-calendar-view/CalendarDND.tsx
15540
+ import { jsx as jsx87, jsxs as jsxs67 } from "react/jsx-runtime";
15541
+ function CalendarDndProviderAgenda({
15542
+ children,
15543
+ onEventUpdate
15544
+ }) {
15545
+ const [activeEvent, setActiveEvent] = useState31(null);
15546
+ const [activeId, setActiveId] = useState31(null);
15547
+ const [activeView, setActiveView] = useState31(
15548
+ null
15549
+ );
15550
+ const [currentTime, setCurrentTime] = useState31(null);
15551
+ const [eventHeight, setEventHeight] = useState31(null);
15552
+ const [isMultiDay, setIsMultiDay] = useState31(false);
15553
+ const [multiDayWidth, setMultiDayWidth] = useState31(null);
15554
+ const [dragHandlePosition, setDragHandlePosition] = useState31(null);
15555
+ const eventDimensions = useRef15({ height: 0 });
15556
+ const sensors = useSensors2(
15557
+ useSensor2(MouseSensor2, {
15558
+ // Require the mouse to move by 5px before activating
15559
+ activationConstraint: {
15560
+ distance: 5
15561
+ }
15562
+ }),
15563
+ useSensor2(TouchSensor2, {
15564
+ // Press delay of 250ms, with tolerance of 5px of movement
15565
+ activationConstraint: {
15566
+ delay: 250,
15567
+ tolerance: 5
15568
+ }
15569
+ }),
15570
+ useSensor2(PointerSensor2, {
15571
+ // Require the pointer to move by 5px before activating
15572
+ activationConstraint: {
15573
+ distance: 5
15574
+ }
15575
+ })
15576
+ );
15577
+ const dndContextId = useId3();
15578
+ const handleDragStart = (event) => {
15579
+ const { active } = event;
15580
+ if (!active.data.current) {
15581
+ console.error("Missing data in drag start event", event);
15582
+ return;
15583
+ }
15584
+ const {
15585
+ event: calendarEvent,
15586
+ view,
15587
+ height,
15588
+ isMultiDay: eventIsMultiDay,
15589
+ multiDayWidth: eventMultiDayWidth,
15590
+ dragHandlePosition: eventDragHandlePosition
15591
+ } = active.data.current;
15592
+ setActiveEvent(calendarEvent);
15593
+ setActiveId(active.id);
15594
+ setActiveView(view);
15595
+ setCurrentTime(calendarEvent.start ? new Date(calendarEvent.start) : null);
15596
+ setIsMultiDay(eventIsMultiDay || false);
15597
+ setMultiDayWidth(eventMultiDayWidth || null);
15598
+ setDragHandlePosition(eventDragHandlePosition || null);
15599
+ if (height) {
15600
+ eventDimensions.current.height = height;
15601
+ setEventHeight(height);
15602
+ }
15603
+ };
15604
+ const handleDragOver = (event) => {
15605
+ const { over } = event;
15606
+ if (over && activeEvent && over.data.current) {
15607
+ const { date, time } = over.data.current;
15608
+ if (time !== void 0 && activeView !== "month") {
15609
+ const newTime = new Date(date);
15610
+ const hours = Math.floor(time);
15611
+ const fractionalHour = time - hours;
15612
+ let minutes = 0;
15613
+ if (fractionalHour < 0.125) minutes = 0;
15614
+ else if (fractionalHour < 0.375) minutes = 15;
15615
+ else if (fractionalHour < 0.625) minutes = 30;
15616
+ else minutes = 45;
15617
+ newTime.setHours(hours, minutes, 0, 0);
15618
+ if (!currentTime || newTime.getHours() !== currentTime.getHours() || newTime.getMinutes() !== currentTime.getMinutes() || newTime.getDate() !== currentTime.getDate() || newTime.getMonth() !== currentTime.getMonth() || newTime.getFullYear() !== currentTime.getFullYear()) {
15619
+ setCurrentTime(newTime);
15620
+ }
15621
+ } else if (activeView === "month") {
15622
+ const newTime = new Date(date);
15623
+ if (currentTime) {
15624
+ newTime.setHours(
15625
+ currentTime.getHours(),
15626
+ currentTime.getMinutes(),
15627
+ currentTime.getSeconds(),
15628
+ currentTime.getMilliseconds()
15629
+ );
15630
+ }
15631
+ if (!currentTime || newTime.getDate() !== currentTime.getDate() || newTime.getMonth() !== currentTime.getMonth() || newTime.getFullYear() !== currentTime.getFullYear()) {
15632
+ setCurrentTime(newTime);
15633
+ }
15634
+ }
15635
+ }
15636
+ };
15637
+ const handleDragEnd = (event) => {
15638
+ const { active, over } = event;
15639
+ if (!over || !activeEvent || !currentTime) {
15640
+ setActiveEvent(null);
15641
+ setActiveId(null);
15642
+ setActiveView(null);
15643
+ setCurrentTime(null);
15644
+ setEventHeight(null);
15645
+ setIsMultiDay(false);
15646
+ setMultiDayWidth(null);
15647
+ setDragHandlePosition(null);
15648
+ return;
15649
+ }
15650
+ try {
15651
+ if (!active.data.current || !over.data.current) {
15652
+ throw new Error("Missing data in drag event");
15653
+ }
15654
+ const activeData = active.data.current;
15655
+ const overData = over.data.current;
15656
+ if (!activeData.event || !overData.date) {
15657
+ throw new Error("Missing required event data");
15658
+ }
15659
+ const calendarEvent = activeData.event;
15660
+ const date = overData.date;
15661
+ const time = overData.time;
15662
+ const newStart = new Date(date);
15663
+ if (time !== void 0) {
15664
+ const hours = Math.floor(time);
15665
+ const fractionalHour = time - hours;
15666
+ let minutes = 0;
15667
+ if (fractionalHour < 0.125) minutes = 0;
15668
+ else if (fractionalHour < 0.375) minutes = 15;
15669
+ else if (fractionalHour < 0.625) minutes = 30;
15670
+ else minutes = 45;
15671
+ newStart.setHours(hours, minutes, 0, 0);
15672
+ } else {
15673
+ newStart.setHours(
15674
+ currentTime.getHours(),
15675
+ currentTime.getMinutes(),
15676
+ currentTime.getSeconds(),
15677
+ currentTime.getMilliseconds()
15678
+ );
15679
+ }
15680
+ if (!calendarEvent.start || !calendarEvent.end) {
15681
+ console.error("Cannot compute duration: event start or end is null", calendarEvent);
15682
+ return;
15683
+ }
15684
+ const originalStart = new Date(calendarEvent.start);
15685
+ const originalEnd = new Date(calendarEvent.end);
15686
+ const durationMinutes = differenceInMinutes5(originalEnd, originalStart);
15687
+ const newEnd = addMinutes2(newStart, durationMinutes);
15688
+ const hasStartTimeChanged = originalStart.getFullYear() !== newStart.getFullYear() || originalStart.getMonth() !== newStart.getMonth() || originalStart.getDate() !== newStart.getDate() || originalStart.getHours() !== newStart.getHours() || originalStart.getMinutes() !== newStart.getMinutes();
15689
+ if (hasStartTimeChanged) {
15690
+ onEventUpdate({
15691
+ ...calendarEvent,
15692
+ end: newEnd,
15693
+ start: newStart
15694
+ });
15695
+ }
15696
+ } catch (error) {
15697
+ console.error("Error in drag end handler:", error);
15698
+ } finally {
15699
+ setActiveEvent(null);
15700
+ setActiveId(null);
15701
+ setActiveView(null);
15702
+ setCurrentTime(null);
15703
+ setEventHeight(null);
15704
+ setIsMultiDay(false);
15705
+ setMultiDayWidth(null);
15706
+ setDragHandlePosition(null);
15707
+ }
15708
+ };
15709
+ return /* @__PURE__ */ jsx87(
15710
+ DndContext2,
15711
+ {
15712
+ id: dndContextId,
15713
+ onDragEnd: handleDragEnd,
15714
+ onDragOver: handleDragOver,
15715
+ onDragStart: handleDragStart,
15716
+ sensors,
15717
+ children: /* @__PURE__ */ jsxs67(
15718
+ CalendarDndContext2.Provider,
15719
+ {
15720
+ value: {
15721
+ activeEvent,
15722
+ activeId,
15723
+ activeView,
15724
+ currentTime,
15725
+ dragHandlePosition,
15726
+ eventHeight,
15727
+ isMultiDay,
15728
+ multiDayWidth
15729
+ },
15730
+ children: [
15731
+ children,
15732
+ /* @__PURE__ */ jsx87(DragOverlay2, { adjustScale: false, dropAnimation: null, children: activeEvent && activeView && /* @__PURE__ */ jsx87(
15733
+ "div",
15734
+ {
15735
+ style: {
15736
+ height: eventHeight ? `${eventHeight}px` : "auto",
15737
+ width: isMultiDay && multiDayWidth ? `${multiDayWidth}%` : "100%"
15738
+ },
15739
+ children: /* @__PURE__ */ jsx87(
15740
+ EventItemAgenda,
15741
+ {
15742
+ currentTime: currentTime || void 0,
15743
+ event: activeEvent,
15744
+ isDragging: true,
15745
+ isFirstDay: dragHandlePosition?.data?.isFirstDay !== false,
15746
+ isLastDay: dragHandlePosition?.data?.isLastDay !== false,
15747
+ showTime: activeView !== "month",
15748
+ view: activeView
15749
+ }
15750
+ )
15751
+ }
15752
+ ) })
15753
+ ]
15754
+ }
15755
+ )
15756
+ }
15757
+ );
15758
+ }
15759
+
15760
+ // src/components/event-calendar-view/constants.ts
15761
+ var EventHeightAgenda = 24;
15762
+ var EventGapAgenda = 4;
15763
+ var WeekCellsHeightAgenda = 64;
15764
+ var AgendaDaysToShowAgenda = 30;
15765
+ var StartHourAgenda = 0;
15766
+ var EndHourAgenda = 24;
15767
+ var DefaultStartHourAgenda = 9;
15768
+ var DefaultEndHourAgenda = 10;
15769
+
15770
+ // src/components/event-calendar-view/DayView.tsx
15771
+ import {
15772
+ addHours as addHours5,
15773
+ areIntervalsOverlapping as areIntervalsOverlapping3,
15774
+ differenceInMinutes as differenceInMinutes7,
15775
+ eachHourOfInterval as eachHourOfInterval3,
15776
+ format as format13,
15777
+ getHours as getHours3,
15778
+ getMinutes as getMinutes3,
15779
+ isSameDay as isSameDay9,
15780
+ startOfDay as startOfDay3,
15781
+ endOfDay
15782
+ } from "date-fns";
15783
+ import { useMemo as useMemo21 } from "react";
15784
+
15785
+ // src/components/event-calendar-view/utils.ts
15786
+ import { isSameDay as isSameDay7 } from "date-fns";
15787
+ import { addHours as addHours4 } from "date-fns";
15788
+ function getEventColorClassesAgenda(color) {
15789
+ const eventColor = color || "sky";
15790
+ switch (eventColor) {
15791
+ case "sky":
15792
+ return "bg-sky-200/50 hover:bg-sky-200/40 text-sky-950/80 dark:bg-sky-400/25 dark:hover:bg-sky-400/20 dark:text-sky-200 shadow-sky-700/8";
15793
+ case "amber":
15794
+ return "bg-amber-200/50 hover:bg-amber-200/40 text-amber-950/80 dark:bg-amber-400/25 dark:hover:bg-amber-400/20 dark:text-amber-200 shadow-amber-700/8";
15795
+ case "violet":
15796
+ return "bg-violet-200/50 hover:bg-violet-200/40 text-violet-950/80 dark:bg-violet-400/25 dark:hover:bg-violet-400/20 dark:text-violet-200 shadow-violet-700/8";
15797
+ case "rose":
15798
+ return "bg-rose-200/50 hover:bg-rose-200/40 text-rose-950/80 dark:bg-rose-400/25 dark:hover:bg-rose-400/20 dark:text-rose-200 shadow-rose-700/8";
15799
+ case "emerald":
15800
+ return "bg-emerald-200/50 hover:bg-emerald-200/40 text-emerald-950/80 dark:bg-emerald-400/25 dark:hover:bg-emerald-400/20 dark:text-emerald-200 shadow-emerald-700/8";
15801
+ case "orange":
15802
+ return "bg-orange-200/50 hover:bg-orange-200/40 text-orange-950/80 dark:bg-orange-400/25 dark:hover:bg-orange-400/20 dark:text-orange-200 shadow-orange-700/8";
15803
+ default:
15804
+ return "bg-sky-200/50 hover:bg-sky-200/40 text-sky-950/80 dark:bg-sky-400/25 dark:hover:bg-sky-400/20 dark:text-sky-200 shadow-sky-700/8";
15805
+ }
15806
+ }
15807
+ function getBorderRadiusClassesAgenda(isFirstDay, isLastDay) {
15808
+ if (isFirstDay && isLastDay) {
15809
+ return "rounded";
15810
+ }
15811
+ if (isFirstDay) {
15812
+ return "rounded-l rounded-r-none";
15813
+ }
15814
+ if (isLastDay) {
15815
+ return "rounded-r rounded-l-none";
15816
+ }
15817
+ return "rounded-none";
15818
+ }
15819
+ function isMultiDayEventAgenda(event) {
15820
+ const eventStart = isValidDate3(event.start) ? new Date(event.start) : void 0;
15821
+ const eventEnd = isValidDate3(event.end) ? new Date(event.end) : void 0;
15822
+ if (!eventStart || !eventEnd) return !!event.allDay;
15823
+ return event.allDay || eventStart.getDate() !== eventEnd.getDate();
15824
+ }
15825
+ function getEventsForDayAgenda(events, day) {
15826
+ return events.filter((event) => {
15827
+ const eventStart = isValidDate3(event.start) ? new Date(event.start) : isValidDate3(event.attend_date) ? normalizeAttendDate(event.attend_date) : void 0;
15828
+ return eventStart ? isSameDay7(day, eventStart) : false;
15829
+ }).sort((a, b) => getEventStartTimestamp2(a) - getEventStartTimestamp2(b));
15830
+ }
15831
+ function sortEventsAgenda(events) {
15832
+ return [...events].sort((a, b) => {
15833
+ const aIsMultiDay = isMultiDayEventAgenda(a);
15834
+ const bIsMultiDay = isMultiDayEventAgenda(b);
15835
+ if (aIsMultiDay && !bIsMultiDay) return -1;
15836
+ if (!aIsMultiDay && bIsMultiDay) return 1;
15837
+ return getEventStartTimestamp2(a) - getEventStartTimestamp2(b);
15838
+ });
15839
+ }
15840
+ function getSpanningEventsForDayAgenda(events, day) {
15841
+ return events.filter((event) => {
15842
+ if (!isMultiDayEventAgenda(event)) return false;
15843
+ const eventStart = isValidDate3(event.start) ? new Date(event.start) : void 0;
15844
+ const eventEnd = isValidDate3(event.end) ? new Date(event.end) : void 0;
15845
+ if (!eventStart || !eventEnd) return false;
15846
+ return !isSameDay7(day, eventStart) && (isSameDay7(day, eventEnd) || day > eventStart && day < eventEnd);
15847
+ });
15848
+ }
15849
+ function getAllEventsForDayAgenda(events, day) {
15850
+ return events.filter((event) => {
15851
+ const eventStart = isValidDate3(event.start) ? new Date(event.start) : void 0;
15852
+ const eventEnd = isValidDate3(event.end) ? new Date(event.end) : void 0;
15853
+ if (!eventStart) return false;
15854
+ return isSameDay7(day, eventStart) || (eventEnd ? isSameDay7(day, eventEnd) : false) || (eventEnd ? day > eventStart && day < eventEnd : false);
15855
+ });
15856
+ }
15857
+ function getAgendaEventsForDayAgenda(events, day) {
15858
+ return events.filter((event) => {
15859
+ const eventStart = isValidDate3(event.start) ? new Date(event.start) : isValidDate3(event.attend_date) ? normalizeAttendDate(event.attend_date) : void 0;
15860
+ const eventEnd = isValidDate3(event.end) ? new Date(event.end) : isValidDate3(event.attend_date) ? (() => {
15861
+ const dt = normalizeAttendDate(event.attend_date);
15862
+ return dt ? addHours4(dt, 1) : void 0;
15863
+ })() : void 0;
15864
+ if (!eventStart) return false;
15865
+ return isSameDay7(day, eventStart) || (eventEnd ? isSameDay7(day, eventEnd) : false) || (eventEnd ? day > eventStart && day < eventEnd : false);
15866
+ }).sort((a, b) => getEventStartTimestamp2(a) - getEventStartTimestamp2(b));
15867
+ }
15868
+ function isValidDate3(d) {
15869
+ try {
15870
+ const t = d instanceof Date ? d.getTime() : new Date(String(d)).getTime();
15871
+ return !isNaN(t);
15872
+ } catch {
15873
+ return false;
15874
+ }
15875
+ }
15876
+ function getEventStartTimestamp2(e) {
15877
+ if (isValidDate3(e.start)) return new Date(e.start).getTime();
15878
+ if (isValidDate3(e.attend_date))
15879
+ return normalizeAttendDate(e.attend_date).getTime();
15880
+ return Number.MAX_SAFE_INTEGER;
15881
+ }
15882
+ function normalizeAttendDate(d) {
15883
+ if (d === void 0 || d === null) return void 0;
15884
+ try {
15885
+ const dt = d instanceof Date ? d : new Date(String(d));
15886
+ if (isNaN(dt.getTime())) return void 0;
15887
+ if (dt.getHours() !== 0 || dt.getMinutes() !== 0 || dt.getSeconds() !== 0 || dt.getMilliseconds() !== 0) {
15888
+ return dt;
15889
+ }
15890
+ return new Date(dt.getFullYear(), dt.getMonth(), dt.getDate());
15891
+ } catch {
15892
+ return void 0;
15893
+ }
15894
+ }
15895
+ function addHoursToDateAgenda(date, hours) {
15896
+ const result = new Date(date);
15897
+ result.setHours(result.getHours() + hours);
15898
+ return result;
15899
+ }
15900
+
15901
+ // src/components/event-calendar-view/hooks/use-current-time-indicator.ts
15902
+ import { endOfWeek as endOfWeek5, isSameDay as isSameDay8, isWithinInterval as isWithinInterval2, startOfWeek as startOfWeek5 } from "date-fns";
15903
+ import { ptBR as ptBR11 } from "date-fns/locale";
15904
+ import { useEffect as useEffect26, useState as useState32 } from "react";
15905
+ function useCurrentTimeIndicatorAgenda(currentDate, view) {
15906
+ const [currentTimePosition, setCurrentTimePosition] = useState32(0);
15907
+ const [currentTimeVisible, setCurrentTimeVisible] = useState32(false);
15908
+ useEffect26(() => {
15909
+ const calculateTimePosition = () => {
15910
+ const now = /* @__PURE__ */ new Date();
15911
+ const hours = now.getHours();
15912
+ const minutes = now.getMinutes();
15913
+ const totalMinutes = (hours - StartHourAgenda) * 60 + minutes;
15914
+ const dayStartMinutes = 0;
15915
+ const dayEndMinutes = (EndHourAgenda - StartHourAgenda) * 60;
15916
+ const position = (totalMinutes - dayStartMinutes) / (dayEndMinutes - dayStartMinutes) * 100;
15917
+ let isCurrentTimeVisible = false;
15918
+ if (view === "day") {
15919
+ isCurrentTimeVisible = isSameDay8(now, currentDate);
15920
+ } else if (view === "week") {
15921
+ const startOfWeekDate = startOfWeek5(currentDate, { locale: ptBR11 });
15922
+ const endOfWeekDate = endOfWeek5(currentDate, { locale: ptBR11 });
15923
+ isCurrentTimeVisible = isWithinInterval2(now, {
15924
+ end: endOfWeekDate,
15925
+ start: startOfWeekDate
15926
+ });
15927
+ }
15928
+ setCurrentTimePosition(position);
15929
+ setCurrentTimeVisible(isCurrentTimeVisible);
15930
+ };
15931
+ calculateTimePosition();
15932
+ const interval = setInterval(calculateTimePosition, 6e4);
15933
+ return () => clearInterval(interval);
15934
+ }, [currentDate, view]);
15935
+ return { currentTimePosition, currentTimeVisible };
15936
+ }
15937
+
15938
+ // src/components/event-calendar-view/EventItemAgenda.tsx
15939
+ import { differenceInMinutes as differenceInMinutes6, format as format12, isPast as isPast2 } from "date-fns";
15940
+ import { useMemo as useMemo20 } from "react";
15941
+ import { ClockUserIcon as ClockUserIcon2 } from "@phosphor-icons/react";
15942
+ import { Fragment as Fragment15, jsx as jsx88, jsxs as jsxs68 } from "react/jsx-runtime";
15943
+ var formatTimeWithOptionalMinutes2 = (date) => {
15944
+ return format12(date, "HH:mm");
15945
+ };
15946
+ var isValidDate4 = (d) => {
15947
+ try {
15948
+ const dt = d instanceof Date ? d : new Date(String(d));
15949
+ return !isNaN(dt.getTime());
15950
+ } catch {
15951
+ return false;
15952
+ }
15953
+ };
15954
+ function EventWrapper2({
15955
+ event,
15956
+ isFirstDay = true,
15957
+ isLastDay = true,
15958
+ isDragging,
15959
+ onClick,
15960
+ className,
15961
+ children,
15962
+ currentTime,
15963
+ dndListeners,
15964
+ dndAttributes,
15965
+ onMouseDown,
15966
+ onTouchStart,
15967
+ ariaLabel
15968
+ }) {
15969
+ const hasValidTimeForWrapper = isValidDate4(event.start) && isValidDate4(event.end) || isValidDate4(event.attend_date);
15970
+ const displayEnd = (() => {
15971
+ if (isValidDate4(event.start) && isValidDate4(event.end)) {
15972
+ return currentTime ? new Date(
15973
+ new Date(currentTime).getTime() + (new Date(event.end).getTime() - new Date(event.start).getTime())
15974
+ ) : new Date(event.end);
15975
+ }
15976
+ if (isValidDate4(event.attend_date)) {
15977
+ const start = normalizeAttendDate(event.attend_date);
15978
+ return start ? addHoursToDateAgenda(start, 1) : void 0;
15979
+ }
15980
+ return void 0;
15981
+ })();
15982
+ const isEventInPast = displayEnd ? isPast2(displayEnd) : false;
15983
+ const colorClasses = hasValidTimeForWrapper ? getEventColorClassesAgenda(event.color) : "bg-gray-200/50 hover:bg-gray-200/40 text-gray-900/80 dark:bg-gray-700/25 dark:text-gray-200/90 shadow-none";
15984
+ return /* @__PURE__ */ jsx88(
15985
+ "button",
15986
+ {
15987
+ className: cn(
15988
+ "flex w-full select-none overflow-hidden px-3 py-1 text-left font-medium outline-none transition-transform duration-150 ease-out backdrop-blur-sm focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:border-ring data-dragging:cursor-grabbing data-past-event:line-through data-dragging:shadow-lg sm:px-3 rounded-lg shadow-sm hover:shadow-md ",
15989
+ colorClasses,
15990
+ getBorderRadiusClassesAgenda(isFirstDay, isLastDay),
15991
+ className
15992
+ ),
15993
+ "data-dragging": isDragging || void 0,
15994
+ "data-past-event": isEventInPast || void 0,
15995
+ onClick,
15996
+ onMouseDown,
15997
+ onTouchStart,
15998
+ "aria-label": ariaLabel,
15999
+ type: "button",
16000
+ ...dndListeners,
16001
+ ...dndAttributes,
16002
+ children
16003
+ }
16004
+ );
16005
+ }
16006
+ function EventItemAgenda({
16007
+ event,
16008
+ view,
16009
+ onClick,
16010
+ showTime,
16011
+ currentTime,
16012
+ isFirstDay = true,
16013
+ isLastDay = true,
16014
+ children,
16015
+ className,
16016
+ dndListeners,
16017
+ dndAttributes,
16018
+ onMouseDown,
16019
+ onTouchStart,
16020
+ agendaOnly = false
16021
+ }) {
16022
+ const eventColor = event.color;
16023
+ const hasValidTime = isValidDate4(event.start) && isValidDate4(event.end) || isValidDate4(event.attend_date);
16024
+ const colorClasses = hasValidTime ? getEventColorClassesAgenda(eventColor) : "bg-gray-200/50 hover:bg-gray-200/40 text-gray-900/80 dark:bg-gray-700/25 dark:text-gray-200/90 shadow-none";
16025
+ const displayStart = useMemo20(() => {
16026
+ if (!hasValidTime) return void 0;
16027
+ if (isValidDate4(event.start))
16028
+ return currentTime || new Date(event.start);
16029
+ if (isValidDate4(event.attend_date))
16030
+ return currentTime || normalizeAttendDate(event.attend_date);
16031
+ return void 0;
16032
+ }, [currentTime, event.start, event.attend_date, hasValidTime]);
16033
+ const displayEnd = useMemo20(() => {
16034
+ if (!hasValidTime) return void 0;
16035
+ if (isValidDate4(event.end)) {
16036
+ return currentTime ? new Date(
16037
+ new Date(currentTime).getTime() + (new Date(event.end).getTime() - new Date(event.start).getTime())
16038
+ ) : new Date(event.end);
16039
+ }
16040
+ if (isValidDate4(event.attend_date)) {
16041
+ const start = normalizeAttendDate(event.attend_date);
16042
+ return start ? addHoursToDateAgenda(start, 1) : void 0;
16043
+ }
16044
+ return void 0;
16045
+ }, [currentTime, event.start, event.end, event.attend_date, hasValidTime]);
16046
+ const durationMinutes = useMemo20(() => {
16047
+ if (!hasValidTime || !displayStart || !displayEnd) return 0;
16048
+ return differenceInMinutes6(displayEnd, displayStart);
16049
+ }, [displayStart, displayEnd, hasValidTime]);
16050
+ const getEventTime = () => {
16051
+ if (!hasValidTime) return "";
16052
+ if (event.allDay) return "All day";
16053
+ if (durationMinutes < 45) {
16054
+ return formatTimeWithOptionalMinutes2(displayStart);
16055
+ }
16056
+ return `${formatTimeWithOptionalMinutes2(
16057
+ displayStart
16058
+ )} - ${formatTimeWithOptionalMinutes2(displayEnd)}`;
16059
+ };
16060
+ let ariaLabel;
16061
+ if (!hasValidTime) {
16062
+ ariaLabel = event.title;
16063
+ } else if (event.allDay) {
16064
+ ariaLabel = `${event.title}, All day`;
16065
+ } else if (durationMinutes < 45) {
16066
+ ariaLabel = `${event.title}, ${formatTimeWithOptionalMinutes2(
16067
+ displayStart
16068
+ )}`;
16069
+ } else {
16070
+ ariaLabel = `${event.title}, ${formatTimeWithOptionalMinutes2(
16071
+ displayStart
16072
+ )} - ${formatTimeWithOptionalMinutes2(displayEnd)}`;
16073
+ }
16074
+ if (view === "month") {
16075
+ return /* @__PURE__ */ jsx88(
16076
+ EventWrapper2,
16077
+ {
16078
+ className: cn(
16079
+ "mt-[var(--event-gap)] h-[var(--event-height)] items-center text-[10px] sm:text-xs",
16080
+ className
16081
+ ),
16082
+ currentTime,
16083
+ dndAttributes,
16084
+ dndListeners,
16085
+ event,
16086
+ ariaLabel,
16087
+ isFirstDay,
16088
+ isLastDay,
16089
+ onClick,
16090
+ children: children || /* @__PURE__ */ jsxs68("span", { className: "flex items-center gap-2 truncate", children: [
16091
+ !event.allDay && hasValidTime && displayStart && /* @__PURE__ */ jsx88("span", { className: "truncate font-normal opacity-80 sm:text-[11px] bg-white/10 px-2 py-0.5 rounded-full text-[11px]", children: formatTimeWithOptionalMinutes2(displayStart) }),
16092
+ /* @__PURE__ */ jsx88(
16093
+ "span",
16094
+ {
16095
+ className: cn(
16096
+ "truncate",
16097
+ agendaOnly ? "font-bold text-lg" : "font-medium"
16098
+ ),
16099
+ children: event.title
16100
+ }
16101
+ )
16102
+ ] })
16103
+ }
16104
+ );
16105
+ }
16106
+ if (view === "week" || view === "day") {
16107
+ return /* @__PURE__ */ jsx88(
16108
+ EventWrapper2,
16109
+ {
16110
+ className: cn(
16111
+ "py-1",
16112
+ durationMinutes < 45 ? "items-center" : "flex-col",
16113
+ view === "week" ? "text-[10px] sm:text-xs" : "text-xs",
16114
+ className
16115
+ ),
16116
+ currentTime,
16117
+ dndAttributes,
16118
+ dndListeners,
16119
+ event,
16120
+ ariaLabel,
16121
+ isFirstDay,
16122
+ isLastDay,
16123
+ children: durationMinutes < 45 ? /* @__PURE__ */ jsxs68("div", { className: "flex items-center justify-between w-full", children: [
16124
+ /* @__PURE__ */ jsx88("div", { className: cn("truncate text-lg"), children: event.title }),
16125
+ showTime && hasValidTime && displayStart && /* @__PURE__ */ jsx88("span", { className: "ml-2 inline-block bg-white/10 px-2 py-0.5 rounded-full text-[11px] opacity-90", children: formatTimeWithOptionalMinutes2(displayStart) })
16126
+ ] }) : /* @__PURE__ */ jsxs68(Fragment15, { children: [
16127
+ /* @__PURE__ */ jsx88("div", { className: cn("truncate font-medium text-lg"), children: event.title }),
16128
+ showTime && hasValidTime && /* @__PURE__ */ jsx88("div", { className: "truncate font-normal opacity-70 sm:text-[15px]", children: /* @__PURE__ */ jsx88("span", { className: "inline-block bg-white/5 px-0.5 py-0.5 rounded-full", children: getEventTime() }) })
16129
+ ] })
16130
+ }
16131
+ );
16132
+ }
16133
+ if (!hasValidTime) {
16134
+ return /* @__PURE__ */ jsxs68(
16135
+ "button",
16136
+ {
16137
+ className: cn(
16138
+ "flex w-full flex-col gap-2 rounded-lg p-3 text-left outline-none transition-shadow duration-150 ease-out hover:bg-white/3 focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:border-ring",
16139
+ getEventColorClassesAgenda(eventColor),
16140
+ className
16141
+ ),
16142
+ "aria-label": ariaLabel,
16143
+ onClick,
16144
+ onMouseDown,
16145
+ onTouchStart,
16146
+ type: "button",
16147
+ ...dndListeners,
16148
+ ...dndAttributes,
16149
+ children: [
16150
+ /* @__PURE__ */ jsx88("div", { className: cn("font-medium", agendaOnly ? "text-lg" : "text-sm"), children: event.title }),
16151
+ /* @__PURE__ */ jsx88(
16152
+ "div",
16153
+ {
16154
+ className: cn(
16155
+ "opacity-70 flex items-center gap-2",
16156
+ agendaOnly ? "text-sm" : "text-xs"
16157
+ ),
16158
+ children: event.location && /* @__PURE__ */ jsxs68("span", { className: "opacity-80 flex items-center gap-1", children: [
16159
+ "-",
16160
+ /* @__PURE__ */ jsx88("span", { className: "truncate", children: event.location })
16161
+ ] })
16162
+ }
16163
+ ),
16164
+ event.description && /* @__PURE__ */ jsx88(
16165
+ "div",
16166
+ {
16167
+ className: cn(
16168
+ "my-1 opacity-90",
16169
+ agendaOnly ? "text-md" : "text-xs"
16170
+ ),
16171
+ style: {
16172
+ display: "-webkit-box",
16173
+ WebkitLineClamp: 2,
16174
+ WebkitBoxOrient: "vertical",
16175
+ overflow: "hidden"
16176
+ },
16177
+ children: event.description
16178
+ }
16179
+ )
16180
+ ]
16181
+ }
16182
+ );
16183
+ }
16184
+ return /* @__PURE__ */ jsxs68(
16185
+ "button",
16186
+ {
16187
+ className: cn(
16188
+ "flex w-full flex-col gap-2 rounded-lg p-3 text-left outline-none transition-shadow duration-150 ease-out hover:bg-white/3 focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:border-ring data-past-event:line-through data-past-event:opacity-90 border-2 border-border",
16189
+ colorClasses,
16190
+ className
16191
+ ),
16192
+ "data-past-event": isPast2(displayEnd) || void 0,
16193
+ "aria-label": ariaLabel,
16194
+ onClick,
16195
+ onMouseDown,
16196
+ onTouchStart,
16197
+ type: "button",
16198
+ ...dndListeners,
16199
+ ...dndAttributes,
16200
+ children: [
16201
+ /* @__PURE__ */ jsxs68("div", { className: "flex w-full justify-between ", children: [
16202
+ /* @__PURE__ */ jsx88("div", { className: cn("font-bold text-lg"), children: event.title }),
16203
+ /* @__PURE__ */ jsx88("div", { className: cn("opacity-90 flex items-center gap-2 text-lg"), children: event.allDay ? /* @__PURE__ */ jsx88("span", { children: "Dia todo" }) : /* @__PURE__ */ jsxs68("span", { className: "uppercase font-semibold flex items-center gap-2", children: [
16204
+ formatTimeWithOptionalMinutes2(displayStart),
16205
+ /* @__PURE__ */ jsx88("span", { className: "opacity-70", children: "-" }),
16206
+ formatTimeWithOptionalMinutes2(displayEnd),
16207
+ /* @__PURE__ */ jsx88(ClockUserIcon2, {})
16208
+ ] }) })
16209
+ ] }),
16210
+ event.description && /* @__PURE__ */ jsx88(
16211
+ "div",
16212
+ {
16213
+ className: cn("my-1 opacity-90 flex text-md"),
16214
+ style: {
16215
+ display: "-webkit-box",
16216
+ WebkitLineClamp: 2,
16217
+ WebkitBoxOrient: "vertical",
16218
+ overflow: "hidden"
16219
+ },
16220
+ children: event.description
16221
+ }
16222
+ )
16223
+ ]
16224
+ }
16225
+ );
16226
+ }
16227
+
16228
+ // src/components/event-calendar-view/DroppableCell.tsx
16229
+ import { useDroppable as useDroppable2 } from "@dnd-kit/core";
16230
+ import { jsx as jsx89 } from "react/jsx-runtime";
16231
+ function DroppableCellAgenda({
16232
+ id,
16233
+ date,
16234
+ time,
16235
+ children,
16236
+ className,
16237
+ onClick
16238
+ }) {
16239
+ const { activeEvent } = useCalendarDndAgenda();
16240
+ const { setNodeRef, isOver } = useDroppable2({
16241
+ data: {
16242
+ date,
16243
+ time
16244
+ },
16245
+ id
16246
+ });
16247
+ const formattedTime = time !== void 0 ? `${Math.floor(time)}:${Math.round((time - Math.floor(time)) * 60).toString().padStart(2, "0")}` : null;
16248
+ return /* @__PURE__ */ jsx89(
16249
+ "div",
16250
+ {
16251
+ className: cn(
16252
+ "flex h-full flex-col overflow-hidden px-0.5 py-1 data-dragging:bg-accent sm:px-1",
16253
+ className
16254
+ ),
16255
+ "data-dragging": isOver && activeEvent ? true : void 0,
16256
+ onClick,
16257
+ ref: setNodeRef,
16258
+ title: formattedTime ? `${formattedTime}` : void 0,
16259
+ children
16260
+ }
16261
+ );
16262
+ }
16263
+
16264
+ // src/components/event-calendar-view/DayView.tsx
16265
+ import { jsx as jsx90, jsxs as jsxs69 } from "react/jsx-runtime";
16266
+ function DayViewAgenda({
16267
+ currentDate,
16268
+ events,
16269
+ onEventSelect,
16270
+ showUndatedEvents
16271
+ }) {
16272
+ const hours = useMemo21(() => {
16273
+ const dayStart = startOfDay3(currentDate);
16274
+ return eachHourOfInterval3({
16275
+ end: addHours5(dayStart, EndHourAgenda - 1),
16276
+ start: addHours5(dayStart, StartHourAgenda)
16277
+ });
16278
+ }, [currentDate]);
16279
+ const dayEvents = useMemo21(() => {
16280
+ const dayStart = startOfDay3(currentDate);
16281
+ const dayEnd = endOfDay(currentDate);
16282
+ return events.map((event) => {
16283
+ let eventStart = event.start != null ? new Date(event.start) : void 0;
16284
+ let eventEnd = event.end != null ? new Date(event.end) : void 0;
16285
+ if ((!eventStart || !eventEnd) && event.attend_date) {
16286
+ try {
16287
+ const ad = new Date(event.attend_date);
16288
+ const hasTime = ad.getHours() !== 0 || ad.getMinutes() !== 0 || ad.getSeconds() !== 0 || ad.getMilliseconds() !== 0;
16289
+ if (hasTime) {
16290
+ if (!eventStart) eventStart = ad;
16291
+ if (!eventEnd) eventEnd = addHours5(ad, 1);
16292
+ }
16293
+ } catch {
16294
+ }
16295
+ }
16296
+ return { event, eventStart, eventEnd };
16297
+ }).filter(({ eventStart, eventEnd }) => !!eventStart && !!eventEnd).filter(
16298
+ ({ eventStart, eventEnd }) => areIntervalsOverlapping3(
16299
+ { start: eventStart, end: eventEnd },
16300
+ { start: dayStart, end: dayEnd }
16301
+ )
16302
+ ).map(({ event }) => event).sort((a, b) => {
16303
+ const aStart = a.start ? new Date(a.start).getTime() : a.attend_date ? new Date(a.attend_date).getTime() : 0;
16304
+ const bStart = b.start ? new Date(b.start).getTime() : b.attend_date ? new Date(b.attend_date).getTime() : 0;
16305
+ return aStart - bStart;
16306
+ });
16307
+ }, [currentDate, events]);
16308
+ const allDayEvents = useMemo21(() => {
16309
+ return dayEvents.filter((event) => {
16310
+ return event.allDay || isMultiDayEventAgenda(event);
16311
+ });
16312
+ }, [dayEvents]);
16313
+ const timeEvents = useMemo21(() => {
16314
+ return dayEvents.filter((event) => {
16315
+ return !event.allDay && !isMultiDayEventAgenda(event);
16316
+ });
16317
+ }, [dayEvents]);
16318
+ const positionedEvents = useMemo21(() => {
16319
+ const result = [];
16320
+ const dayStart = startOfDay3(currentDate);
16321
+ const sortedEvents = [...timeEvents].sort((a, b) => {
16322
+ const aStart = new Date(a.start);
16323
+ const bStart = new Date(b.start);
16324
+ const aEnd = new Date(a.end);
16325
+ const bEnd = new Date(b.end);
16326
+ if (aStart < bStart) return -1;
16327
+ if (aStart > bStart) return 1;
16328
+ const aDuration = differenceInMinutes7(aEnd, aStart);
16329
+ const bDuration = differenceInMinutes7(bEnd, bStart);
16330
+ return bDuration - aDuration;
16331
+ });
16332
+ const columns = [];
16333
+ for (const event of sortedEvents) {
16334
+ let eventStart = event.start != null ? new Date(event.start) : void 0;
16335
+ let eventEnd = event.end != null ? new Date(event.end) : void 0;
16336
+ if ((!eventStart || !eventEnd) && event.attend_date) {
16337
+ try {
16338
+ const ad = new Date(event.attend_date);
16339
+ const hasTime = ad.getHours() !== 0 || ad.getMinutes() !== 0 || ad.getSeconds() !== 0 || ad.getMilliseconds() !== 0;
16340
+ if (hasTime) {
16341
+ if (!eventStart) eventStart = ad;
16342
+ if (!eventEnd) eventEnd = addHours5(ad, 1);
16343
+ }
16344
+ } catch {
16345
+ }
16346
+ }
16347
+ if (!eventStart || !eventEnd) continue;
16348
+ const adjustedStart = isSameDay9(currentDate, eventStart) ? eventStart : dayStart;
16349
+ const adjustedEnd = isSameDay9(currentDate, eventEnd) ? eventEnd : addHours5(dayStart, 24);
16350
+ const startHour = getHours3(adjustedStart) + getMinutes3(adjustedStart) / 60;
16351
+ const endHour = getHours3(adjustedEnd) + getMinutes3(adjustedEnd) / 60;
16352
+ const top = (startHour - StartHourAgenda) * WeekCellsHeightAgenda;
16353
+ const height = (endHour - startHour) * WeekCellsHeightAgenda;
16354
+ let columnIndex = 0;
16355
+ let placed = false;
16356
+ while (!placed) {
16357
+ const col = columns[columnIndex] || [];
16358
+ if (col.length === 0) {
16359
+ columns[columnIndex] = col;
16360
+ placed = true;
16361
+ } else {
16362
+ const overlaps = col.some(
16363
+ (c) => areIntervalsOverlapping3(
16364
+ { end: adjustedEnd, start: adjustedStart },
16365
+ { end: c.end, start: c.start }
16366
+ )
16367
+ );
16368
+ if (!overlaps) {
16369
+ placed = true;
16370
+ } else {
16371
+ columnIndex++;
16372
+ }
16373
+ }
16374
+ }
16375
+ const currentColumn = columns[columnIndex] || [];
16376
+ columns[columnIndex] = currentColumn;
16377
+ currentColumn.push({ start: adjustedStart, end: adjustedEnd, event });
16378
+ const width = columnIndex === 0 ? 1 : 0.9;
16379
+ const left = columnIndex === 0 ? 0 : columnIndex * 0.1;
16380
+ result.push({
16381
+ event,
16382
+ height,
16383
+ left,
16384
+ top,
16385
+ width,
16386
+ zIndex: 10 + columnIndex
16387
+ });
16388
+ }
16389
+ return result;
16390
+ }, [currentDate, timeEvents]);
16391
+ const handleEventClick = (event, e) => {
16392
+ e.stopPropagation();
16393
+ onEventSelect(event);
16394
+ };
16395
+ const showAllDaySection = allDayEvents.length > 0;
16396
+ const { currentTimePosition, currentTimeVisible } = useCurrentTimeIndicatorAgenda(
16397
+ currentDate,
16398
+ "day"
16399
+ );
16400
+ return /* @__PURE__ */ jsxs69("div", { className: "contents", "data-slot": "day-view", children: [
16401
+ showAllDaySection && /* @__PURE__ */ jsx90("div", { className: "border-border/70 border-t bg-muted/50", children: /* @__PURE__ */ jsxs69("div", { className: "grid grid-cols-[3rem_1fr] sm:grid-cols-[4rem_1fr]", children: [
16402
+ /* @__PURE__ */ jsx90("div", { className: "relative", children: /* @__PURE__ */ jsx90("span", { className: "absolute bottom-0 left-0 h-6 w-16 max-w-full pe-2 text-right text-[10px] text-muted-foreground/70 sm:pe-4 sm:text-xs", children: "All day" }) }),
16403
+ /* @__PURE__ */ jsx90("div", { className: "relative border-border/70 border-r p-1 last:border-r-0", children: allDayEvents.map((event) => {
16404
+ const eventStart = new Date(
16405
+ event.start ?? event.attend_date ?? event.end ?? Date.now()
16406
+ );
16407
+ const eventEnd = new Date(
16408
+ event.end ?? event.attend_date ?? event.start ?? Date.now()
16409
+ );
16410
+ const isFirstDay = isSameDay9(currentDate, eventStart);
16411
+ const isLastDay = isSameDay9(currentDate, eventEnd);
16412
+ return /* @__PURE__ */ jsx90(
16413
+ EventItemAgenda,
16414
+ {
16415
+ event,
16416
+ isFirstDay,
16417
+ isLastDay,
16418
+ onClick: (e) => handleEventClick(event, e),
16419
+ view: "month",
16420
+ children: /* @__PURE__ */ jsx90("div", { children: event.title })
16421
+ },
16422
+ `spanning-${event.id}`
16423
+ );
16424
+ }) })
16425
+ ] }) }),
16426
+ /* @__PURE__ */ jsxs69("div", { className: "grid flex-1 grid-cols-[3rem_1fr] overflow-hidden border-border/70 border-t sm:grid-cols-[4rem_1fr]", children: [
16427
+ /* @__PURE__ */ jsx90("div", { children: hours.map((hour, index) => /* @__PURE__ */ jsx90(
16428
+ "div",
16429
+ {
16430
+ className: "relative h-[var(--week-cells-height)] border-border/70 border-b last:border-b-0",
16431
+ children: index > 0 && /* @__PURE__ */ jsx90("span", { className: "-top-3 absolute left-0 flex h-6 w-16 max-w-full items-center justify-end bg-background pe-2 text-[10px] text-muted-foreground/70 sm:pe-4 sm:text-xs", children: format13(hour, "HH:mm") })
16432
+ },
16433
+ hour.toString()
16434
+ )) }),
16435
+ /* @__PURE__ */ jsxs69("div", { className: "relative", children: [
16436
+ positionedEvents.map((positionedEvent) => {
16437
+ const evt = positionedEvent.event;
16438
+ const eventStart = new Date(
16439
+ evt.start ?? evt.attend_date ?? evt.end ?? Date.now()
16440
+ );
16441
+ const eventEnd = new Date(
16442
+ evt.end ?? evt.attend_date ?? evt.start ?? Date.now()
16443
+ );
16444
+ const isFirstDay = isSameDay9(currentDate, eventStart);
16445
+ const isLastDay = isSameDay9(currentDate, eventEnd);
16446
+ return /* @__PURE__ */ jsx90(
16447
+ "div",
16448
+ {
16449
+ className: "absolute z-10 px-0.5",
16450
+ style: {
16451
+ height: `${positionedEvent.height}px`,
16452
+ left: `${positionedEvent.left * 100}%`,
16453
+ top: `${positionedEvent.top}px`,
16454
+ width: `${positionedEvent.width * 100}%`,
16455
+ zIndex: positionedEvent.zIndex
16456
+ },
16457
+ children: /* @__PURE__ */ jsx90(
16458
+ EventItemAgenda,
16459
+ {
16460
+ event: evt,
16461
+ view: "day",
16462
+ isFirstDay,
16463
+ isLastDay,
16464
+ onClick: (e) => handleEventClick(evt, e),
16465
+ showTime: true
16466
+ }
16467
+ )
16468
+ },
16469
+ positionedEvent.event.id
16470
+ );
16471
+ }),
16472
+ currentTimeVisible && /* @__PURE__ */ jsx90(
16473
+ "div",
16474
+ {
16475
+ className: "pointer-events-none absolute right-0 left-0 z-20",
16476
+ style: { top: `${currentTimePosition}%` },
16477
+ children: /* @__PURE__ */ jsxs69("div", { className: "relative flex items-center", children: [
16478
+ /* @__PURE__ */ jsx90("div", { className: "-left-1 absolute h-2 w-2 rounded-full bg-primary" }),
16479
+ /* @__PURE__ */ jsx90("div", { className: "h-[2px] w-full bg-primary" })
16480
+ ] })
16481
+ }
16482
+ ),
16483
+ hours.map((hour) => {
16484
+ const hourValue = getHours3(hour);
16485
+ return /* @__PURE__ */ jsx90(
16486
+ "div",
16487
+ {
16488
+ className: "relative h-[var(--week-cells-height)] border-border/70 border-b last:border-b-0",
16489
+ children: [0, 1, 2, 3].map((quarter) => {
16490
+ const quarterHourTime = hourValue + quarter * 0.25;
16491
+ return /* @__PURE__ */ jsx90(
16492
+ DroppableCellAgenda,
16493
+ {
16494
+ className: cn(
16495
+ "absolute h-[calc(var(--week-cells-height)/4)] w-full",
16496
+ quarter === 0 && "top-0",
16497
+ quarter === 1 && "top-[calc(var(--week-cells-height)/4)]",
16498
+ quarter === 2 && "top-[calc(var(--week-cells-height)/4*2)]",
16499
+ quarter === 3 && "top-[calc(var(--week-cells-height)/4*3)]"
16500
+ ),
16501
+ date: currentDate,
16502
+ id: `day-cell-${currentDate.toISOString()}-${quarterHourTime}`,
16503
+ onClick: () => {
16504
+ const startTime = new Date(currentDate);
16505
+ startTime.setHours(hourValue);
16506
+ startTime.setMinutes(quarter * 15);
16507
+ },
16508
+ time: quarterHourTime
16509
+ },
16510
+ `${hour.toString()}-${quarter}`
16511
+ );
16512
+ })
16513
+ },
16514
+ hour.toString()
16515
+ );
16516
+ })
16517
+ ] })
16518
+ ] }),
16519
+ /* @__PURE__ */ jsx90(
16520
+ UndatedEvents,
16521
+ {
16522
+ events,
16523
+ onEventSelect,
16524
+ show: showUndatedEvents
16525
+ }
16526
+ )
16527
+ ] });
16528
+ }
16529
+
16530
+ // src/components/event-calendar-view/EventAgenda.tsx
16531
+ import {
16532
+ addDays as addDays5,
16533
+ addMonths as addMonths2,
16534
+ addWeeks as addWeeks2,
16535
+ endOfWeek as endOfWeek6,
16536
+ format as format14,
16537
+ isSameMonth as isSameMonth3,
16538
+ startOfWeek as startOfWeek6,
16539
+ subMonths as subMonths2,
16540
+ subWeeks as subWeeks2
16541
+ } from "date-fns";
16542
+ import { ptBR as ptBR12 } from "date-fns/locale";
16543
+ import { useEffect as useEffect27, useMemo as useMemo22, useState as useState33, useCallback as useCallback16 } from "react";
16544
+ import { toast as toast4 } from "sonner";
16545
+ import {
16546
+ CalendarIcon as CalendarIcon6,
16547
+ CaretDownIcon as CaretDownIcon6,
16548
+ CaretLeftIcon as CaretLeftIcon4,
16549
+ CaretRightIcon as CaretRightIcon7,
16550
+ Check as Check2
16551
+ } from "@phosphor-icons/react";
16552
+ import { Fragment as Fragment16, jsx as jsx91, jsxs as jsxs70 } from "react/jsx-runtime";
16553
+ function EventAgenda({
16554
+ events = [],
16555
+ onEventUpdate,
16556
+ className,
16557
+ initialView = "month",
16558
+ mode,
16559
+ initialDate
16560
+ }) {
16561
+ const [currentDate, setCurrentDate] = useState33(
16562
+ initialDate && new Date(initialDate) || /* @__PURE__ */ new Date()
16563
+ );
16564
+ const [view, setView] = useState33(initialView);
16565
+ const [isFading, setIsFading] = useState33(false);
16566
+ const FADE_DURATION = 220;
16567
+ const changeView = useCallback16(
16568
+ (next) => {
16569
+ if (mode === "agenda-only") return;
16570
+ if (next === view) return;
16571
+ setIsFading(true);
16572
+ window.setTimeout(() => {
16573
+ setView(next);
16574
+ requestAnimationFrame(() => setIsFading(false));
16575
+ }, FADE_DURATION);
16576
+ },
16577
+ [view, mode]
16578
+ );
16579
+ const [isPaging, setIsPaging] = useState33(false);
16580
+ const [pageDirection, setPageDirection] = useState33(
16581
+ null
16582
+ );
16583
+ const PAGE_DURATION = 200;
16584
+ const pageTransition = useCallback16(
16585
+ (applyDateChange, direction) => {
16586
+ setIsPaging(true);
16587
+ setPageDirection(direction);
16588
+ window.setTimeout(() => {
16589
+ applyDateChange();
16590
+ requestAnimationFrame(() => {
16591
+ setIsPaging(false);
16592
+ setPageDirection(null);
16593
+ });
16594
+ }, PAGE_DURATION);
16595
+ },
16596
+ []
16597
+ );
16598
+ const [isEventDialogOpen, setIsEventDialogOpen] = useState33(false);
16599
+ useEffect27(() => {
16600
+ const handleKeyDown = (e) => {
16601
+ if (isEventDialogOpen || e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLElement && e.target.isContentEditable) {
16602
+ return;
16603
+ }
16604
+ if (mode === "agenda-only") return;
16605
+ switch (e.key.toLowerCase()) {
16606
+ case "m":
16607
+ changeView("month");
16608
+ break;
16609
+ case "w":
16610
+ case "s":
16611
+ changeView("week");
16612
+ break;
16613
+ case "d":
16614
+ changeView("day");
16615
+ break;
16616
+ case "a":
16617
+ changeView("agenda");
16618
+ break;
16619
+ }
16620
+ };
16621
+ window.addEventListener("keydown", handleKeyDown);
16622
+ return () => {
16623
+ window.removeEventListener("keydown", handleKeyDown);
16624
+ };
16625
+ }, [isEventDialogOpen, changeView, mode]);
16626
+ useEffect27(() => {
16627
+ if (mode === "agenda-only") setView("agenda");
16628
+ }, [mode]);
16629
+ const handlePrevious = () => {
16630
+ pageTransition(() => {
16631
+ if (view === "month") {
16632
+ setCurrentDate(subMonths2(currentDate, 1));
16633
+ } else if (view === "week") {
16634
+ setCurrentDate(subWeeks2(currentDate, 1));
16635
+ } else if (view === "day") {
16636
+ setCurrentDate(addDays5(currentDate, -1));
16637
+ } else if (view === "agenda") {
16638
+ setCurrentDate(addDays5(currentDate, -AgendaDaysToShowAgenda));
16639
+ }
16640
+ }, "right");
16641
+ };
16642
+ const handleNext = () => {
16643
+ pageTransition(() => {
16644
+ if (view === "month") {
16645
+ setCurrentDate(addMonths2(currentDate, 1));
16646
+ } else if (view === "week") {
16647
+ setCurrentDate(addWeeks2(currentDate, 1));
16648
+ } else if (view === "day") {
16649
+ setCurrentDate(addDays5(currentDate, 1));
16650
+ } else if (view === "agenda") {
16651
+ setCurrentDate(addDays5(currentDate, AgendaDaysToShowAgenda));
16652
+ }
16653
+ }, "left");
16654
+ };
16655
+ const handleToday = () => {
16656
+ setCurrentDate(/* @__PURE__ */ new Date());
16657
+ };
16658
+ const handleEventSelect = (event) => {
16659
+ console.log("Event selected:", event);
16660
+ setIsEventDialogOpen(true);
16661
+ };
16662
+ const handleEventUpdate = (updatedEvent) => {
16663
+ onEventUpdate?.(updatedEvent);
16664
+ const startDate = updatedEvent.start ?? /* @__PURE__ */ new Date();
16665
+ toast4(`Evento "${updatedEvent.title}" movido`, {
16666
+ description: format14(startDate, "d 'de' MMMM 'de' yyyy", { locale: ptBR12 }),
16667
+ position: "bottom-left"
16668
+ });
16669
+ };
16670
+ const viewTitle = useMemo22(() => {
16671
+ const capitalize = (s) => s && s.length > 0 ? s.charAt(0).toUpperCase() + s.slice(1) : s;
16672
+ if (view === "month") {
16673
+ return capitalize(format14(currentDate, "MMMM yyyy", { locale: ptBR12 }));
16674
+ }
16675
+ if (view === "week") {
16676
+ const start = startOfWeek6(currentDate, { weekStartsOn: 1 });
16677
+ const end = endOfWeek6(currentDate, { weekStartsOn: 1 });
16678
+ if (isSameMonth3(start, end)) {
16679
+ return capitalize(format14(start, "MMMM yyyy", { locale: ptBR12 }));
16680
+ }
16681
+ const s1 = capitalize(format14(start, "MMM", { locale: ptBR12 }));
16682
+ const s2 = capitalize(format14(end, "MMM yyyy", { locale: ptBR12 }));
16683
+ return `${s1} - ${s2}`;
16684
+ }
16685
+ if (view === "day") {
16686
+ const dayNum = format14(currentDate, "d", { locale: ptBR12 });
16687
+ const month = capitalize(format14(currentDate, "MMMM", { locale: ptBR12 }));
16688
+ const year = format14(currentDate, "yyyy", { locale: ptBR12 });
16689
+ const short = `${dayNum} de ${month} de ${year}`;
16690
+ return /* @__PURE__ */ jsxs70(Fragment16, { children: [
16691
+ /* @__PURE__ */ jsx91("span", { "aria-hidden": "true", className: "min-[480px]:hidden", children: short }),
16692
+ /* @__PURE__ */ jsx91("span", { "aria-hidden": "true", className: "max-[479px]:hidden min-md:hidden", children: short })
16693
+ ] });
16694
+ }
16695
+ if (view === "agenda") {
16696
+ const start = currentDate;
16697
+ const end = addDays5(currentDate, AgendaDaysToShowAgenda - 1);
16698
+ if (isSameMonth3(start, end)) {
16699
+ return capitalize(format14(start, "MMMM yyyy", { locale: ptBR12 }));
16700
+ }
16701
+ const s1 = capitalize(format14(start, "MMMM", { locale: ptBR12 }));
16702
+ const s2 = capitalize(format14(end, "MMMM yyyy", { locale: ptBR12 }));
16703
+ return `${s1} - ${s2}`;
16704
+ }
16705
+ return capitalize(format14(currentDate, "MMMM yyyy", { locale: ptBR12 }));
16706
+ }, [currentDate, view]);
16707
+ const calendarContent = /* @__PURE__ */ jsxs70(Fragment16, { children: [
16708
+ /* @__PURE__ */ jsxs70(
16709
+ "div",
16710
+ {
16711
+ className: cn(
16712
+ "flex items-center justify-between p-2 sm:p-4",
16713
+ className
16714
+ ),
16715
+ children: [
16716
+ /* @__PURE__ */ jsxs70("div", { className: "flex items-center gap-1 sm:gap-4", children: [
16717
+ /* @__PURE__ */ jsxs70(
16718
+ ButtonBase,
16719
+ {
16720
+ className: "max-[479px]:aspect-square max-[479px]:p-0!",
16721
+ onClick: handleToday,
16722
+ variant: "outline",
16723
+ children: [
16724
+ /* @__PURE__ */ jsx91(
16725
+ CalendarIcon6,
16726
+ {
16727
+ "aria-hidden": "true",
16728
+ className: "min-[480px]:hidden",
16729
+ size: 16
16730
+ }
16731
+ ),
16732
+ /* @__PURE__ */ jsx91("span", { className: "max-[479px]:sr-only", children: "Hoje" })
16733
+ ]
16734
+ }
16735
+ ),
16736
+ /* @__PURE__ */ jsxs70("div", { className: "flex items-center sm:gap-2", children: [
16737
+ /* @__PURE__ */ jsx91(
16738
+ ButtonBase,
16739
+ {
16740
+ "aria-label": "Anterior",
16741
+ onClick: handlePrevious,
16742
+ size: "icon",
16743
+ variant: "ghost",
16744
+ children: /* @__PURE__ */ jsx91(CaretLeftIcon4, { "aria-hidden": "true", size: 16 })
16745
+ }
16746
+ ),
16747
+ /* @__PURE__ */ jsx91(
16748
+ ButtonBase,
16749
+ {
16750
+ "aria-label": "Pr\xF3ximo",
16751
+ onClick: handleNext,
16752
+ size: "icon",
16753
+ variant: "ghost",
16754
+ children: /* @__PURE__ */ jsx91(CaretRightIcon7, { "aria-hidden": "true", size: 16 })
16755
+ }
16756
+ )
16757
+ ] }),
16758
+ /* @__PURE__ */ jsx91("h2", { className: "font-semibold text-xl", children: viewTitle })
16759
+ ] }),
16760
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx91(Fragment16, { children: /* @__PURE__ */ jsxs70(DropDownMenuBase, { children: [
16761
+ /* @__PURE__ */ jsx91(DropDownMenuTriggerBase, { asChild: true, children: /* @__PURE__ */ jsxs70(
16762
+ ButtonBase,
16763
+ {
16764
+ className: "gap-2 px-3 py-1.5 max-[479px]:h-8",
16765
+ variant: "outline",
16766
+ children: [
16767
+ /* @__PURE__ */ jsxs70("span", { className: "flex items-center gap-2", children: [
16768
+ /* @__PURE__ */ jsx91("span", { className: "hidden min-[480px]:inline-block", children: (() => {
16769
+ const labels = {
16770
+ month: "M\xEAs",
16771
+ week: "Semana",
16772
+ day: "Dia",
16773
+ agenda: "Agenda"
16774
+ };
16775
+ return labels[view] || view;
16776
+ })() }),
16777
+ /* @__PURE__ */ jsx91("span", { className: "min-[480px]:hidden", children: (() => {
16778
+ const labels = {
16779
+ month: "M",
16780
+ week: "S",
16781
+ day: "D",
16782
+ agenda: "A"
16783
+ };
16784
+ return labels[view] || view;
16785
+ })() })
16786
+ ] }),
16787
+ /* @__PURE__ */ jsx91(
16788
+ CaretDownIcon6,
16789
+ {
16790
+ "aria-hidden": "true",
16791
+ className: "-me-1 opacity-60",
16792
+ size: 16
16793
+ }
16794
+ )
16795
+ ]
16796
+ }
16797
+ ) }),
16798
+ mode === "agenda-only" ? null : /* @__PURE__ */ jsxs70(
16799
+ DropDownMenuContentBase,
16800
+ {
16801
+ align: "end",
16802
+ className: "min-w-32 rounded-md p-1",
16803
+ children: [
16804
+ /* @__PURE__ */ jsxs70(
16805
+ DropDownMenuItemBase,
16806
+ {
16807
+ onClick: () => changeView("month"),
16808
+ className: cn(
16809
+ "flex items-center justify-between gap-2 px-3 py-2 rounded",
16810
+ view === "month"
16811
+ ),
16812
+ children: [
16813
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx91("span", { children: " M\xEAs " }) }),
16814
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: view === "month" ? /* @__PURE__ */ jsx91(Check2, { "aria-hidden": true, className: "opacity-80", size: 14 }) : /* @__PURE__ */ jsx91(DropDownMenuShortcutBase, { children: "M" }) })
16815
+ ]
16816
+ }
16817
+ ),
16818
+ /* @__PURE__ */ jsxs70(
16819
+ DropDownMenuItemBase,
16820
+ {
16821
+ onClick: () => changeView("week"),
16822
+ className: cn(
16823
+ "flex items-center justify-between gap-2 px-3 py-2 rounded",
16824
+ view === "week"
16825
+ ),
16826
+ children: [
16827
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: "Semana" }),
16828
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: view === "week" ? /* @__PURE__ */ jsx91(Check2, { "aria-hidden": true, className: "opacity-80", size: 14 }) : /* @__PURE__ */ jsx91(DropDownMenuShortcutBase, { children: "S" }) })
16829
+ ]
16830
+ }
16831
+ ),
16832
+ /* @__PURE__ */ jsxs70(
16833
+ DropDownMenuItemBase,
16834
+ {
16835
+ onClick: () => changeView("day"),
16836
+ className: cn(
16837
+ "flex items-center justify-between gap-2 px-3 py-2 rounded",
16838
+ view === "day"
16839
+ ),
16840
+ children: [
16841
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: "Dia" }),
16842
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: view === "day" ? /* @__PURE__ */ jsx91(Check2, { "aria-hidden": true, className: "opacity-80", size: 14 }) : /* @__PURE__ */ jsx91(DropDownMenuShortcutBase, { children: "D" }) })
16843
+ ]
16844
+ }
16845
+ ),
16846
+ /* @__PURE__ */ jsxs70(
16847
+ DropDownMenuItemBase,
16848
+ {
16849
+ onClick: () => changeView("agenda"),
16850
+ className: cn(
16851
+ "flex items-center justify-between gap-2 px-3 py-2 rounded",
16852
+ view === "agenda"
16853
+ ),
16854
+ children: [
16855
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: "Agenda" }),
16856
+ /* @__PURE__ */ jsx91("div", { className: "flex items-center gap-2", children: view === "agenda" ? /* @__PURE__ */ jsx91(Check2, { "aria-hidden": true, className: "opacity-80", size: 14 }) : /* @__PURE__ */ jsx91(DropDownMenuShortcutBase, { children: "A" }) })
16857
+ ]
16858
+ }
16859
+ )
16860
+ ]
16861
+ }
16862
+ )
16863
+ ] }) }) })
16864
+ ]
16865
+ }
16866
+ ),
16867
+ /* @__PURE__ */ jsxs70(
16868
+ "div",
16869
+ {
16870
+ className: cn(
16871
+ "flex flex-1 flex-col transition-all duration-200 ease-in-out",
16872
+ isFading ? "opacity-0 -translate-y-2 pointer-events-none" : isPaging ? pageDirection === "left" ? "-translate-x-4 opacity-0 pointer-events-none" : "translate-x-4 opacity-0 pointer-events-none" : "opacity-100 translate-y-0"
16873
+ ),
16874
+ "aria-live": "polite",
16875
+ children: [
16876
+ view === "month" && /* @__PURE__ */ jsx91(
16877
+ MonthViewAgenda,
16878
+ {
16879
+ currentDate,
16880
+ events,
16881
+ onEventSelect: handleEventSelect
16882
+ }
16883
+ ),
16884
+ view === "week" && /* @__PURE__ */ jsx91(
16885
+ WeekViewAgenda,
16886
+ {
16887
+ currentDate,
16888
+ events,
16889
+ onEventSelect: handleEventSelect
16890
+ }
16891
+ ),
16892
+ view === "day" && /* @__PURE__ */ jsx91(
16893
+ DayViewAgenda,
16894
+ {
16895
+ currentDate,
16896
+ events,
16897
+ onEventSelect: handleEventSelect
16898
+ }
16899
+ ),
16900
+ view === "agenda" && /* @__PURE__ */ jsx91(
16901
+ Agenda,
16902
+ {
16903
+ currentDate,
16904
+ events,
16905
+ onEventSelect: handleEventSelect
16906
+ }
16907
+ )
16908
+ ]
16909
+ }
16910
+ )
16911
+ ] });
16912
+ return /* @__PURE__ */ jsx91(
16913
+ "div",
16914
+ {
16915
+ className: "flex flex-col rounded-lg border has-data-[slot=month-view]:flex-1 px-6",
16916
+ style: {
16917
+ "--event-gap": `${EventGapAgenda}px`,
16918
+ "--event-height": `${EventHeightAgenda}px`,
16919
+ "--week-cells-height": `${WeekCellsHeightAgenda}px`
16920
+ },
16921
+ children: /* @__PURE__ */ jsx91(CalendarDndProviderAgenda, { onEventUpdate: handleEventUpdate, children: calendarContent })
16922
+ }
16923
+ );
16924
+ }
16925
+
16926
+ // src/components/event-calendar-view/UndatedEvents.tsx
16927
+ import { useMemo as useMemo23 } from "react";
16928
+ import { jsx as jsx92, jsxs as jsxs71 } from "react/jsx-runtime";
16929
+ var isValidDate5 = (d) => {
16930
+ try {
16931
+ const t = d instanceof Date ? d.getTime() : new Date(String(d)).getTime();
16932
+ return !isNaN(t);
16933
+ } catch {
16934
+ return false;
16935
+ }
16936
+ };
16937
+ function UndatedEvents({
16938
+ events,
16939
+ onEventSelect,
16940
+ className,
16941
+ title = "Data de Atendimento n\xE3o Prevista",
16942
+ show = true
16943
+ }) {
16944
+ const undatedEvents = useMemo23(
16945
+ () => events.filter(
16946
+ (e) => !(isValidDate5(e.start) && isValidDate5(e.end)) && !isValidDate5(e.attend_date)
16947
+ ),
16948
+ [events]
16949
+ );
16950
+ if (!show || undatedEvents.length === 0) return null;
16951
+ return /* @__PURE__ */ jsx92("div", { className, children: /* @__PURE__ */ jsxs71("div", { className: "relative border-border/70 border-t", children: [
16952
+ /* @__PURE__ */ jsx92("span", { className: "-top-3 absolute left-0 flex h-6 items-center bg-background pe-4 uppercase sm:pe-4 text-lg", children: title }),
16953
+ /* @__PURE__ */ jsx92("div", { className: "mt-6 space-y-2", children: undatedEvents.map((event) => /* @__PURE__ */ jsx92(
16954
+ EventItemAgenda,
16955
+ {
16956
+ event,
16957
+ onClick: onEventSelect ? () => onEventSelect(event) : void 0,
16958
+ view: "agenda",
16959
+ agendaOnly: true,
16960
+ className: "cursor-default hover:shadow-none hover:scale-100 bg-gray-200/50 hover:bg-gray-200/40 text-gray-900/80 dark:bg-gray-700/25 dark:text-gray-200/90 shadow-none "
16961
+ },
16962
+ event.id
16963
+ )) })
16964
+ ] }) });
16965
+ }
16966
+
16967
+ // src/components/event-calendar-view/hooks/use-event-visibility.ts
16968
+ import { useLayoutEffect as useLayoutEffect3, useMemo as useMemo24, useRef as useRef16, useState as useState34 } from "react";
16969
+ function useEventVisibilityAgenda({
16970
+ eventHeight,
16971
+ eventGap
16972
+ }) {
16973
+ const contentRef = useRef16(null);
16974
+ const observerRef = useRef16(null);
16975
+ const [contentHeight, setContentHeight] = useState34(null);
16976
+ useLayoutEffect3(() => {
16977
+ if (!contentRef.current) return;
16978
+ const updateHeight = () => {
16979
+ if (contentRef.current) {
16980
+ setContentHeight(contentRef.current.clientHeight);
16981
+ }
16982
+ };
16983
+ updateHeight();
16984
+ if (!observerRef.current) {
16985
+ observerRef.current = new ResizeObserver(() => {
16986
+ updateHeight();
16987
+ });
16988
+ }
16989
+ observerRef.current.observe(contentRef.current);
16990
+ return () => {
16991
+ if (observerRef.current) {
16992
+ observerRef.current.disconnect();
16993
+ }
16994
+ };
16995
+ }, []);
16996
+ const getVisibleEventCount = useMemo24(() => {
16997
+ return (totalEvents) => {
16998
+ if (!contentHeight) return totalEvents;
16999
+ const maxEvents = Math.floor(contentHeight / (eventHeight + eventGap));
17000
+ if (totalEvents <= maxEvents) {
17001
+ return totalEvents;
17002
+ }
17003
+ return maxEvents > 0 ? maxEvents - 1 : 0;
17004
+ };
17005
+ }, [contentHeight, eventHeight, eventGap]);
17006
+ return {
17007
+ contentHeight,
17008
+ contentRef,
17009
+ getVisibleEventCount
17010
+ };
17011
+ }
17012
+
17013
+ // src/components/event-calendar-view/MonthView.tsx
17014
+ import {
17015
+ addDays as addDays6,
17016
+ eachDayOfInterval as eachDayOfInterval3,
17017
+ endOfMonth as endOfMonth2,
17018
+ endOfWeek as endOfWeek7,
17019
+ format as format15,
17020
+ isSameDay as isSameDay10,
17021
+ isSameMonth as isSameMonth4,
17022
+ isToday as isToday5,
17023
+ startOfMonth as startOfMonth2,
17024
+ startOfWeek as startOfWeek7
17025
+ } from "date-fns";
17026
+ import { ptBR as ptBR13 } from "date-fns/locale";
17027
+ import { useEffect as useEffect28, useMemo as useMemo25, useState as useState35 } from "react";
17028
+ import { twMerge as twMerge3 } from "tailwind-merge";
17029
+ import { jsx as jsx93, jsxs as jsxs72 } from "react/jsx-runtime";
17030
+ function MonthViewAgenda({
17031
+ currentDate,
17032
+ events,
17033
+ onEventSelect,
17034
+ showUndatedEvents
17035
+ }) {
17036
+ const days = useMemo25(() => {
17037
+ const monthStart = startOfMonth2(currentDate);
17038
+ const monthEnd = endOfMonth2(monthStart);
17039
+ const calendarStart = startOfWeek7(monthStart, { weekStartsOn: 0 });
17040
+ const calendarEnd = endOfWeek7(monthEnd, { weekStartsOn: 0 });
17041
+ return eachDayOfInterval3({ end: calendarEnd, start: calendarStart });
17042
+ }, [currentDate]);
17043
+ const weekdays = useMemo25(() => {
17044
+ return Array.from({ length: 7 }).map((_, i) => {
17045
+ const date = addDays6(startOfWeek7(/* @__PURE__ */ new Date(), { weekStartsOn: 0 }), i);
17046
+ const short = format15(date, "EEE", { locale: ptBR13 });
17047
+ return short.charAt(0).toUpperCase() + short.slice(1);
17048
+ });
17049
+ }, []);
17050
+ const weeks = useMemo25(() => {
17051
+ const result = [];
17052
+ let week = [];
17053
+ for (let i = 0; i < days.length; i++) {
17054
+ week.push(days[i]);
17055
+ if (week.length === 7 || i === days.length - 1) {
17056
+ result.push(week);
17057
+ week = [];
17058
+ }
17059
+ }
17060
+ return result;
17061
+ }, [days]);
17062
+ const handleEventClick = (event, e) => {
17063
+ e.stopPropagation();
17064
+ onEventSelect(event);
17065
+ };
17066
+ const [isMounted, setIsMounted] = useState35(false);
17067
+ const { contentRef, getVisibleEventCount } = useEventVisibilityAgenda({
17068
+ eventGap: EventGapAgenda,
17069
+ eventHeight: EventHeightAgenda
17070
+ });
17071
+ useEffect28(() => {
17072
+ setIsMounted(true);
17073
+ }, []);
17074
+ return /* @__PURE__ */ jsxs72("div", { className: "contents", "data-slot": "month-view", children: [
17075
+ /* @__PURE__ */ jsx93("div", { className: "grid grid-cols-7 border-border/70 border-b", children: weekdays.map((day) => /* @__PURE__ */ jsx93(
17076
+ "div",
17077
+ {
17078
+ className: "py-2 text-center text-muted-foreground/70 text-sm uppercase tracking-wide bg-muted/5",
17079
+ children: day
17080
+ },
17081
+ day
17082
+ )) }),
17083
+ /* @__PURE__ */ jsx93("div", { className: "grid flex-1 auto-rows-fr", children: weeks.map((week, weekIndex) => /* @__PURE__ */ jsx93(
17084
+ "div",
17085
+ {
17086
+ className: "grid grid-cols-7 [&:last-child>*]:border-b-0",
17087
+ children: week.map((day, dayIndex) => {
17088
+ if (!day) return null;
17089
+ const dayEvents = getEventsForDayAgenda(events, day);
17090
+ const spanningEvents = getSpanningEventsForDayAgenda(events, day);
17091
+ const isCurrentMonth = isSameMonth4(day, currentDate);
17092
+ const cellId = `month-cell-${day.toISOString()}`;
17093
+ const allDayEvents = [...spanningEvents, ...dayEvents];
17094
+ const allEvents = getAllEventsForDayAgenda(events, day);
17095
+ const isReferenceCell = weekIndex === 0 && dayIndex === 0;
17096
+ const visibleCount = isMounted ? getVisibleEventCount(allDayEvents.length) : void 0;
17097
+ const hasMore = visibleCount !== void 0 && allDayEvents.length > visibleCount;
17098
+ const remainingCount = hasMore ? allDayEvents.length - visibleCount : 0;
17099
+ return /* @__PURE__ */ jsx93(
17100
+ "div",
17101
+ {
17102
+ className: "group border-border/70 border-r border-b last:border-r-0 data-outside-cell:bg-muted/25 data-outside-cell:text-muted-foreground/70 hover:bg-muted/5 transition-colors p-2 ",
17103
+ "data-outside-cell": !isCurrentMonth || void 0,
17104
+ "data-today": isToday5(day) || void 0,
17105
+ children: /* @__PURE__ */ jsxs72(
17106
+ DroppableCellAgenda,
17107
+ {
17108
+ date: day,
17109
+ id: cellId,
17110
+ onClick: () => {
17111
+ const startTime = new Date(day);
17112
+ startTime.setHours(DefaultStartHourAgenda, 0, 0);
17113
+ },
17114
+ children: [
17115
+ /* @__PURE__ */ jsx93(
17116
+ "div",
17117
+ {
17118
+ className: twMerge3(
17119
+ `mt-1 inline-flex w-7 h-7 items-center justify-center rounded-full text-sm font-semibold text-muted-foreground`,
17120
+ isToday5(day) ? "bg-blue-500 text-white" : ""
17121
+ ),
17122
+ children: format15(day, "d")
17123
+ }
17124
+ ),
17125
+ /* @__PURE__ */ jsxs72(
17126
+ "div",
17127
+ {
17128
+ className: "min-h-[calc((var(--event-height)+var(--event-gap))*2)] sm:min-h-[calc((var(--event-height)+var(--event-gap))*3)] lg:min-h-[calc((var(--event-height)+var(--event-gap))*4)] px-1 py-1",
17129
+ ref: isReferenceCell ? contentRef : null,
17130
+ children: [
17131
+ sortEventsAgenda(allDayEvents).map((event, index) => {
17132
+ const eventStart = new Date(
17133
+ event.start ?? event.attend_date ?? event.end ?? Date.now()
17134
+ );
17135
+ const eventEnd = new Date(
17136
+ event.end ?? event.attend_date ?? event.start ?? Date.now()
17137
+ );
17138
+ const isFirstDay = isSameDay10(day, eventStart);
17139
+ const isLastDay = isSameDay10(day, eventEnd);
17140
+ const isHidden = isMounted && visibleCount && index >= visibleCount;
17141
+ if (!visibleCount) return null;
17142
+ if (!isFirstDay) {
17143
+ return /* @__PURE__ */ jsx93(
17144
+ "div",
17145
+ {
17146
+ "aria-hidden": isHidden ? "true" : void 0,
17147
+ className: "aria-hidden:hidden",
17148
+ children: /* @__PURE__ */ jsx93(
17149
+ EventItemAgenda,
17150
+ {
17151
+ event,
17152
+ isFirstDay,
17153
+ isLastDay,
17154
+ onClick: (e) => handleEventClick(event, e),
17155
+ view: "month",
17156
+ children: /* @__PURE__ */ jsxs72("div", { "aria-hidden": true, className: "invisible", children: [
17157
+ !event.allDay && /* @__PURE__ */ jsxs72("span", { children: [
17158
+ format15(eventStart, "HH:mm"),
17159
+ " "
17160
+ ] }),
17161
+ event.title
17162
+ ] })
17163
+ }
17164
+ )
17165
+ },
17166
+ `spanning-${event.id}-${day.toISOString().slice(0, 10)}`
17167
+ );
17168
+ }
17169
+ return /* @__PURE__ */ jsx93(
17170
+ "div",
17171
+ {
17172
+ "aria-hidden": isHidden ? "true" : void 0,
17173
+ className: "aria-hidden:hidden",
17174
+ children: /* @__PURE__ */ jsx93(
17175
+ EventItemAgenda,
17176
+ {
17177
+ className: "cursor-default",
17178
+ event,
17179
+ isFirstDay,
17180
+ isLastDay,
17181
+ onClick: (e) => handleEventClick(event, e),
17182
+ view: "month",
17183
+ children: /* @__PURE__ */ jsxs72("span", { className: "flex items-center gap-2 truncate", children: [
17184
+ !event.allDay && /* @__PURE__ */ jsx93("span", { className: "truncate font-normal opacity-80 sm:text-[11px] bg-white/10 px-2 py-0.5 rounded-full text-[11px]", children: format15(eventStart, "HH:mm") }),
17185
+ /* @__PURE__ */ jsx93("span", { className: "truncate font-medium", children: event.title })
17186
+ ] })
17187
+ }
17188
+ )
17189
+ },
17190
+ event.id
17191
+ );
17192
+ }),
17193
+ hasMore && /* @__PURE__ */ jsxs72(PopoverBase, { modal: true, children: [
17194
+ /* @__PURE__ */ jsx93(PopoverTriggerBase, { asChild: true, children: /* @__PURE__ */ jsxs72(
17195
+ "button",
17196
+ {
17197
+ className: "mt-[var(--event-gap)] flex h-[var(--event-height)] w-full select-none items-center overflow-hidden px-2 text-left text-[10px] text-muted-foreground outline-none backdrop-blur-md rounded-md transition hover:bg-muted/60 hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 sm:text-xs",
17198
+ onClick: (e) => e.stopPropagation(),
17199
+ type: "button",
17200
+ "aria-label": `Show ${remainingCount} more events on ${format15(
17201
+ day,
17202
+ "PPP",
17203
+ { locale: ptBR13 }
17204
+ )}`,
17205
+ children: [
17206
+ /* @__PURE__ */ jsxs72("span", { className: "font-medium", children: [
17207
+ "+ ",
17208
+ remainingCount
17209
+ ] }),
17210
+ /* @__PURE__ */ jsx93("span", { className: "sr-only", children: " more" })
17211
+ ]
17212
+ }
17213
+ ) }),
17214
+ /* @__PURE__ */ jsx93(
17215
+ PopoverContentBase,
17216
+ {
17217
+ align: "center",
17218
+ className: "max-w-52 p-3",
17219
+ style: {
17220
+ "--event-height": `${EventHeightAgenda}px`
17221
+ },
17222
+ children: /* @__PURE__ */ jsxs72("div", { className: "space-y-2", children: [
17223
+ /* @__PURE__ */ jsx93("div", { className: "font-medium text-sm", children: format15(day, "EEE d", { locale: ptBR13 }) }),
17224
+ /* @__PURE__ */ jsx93("div", { className: "space-y-1", children: sortEventsAgenda(allEvents).map((event) => {
17225
+ const eventStart = new Date(
17226
+ event.start ?? event.end ?? Date.now()
17227
+ );
17228
+ const eventEnd = new Date(
17229
+ event.end ?? event.start ?? Date.now()
17230
+ );
17231
+ const isFirstDay = isSameDay10(day, eventStart);
17232
+ const isLastDay = isSameDay10(day, eventEnd);
17233
+ return /* @__PURE__ */ jsx93(
17234
+ EventItemAgenda,
17235
+ {
17236
+ event,
17237
+ isFirstDay,
17238
+ isLastDay,
17239
+ onClick: (e) => handleEventClick(event, e),
17240
+ view: "month"
17241
+ },
17242
+ event.id
17243
+ );
17244
+ }) })
17245
+ ] })
17246
+ }
17247
+ )
17248
+ ] })
17249
+ ]
17250
+ }
17251
+ )
17252
+ ]
17253
+ }
17254
+ )
17255
+ },
17256
+ day.toString()
17257
+ );
17258
+ })
17259
+ },
17260
+ `week-${week}`
17261
+ )) }),
17262
+ /* @__PURE__ */ jsx93(
17263
+ UndatedEvents,
17264
+ {
17265
+ events,
17266
+ onEventSelect,
17267
+ className: "my-12",
17268
+ show: showUndatedEvents
17269
+ }
17270
+ )
17271
+ ] });
17272
+ }
17273
+
17274
+ // src/components/event-calendar-view/WeekView.tsx
17275
+ import {
17276
+ addHours as addHours6,
17277
+ areIntervalsOverlapping as areIntervalsOverlapping4,
17278
+ differenceInMinutes as differenceInMinutes8,
17279
+ eachDayOfInterval as eachDayOfInterval4,
17280
+ eachHourOfInterval as eachHourOfInterval4,
17281
+ endOfWeek as endOfWeek8,
17282
+ format as format16,
17283
+ getHours as getHours4,
17284
+ getMinutes as getMinutes4,
17285
+ isBefore as isBefore3,
17286
+ isSameDay as isSameDay11,
17287
+ isToday as isToday6,
17288
+ startOfDay as startOfDay4,
17289
+ startOfWeek as startOfWeek8
17290
+ } from "date-fns";
17291
+ import { endOfDay as endOfDay2 } from "date-fns";
17292
+ import { ptBR as ptBR14 } from "date-fns/locale";
17293
+ import { useMemo as useMemo26 } from "react";
17294
+
17295
+ // src/components/event-calendar-view/DraggablaEvent.tsx
17296
+ import { useDraggable as useDraggable2 } from "@dnd-kit/core";
17297
+ import { CSS as CSS2 } from "@dnd-kit/utilities";
17298
+ import { differenceInDays as differenceInDays2 } from "date-fns";
17299
+ import { useRef as useRef17, useState as useState36 } from "react";
17300
+ import { jsx as jsx94 } from "react/jsx-runtime";
17301
+ function DraggableEvent2({
17302
+ event,
17303
+ view,
17304
+ showTime,
17305
+ onClick,
17306
+ height,
17307
+ isMultiDay,
17308
+ multiDayWidth,
17309
+ isFirstDay = true,
17310
+ isLastDay = true,
17311
+ "aria-hidden": ariaHidden
17312
+ }) {
17313
+ const { activeId } = useCalendarDndAgenda();
17314
+ const elementRef = useRef17(null);
17315
+ const [dragHandlePosition, setDragHandlePosition] = useState36(null);
17316
+ const eventStart = new Date(event.start ?? Date.now());
17317
+ const eventEnd = new Date(event.end ?? Date.now());
17318
+ const isMultiDayEvent2 = isMultiDay || event.allDay || differenceInDays2(eventEnd, eventStart) >= 1;
17319
+ const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable2({
17320
+ data: {
17321
+ dragHandlePosition,
17322
+ event,
17323
+ height: height || elementRef.current?.offsetHeight || null,
17324
+ isFirstDay,
17325
+ isLastDay,
17326
+ isMultiDay: isMultiDayEvent2,
17327
+ multiDayWidth,
17328
+ view
17329
+ },
17330
+ id: `${event.id}-${view}`
17331
+ });
17332
+ const handleMouseDown = (e) => {
17333
+ if (elementRef.current) {
17334
+ const rect = elementRef.current.getBoundingClientRect();
17335
+ setDragHandlePosition({
17336
+ x: e.clientX - rect.left,
17337
+ y: e.clientY - rect.top
17338
+ });
17339
+ }
17340
+ };
17341
+ if (isDragging || activeId === `${event.id}-${view}`) {
17342
+ return /* @__PURE__ */ jsx94(
17343
+ "div",
17344
+ {
17345
+ className: "opacity-0",
17346
+ ref: setNodeRef,
17347
+ style: { height: height || "auto" }
17348
+ }
17349
+ );
17350
+ }
17351
+ const style = transform ? {
17352
+ height: height || "auto",
17353
+ transform: CSS2.Translate.toString(transform),
17354
+ width: isMultiDayEvent2 && multiDayWidth ? `${multiDayWidth}%` : void 0
17355
+ } : {
17356
+ height: height || "auto",
17357
+ width: isMultiDayEvent2 && multiDayWidth ? `${multiDayWidth}%` : void 0
17358
+ };
17359
+ const handleTouchStart = (e) => {
17360
+ if (elementRef.current) {
17361
+ const rect = elementRef.current.getBoundingClientRect();
17362
+ const touch = e.touches[0];
17363
+ if (touch) {
17364
+ setDragHandlePosition({
17365
+ x: touch.clientX - rect.left,
17366
+ y: touch.clientY - rect.top
17367
+ });
17368
+ }
17369
+ }
17370
+ };
17371
+ return /* @__PURE__ */ jsx94(
17372
+ "div",
17373
+ {
17374
+ className: "touch-none",
17375
+ ref: (node) => {
17376
+ setNodeRef(node);
17377
+ if (elementRef) elementRef.current = node;
17378
+ },
17379
+ style,
17380
+ children: /* @__PURE__ */ jsx94(
17381
+ EventItemAgenda,
17382
+ {
17383
+ "aria-hidden": ariaHidden,
17384
+ dndAttributes: attributes,
17385
+ dndListeners: listeners,
17386
+ event,
17387
+ isDragging,
17388
+ isFirstDay,
17389
+ isLastDay,
17390
+ onClick,
17391
+ onMouseDown: handleMouseDown,
17392
+ onTouchStart: handleTouchStart,
17393
+ showTime,
17394
+ view
17395
+ }
17396
+ )
17397
+ }
17398
+ );
17399
+ }
17400
+
17401
+ // src/components/event-calendar-view/WeekView.tsx
17402
+ import { jsx as jsx95, jsxs as jsxs73 } from "react/jsx-runtime";
17403
+ function WeekViewAgenda({
17404
+ currentDate,
17405
+ events,
17406
+ onEventSelect,
17407
+ onEventCreate
17408
+ }) {
17409
+ const days = useMemo26(() => {
17410
+ const weekStart2 = startOfWeek8(currentDate, { weekStartsOn: 0 });
17411
+ const weekEnd = endOfWeek8(currentDate, { weekStartsOn: 0 });
17412
+ return eachDayOfInterval4({ end: weekEnd, start: weekStart2 });
17413
+ }, [currentDate]);
17414
+ const weekStart = useMemo26(
17415
+ () => startOfWeek8(currentDate, { weekStartsOn: 0 }),
17416
+ [currentDate]
17417
+ );
17418
+ const hours = useMemo26(() => {
17419
+ const dayStart = startOfDay4(currentDate);
17420
+ return eachHourOfInterval4({
17421
+ end: addHours6(dayStart, EndHour - 1),
17422
+ start: addHours6(dayStart, StartHour)
17423
+ });
17424
+ }, [currentDate]);
17425
+ const allDayEvents = useMemo26(() => {
17426
+ return events.filter((event) => {
17427
+ return event.allDay || isMultiDayEventAgenda(event);
17428
+ }).filter((event) => {
17429
+ const eventStart = event.start ? new Date(event.start) : void 0;
17430
+ const eventEnd = event.end ? new Date(event.end) : void 0;
17431
+ return days.some((day) => {
17432
+ if (eventStart && isSameDay11(day, eventStart)) return true;
17433
+ if (eventEnd && isSameDay11(day, eventEnd)) return true;
17434
+ if (eventStart && eventEnd && day > eventStart && day < eventEnd) return true;
17435
+ return false;
17436
+ });
17437
+ });
17438
+ }, [events, days]);
17439
+ const processedDayEvents = useMemo26(() => {
17440
+ const result = days.map((day) => {
17441
+ const dayEventsWithIntervals = events.filter((event) => !event.allDay && !isMultiDayEventAgenda(event)).map((event) => {
17442
+ let eventStart = event.start != null ? new Date(event.start) : void 0;
17443
+ let eventEnd = event.end != null ? new Date(event.end) : void 0;
17444
+ if ((!eventStart || !eventEnd) && event.attend_date) {
17445
+ try {
17446
+ const ad = new Date(event.attend_date);
17447
+ const hasTime = ad.getHours() !== 0 || ad.getMinutes() !== 0 || ad.getSeconds() !== 0 || ad.getMilliseconds() !== 0;
17448
+ if (hasTime) {
17449
+ if (!eventStart) eventStart = ad;
17450
+ if (!eventEnd) eventEnd = addHours6(ad, 1);
17451
+ }
17452
+ } catch {
17453
+ }
17454
+ }
17455
+ return { event, eventStart, eventEnd };
17456
+ }).filter(({ eventStart, eventEnd }) => !!eventStart && !!eventEnd).filter(({ eventStart, eventEnd }) => {
17457
+ const dayStart2 = startOfDay4(day);
17458
+ const dayEnd = endOfDay2(day);
17459
+ return areIntervalsOverlapping4(
17460
+ { start: eventStart, end: eventEnd },
17461
+ { start: dayStart2, end: dayEnd }
17462
+ );
17463
+ });
17464
+ const sortedEvents = [...dayEventsWithIntervals].sort((a, b) => {
17465
+ const aStart = a.eventStart.getTime();
17466
+ const bStart = b.eventStart.getTime();
17467
+ if (aStart < bStart) return -1;
17468
+ if (aStart > bStart) return 1;
17469
+ const aDuration = differenceInMinutes8(
17470
+ a.eventEnd,
17471
+ a.eventStart
17472
+ );
17473
+ const bDuration = differenceInMinutes8(
17474
+ b.eventEnd,
17475
+ b.eventStart
17476
+ );
17477
+ return bDuration - aDuration;
17478
+ });
17479
+ const positionedEvents = [];
17480
+ const dayStart = startOfDay4(day);
17481
+ const columns = [];
17482
+ for (const item of sortedEvents) {
17483
+ const event = item.event;
17484
+ const eventStart = item.eventStart;
17485
+ const eventEnd = item.eventEnd;
17486
+ const adjustedStart = isSameDay11(day, eventStart) ? eventStart : dayStart;
17487
+ const adjustedEnd = isSameDay11(day, eventEnd) ? eventEnd : addHours6(dayStart, 24);
17488
+ const startHour = getHours4(adjustedStart) + getMinutes4(adjustedStart) / 60;
17489
+ const endHour = getHours4(adjustedEnd) + getMinutes4(adjustedEnd) / 60;
17490
+ const top = (startHour - StartHour) * WeekCellsHeightAgenda;
17491
+ const height = (endHour - startHour) * WeekCellsHeightAgenda;
17492
+ let columnIndex = 0;
17493
+ let placed = false;
17494
+ while (!placed) {
17495
+ const col = columns[columnIndex] || [];
17496
+ if (col.length === 0) {
17497
+ columns[columnIndex] = col;
17498
+ placed = true;
17499
+ } else {
17500
+ const overlaps = col.some(
17501
+ (c) => areIntervalsOverlapping4(
17502
+ { end: adjustedEnd, start: adjustedStart },
17503
+ { end: c.end, start: c.start }
17504
+ )
17505
+ );
17506
+ if (!overlaps) {
17507
+ placed = true;
17508
+ } else {
17509
+ columnIndex++;
17510
+ }
17511
+ }
17512
+ }
17513
+ const currentColumn = columns[columnIndex] || [];
17514
+ columns[columnIndex] = currentColumn;
17515
+ currentColumn.push({ start: adjustedStart, end: adjustedEnd, event });
17516
+ const width = columnIndex === 0 ? 1 : 0.7;
17517
+ const left = columnIndex === 0 ? 0 : columnIndex * 0.3;
17518
+ positionedEvents.push({
17519
+ event,
17520
+ height,
17521
+ left,
17522
+ top,
17523
+ width,
17524
+ zIndex: 10 + columnIndex
17525
+ });
17526
+ }
17527
+ return positionedEvents;
17528
+ });
17529
+ return result;
17530
+ }, [days, events]);
17531
+ const handleEventClick = (event, e) => {
17532
+ e.stopPropagation();
17533
+ onEventSelect(event);
17534
+ };
17535
+ const showAllDaySection = allDayEvents.length > 0;
17536
+ const { currentTimePosition, currentTimeVisible } = useCurrentTimeIndicatorAgenda(
17537
+ currentDate,
17538
+ "week"
17539
+ );
17540
+ return /* @__PURE__ */ jsxs73("div", { className: "flex h-full flex-col", "data-slot": "week-view", children: [
17541
+ /* @__PURE__ */ jsxs73("div", { className: "sticky top-0 z-30 grid grid-cols-8 border-border/70 border-b bg-background", children: [
17542
+ /* @__PURE__ */ jsx95("div", { className: "py-2 text-center text-muted-foreground/70 text-sm", children: /* @__PURE__ */ jsx95("span", { className: "max-[479px]:sr-only", children: format16(/* @__PURE__ */ new Date(), "O") }) }),
17543
+ days.map((day) => /* @__PURE__ */ jsxs73(
17544
+ "div",
17545
+ {
17546
+ className: "py-2 text-center text-muted-foreground/70 text-sm data-today:font-medium data-today:text-foreground",
17547
+ "data-today": isToday6(day) || void 0,
17548
+ children: [
17549
+ /* @__PURE__ */ jsxs73("span", { "aria-hidden": "true", className: "sm:hidden", children: [
17550
+ format16(day, "EEE", { locale: ptBR14 })[0],
17551
+ " ",
17552
+ format16(day, "d", { locale: ptBR14 })
17553
+ ] }),
17554
+ /* @__PURE__ */ jsx95("span", { className: "max-sm:hidden", children: format16(day, "EEE dd", { locale: ptBR14 }) })
17555
+ ]
17556
+ },
17557
+ day.toString()
17558
+ ))
17559
+ ] }),
17560
+ showAllDaySection && /* @__PURE__ */ jsx95("div", { className: "border-border/70 border-b bg-muted/50", children: /* @__PURE__ */ jsxs73("div", { className: "grid grid-cols-8", children: [
17561
+ /* @__PURE__ */ jsx95("div", { className: "relative border-border/70 border-r", children: /* @__PURE__ */ jsx95("span", { className: "absolute bottom-0 left-0 h-6 w-16 max-w-full pe-2 text-right text-[10px] text-muted-foreground/70 sm:pe-4 sm:text-xs", children: "All day" }) }),
17562
+ days.map((day, dayIndex) => {
17563
+ const dayAllDayEvents = allDayEvents.filter((event) => {
17564
+ const eventStart = event.start ? new Date(event.start) : void 0;
17565
+ const eventEnd = event.end ? new Date(event.end) : void 0;
17566
+ if (!eventStart && !eventEnd) return false;
17567
+ return eventStart && isSameDay11(day, eventStart) || eventStart && eventEnd && day > eventStart && day < eventEnd || eventEnd && isSameDay11(day, eventEnd);
17568
+ });
17569
+ return /* @__PURE__ */ jsx95(
17570
+ "div",
17571
+ {
17572
+ className: "relative border-border/70 border-r p-1 last:border-r-0",
17573
+ "data-today": isToday6(day) || void 0,
17574
+ children: dayAllDayEvents.map((event) => {
17575
+ const eventStart = event.start ? new Date(event.start) : void 0;
17576
+ const eventEnd = event.end ? new Date(event.end) : void 0;
17577
+ const isFirstDay = eventStart ? isSameDay11(day, eventStart) : false;
17578
+ const isLastDay = eventEnd ? isSameDay11(day, eventEnd) : false;
17579
+ const isFirstVisibleDay = eventStart ? dayIndex === 0 && isBefore3(eventStart, weekStart) : false;
17580
+ const shouldShowTitle = isFirstDay || isFirstVisibleDay;
17581
+ return /* @__PURE__ */ jsx95(
17582
+ EventItemAgenda,
17583
+ {
17584
+ event,
17585
+ isFirstDay,
17586
+ isLastDay,
17587
+ onClick: (e) => handleEventClick(event, e),
17588
+ view: "month",
17589
+ children: /* @__PURE__ */ jsx95(
17590
+ "div",
17591
+ {
17592
+ "aria-hidden": !shouldShowTitle,
17593
+ className: cn(
17594
+ "truncate",
17595
+ !shouldShowTitle && "invisible"
17596
+ ),
17597
+ children: event.title
17598
+ }
17599
+ )
17600
+ },
17601
+ `spanning-${event.id}`
17602
+ );
17603
+ })
17604
+ },
17605
+ day.toString()
17606
+ );
17607
+ })
17608
+ ] }) }),
17609
+ /* @__PURE__ */ jsxs73("div", { className: "grid flex-1 grid-cols-8 overflow-hidden", children: [
17610
+ /* @__PURE__ */ jsx95("div", { className: "grid auto-cols-fr border-border/70 border-r", children: hours.map((hour, index) => /* @__PURE__ */ jsx95(
17611
+ "div",
17612
+ {
17613
+ className: "relative min-h-[var(--week-cells-height)] border-border/70 border-b last:border-b-0",
17614
+ children: index > 0 && /* @__PURE__ */ jsx95("span", { className: "-top-3 absolute left-0 flex h-6 w-16 max-w-full items-center justify-end bg-background pe-2 text-[10px] text-muted-foreground/70 sm:pe-4 sm:text-xs", children: format16(hour, "HH:mm") })
17615
+ },
17616
+ hour.toString()
17617
+ )) }),
17618
+ days.map((day, dayIndex) => /* @__PURE__ */ jsxs73(
17619
+ "div",
17620
+ {
17621
+ className: "relative grid auto-cols-fr border-border/70 border-r last:border-r-0",
17622
+ "data-today": isToday6(day) || void 0,
17623
+ children: [
17624
+ (processedDayEvents[dayIndex] ?? []).map((positionedEvent) => /* @__PURE__ */ jsx95(
17625
+ "div",
17626
+ {
17627
+ className: "absolute z-10 px-0.5",
17628
+ onClick: (e) => e.stopPropagation(),
17629
+ style: {
17630
+ height: `${positionedEvent.height}px`,
17631
+ left: `${positionedEvent.left * 100}%`,
17632
+ top: `${positionedEvent.top}px`,
17633
+ width: `${positionedEvent.width * 100}%`,
17634
+ zIndex: positionedEvent.zIndex
17635
+ },
17636
+ children: /* @__PURE__ */ jsx95("div", { className: "size-full", children: /* @__PURE__ */ jsx95(
17637
+ DraggableEvent2,
17638
+ {
17639
+ event: positionedEvent.event,
17640
+ height: positionedEvent.height,
17641
+ onClick: (e) => handleEventClick(positionedEvent.event, e),
17642
+ showTime: true,
17643
+ view: "week"
17644
+ }
17645
+ ) })
17646
+ },
17647
+ positionedEvent.event.id
17648
+ )),
17649
+ currentTimeVisible && isToday6(day) && /* @__PURE__ */ jsx95(
17650
+ "div",
17651
+ {
17652
+ className: "pointer-events-none absolute right-0 left-0 z-20",
17653
+ style: { top: `${currentTimePosition}%` },
17654
+ children: /* @__PURE__ */ jsxs73("div", { className: "relative flex items-center", children: [
17655
+ /* @__PURE__ */ jsx95("div", { className: "-left-1 absolute h-2 w-2 rounded-full bg-primary" }),
17656
+ /* @__PURE__ */ jsx95("div", { className: "h-[2px] w-full bg-primary" })
17657
+ ] })
17658
+ }
17659
+ ),
17660
+ hours.map((hour) => {
17661
+ const hourValue = getHours4(hour);
17662
+ return /* @__PURE__ */ jsx95(
17663
+ "div",
17664
+ {
17665
+ className: "relative min-h-[var(--week-cells-height)] border-border/70 border-b last:border-b-0",
17666
+ children: [0, 1, 2, 3].map((quarter) => {
17667
+ const quarterHourTime = hourValue + quarter * 0.25;
17668
+ return /* @__PURE__ */ jsx95(
17669
+ DroppableCellAgenda,
17670
+ {
17671
+ className: cn(
17672
+ "absolute h-[calc(var(--week-cells-height)/4)] w-full",
17673
+ quarter === 0 && "top-0",
17674
+ quarter === 1 && "top-[calc(var(--week-cells-height)/4)]",
17675
+ quarter === 2 && "top-[calc(var(--week-cells-height)/4*2)]",
17676
+ quarter === 3 && "top-[calc(var(--week-cells-height)/4*)]"
17677
+ ),
17678
+ date: day,
17679
+ id: `week-cell-${day.toISOString()}-${quarterHourTime}`,
17680
+ onClick: () => {
17681
+ const startTime = new Date(day);
17682
+ startTime.setHours(hourValue);
17683
+ startTime.setMinutes(quarter * 15);
17684
+ if (onEventCreate) onEventCreate(startTime);
17685
+ },
17686
+ time: quarterHourTime
17687
+ },
17688
+ `${hour.toString()}-${quarter}`
17689
+ );
17690
+ })
17691
+ },
17692
+ hour.toString()
17693
+ );
17694
+ })
17695
+ ]
17696
+ },
17697
+ day.toString()
17698
+ ))
17699
+ ] })
17700
+ ] });
17701
+ }
17702
+
17703
+ // src/components/ui/data/Banner.tsx
17704
+ import { RocketIcon, XIcon as XIcon13 } from "@phosphor-icons/react";
17705
+ import React45, { useState as useState37 } from "react";
17706
+ import { jsx as jsx96, jsxs as jsxs74 } from "react/jsx-runtime";
17707
+
15413
17708
  // src/hooks/use-drag.tsx
15414
- import { useState as useState31, useCallback as useCallback16, useRef as useRef15, useEffect as useEffect26 } from "react";
17709
+ import { useState as useState38, useCallback as useCallback17, useRef as useRef18, useEffect as useEffect29 } from "react";
15415
17710
  var useDrag = (options = {}) => {
15416
- const [isDragging, setIsDragging] = useState31(null);
15417
- const [positions, setPositions] = useState31({});
15418
- const dragStartPos = useRef15(null);
15419
- const dragId = useRef15(null);
15420
- const handleMouseDown = useCallback16((id, e) => {
17711
+ const [isDragging, setIsDragging] = useState38(null);
17712
+ const [positions, setPositions] = useState38({});
17713
+ const dragStartPos = useRef18(null);
17714
+ const dragId = useRef18(null);
17715
+ const handleMouseDown = useCallback17((id, e) => {
15421
17716
  e.preventDefault();
15422
17717
  const currentPosition = positions[id] || { top: 0, left: 0 };
15423
17718
  dragStartPos.current = {
@@ -15430,7 +17725,7 @@ var useDrag = (options = {}) => {
15430
17725
  setIsDragging(id);
15431
17726
  options.onDragStart?.(id);
15432
17727
  }, [positions, options]);
15433
- const handleMouseMove = useCallback16((e) => {
17728
+ const handleMouseMove = useCallback17((e) => {
15434
17729
  if (!isDragging || !dragStartPos.current || !dragId.current) return;
15435
17730
  const deltaX = e.clientX - dragStartPos.current.x;
15436
17731
  const deltaY = e.clientY - dragStartPos.current.y;
@@ -15446,7 +17741,7 @@ var useDrag = (options = {}) => {
15446
17741
  }));
15447
17742
  options.onDrag?.(dragId.current, newPosition);
15448
17743
  }, [isDragging, options]);
15449
- const handleMouseUp = useCallback16(() => {
17744
+ const handleMouseUp = useCallback17(() => {
15450
17745
  if (dragId.current) {
15451
17746
  options.onDragEnd?.(dragId.current);
15452
17747
  }
@@ -15454,7 +17749,7 @@ var useDrag = (options = {}) => {
15454
17749
  dragStartPos.current = null;
15455
17750
  dragId.current = null;
15456
17751
  }, [options]);
15457
- useEffect26(() => {
17752
+ useEffect29(() => {
15458
17753
  if (isDragging) {
15459
17754
  document.addEventListener("mousemove", handleMouseMove);
15460
17755
  document.addEventListener("mouseup", handleMouseUp);
@@ -15466,16 +17761,16 @@ var useDrag = (options = {}) => {
15466
17761
  };
15467
17762
  }
15468
17763
  }, [isDragging, handleMouseMove, handleMouseUp]);
15469
- const setPosition = useCallback16((id, position) => {
17764
+ const setPosition = useCallback17((id, position) => {
15470
17765
  setPositions((prev) => ({
15471
17766
  ...prev,
15472
17767
  [id]: position
15473
17768
  }));
15474
17769
  }, []);
15475
- const getPosition = useCallback16((id) => {
17770
+ const getPosition = useCallback17((id) => {
15476
17771
  return positions[id] || { top: 0, left: 0 };
15477
17772
  }, [positions]);
15478
- const isElementDragging = useCallback16((id) => {
17773
+ const isElementDragging = useCallback17((id) => {
15479
17774
  return isDragging === id;
15480
17775
  }, [isDragging]);
15481
17776
  return {
@@ -15488,7 +17783,9 @@ var useDrag = (options = {}) => {
15488
17783
  };
15489
17784
  export {
15490
17785
  AddButton,
17786
+ Agenda,
15491
17787
  AgendaDaysToShow,
17788
+ AgendaDaysToShowAgenda,
15492
17789
  AgendaView,
15493
17790
  AlertDialogActionBase,
15494
17791
  AlertDialogBase,
@@ -15519,6 +17816,7 @@ export {
15519
17816
  ButtonGroupBase,
15520
17817
  CalendarBase,
15521
17818
  CalendarDndProvider,
17819
+ CalendarDndProviderAgenda,
15522
17820
  CardBase,
15523
17821
  CardContentBase,
15524
17822
  CardDescriptionBase,
@@ -15569,9 +17867,12 @@ export {
15569
17867
  CopyButton,
15570
17868
  DateTimePicker,
15571
17869
  DayView,
17870
+ DayViewAgenda,
15572
17871
  DebouncedInput,
15573
17872
  DefaultEndHour,
17873
+ DefaultEndHourAgenda,
15574
17874
  DefaultStartHour,
17875
+ DefaultStartHourAgenda,
15575
17876
  DestructiveDialog,
15576
17877
  DialogBase,
15577
17878
  DialogCloseBase,
@@ -15612,14 +17913,20 @@ export {
15612
17913
  DropDownMenuSubTriggerBase,
15613
17914
  DropDownMenuTriggerBase,
15614
17915
  DroppableCell,
17916
+ DroppableCellAgenda,
15615
17917
  EditButton,
15616
17918
  EndHour,
17919
+ EndHourAgenda,
15617
17920
  ErrorMessage_default as ErrorMessage,
17921
+ EventAgenda,
15618
17922
  EventCalendar,
15619
17923
  EventDialog,
15620
17924
  EventGap,
17925
+ EventGapAgenda,
15621
17926
  EventHeight,
17927
+ EventHeightAgenda,
15622
17928
  EventItem,
17929
+ EventItemAgenda,
15623
17930
  EventsPopup,
15624
17931
  FavoriteButton,
15625
17932
  FileUploader,
@@ -15651,6 +17958,7 @@ export {
15651
17958
  ModalTriggerBase,
15652
17959
  ModeToggleBase,
15653
17960
  MonthView,
17961
+ MonthViewAgenda,
15654
17962
  MoreButton,
15655
17963
  MultiCombobox,
15656
17964
  MultiSelectBase,
@@ -15736,6 +18044,7 @@ export {
15736
18044
  SkeletonBase,
15737
18045
  SlideBase,
15738
18046
  StartHour,
18047
+ StartHourAgenda,
15739
18048
  StatusIndicator,
15740
18049
  SwitchBase,
15741
18050
  TableBase,
@@ -15761,6 +18070,7 @@ export {
15761
18070
  TooltipSimple_default as TooltipSimple,
15762
18071
  TooltipTriggerBase,
15763
18072
  TooltipWithTotal_default as TooltipWithTotal,
18073
+ UndatedEvents,
15764
18074
  UniversalTooltipRenderer,
15765
18075
  UnlockButton,
15766
18076
  UploadButton,
@@ -15768,8 +18078,11 @@ export {
15768
18078
  ViewButton,
15769
18079
  VisibilityButton,
15770
18080
  WeekCellsHeight,
18081
+ WeekCellsHeightAgenda,
15771
18082
  WeekView,
18083
+ WeekViewAgenda,
15772
18084
  addHoursToDate,
18085
+ addHoursToDateAgenda,
15773
18086
  badgeVariants,
15774
18087
  buttonVariantsBase,
15775
18088
  compactTick,
@@ -15780,13 +18093,19 @@ export {
15780
18093
  formatFieldName,
15781
18094
  generateAdditionalColors,
15782
18095
  getAgendaEventsForDay,
18096
+ getAgendaEventsForDayAgenda,
15783
18097
  getAllEventsForDay,
18098
+ getAllEventsForDayAgenda,
15784
18099
  getArrowByType,
15785
18100
  getBorderRadiusClasses,
18101
+ getBorderRadiusClassesAgenda,
15786
18102
  getDateByType,
15787
18103
  getEventColorClasses,
18104
+ getEventColorClassesAgenda,
15788
18105
  getEventsForDay,
18106
+ getEventsForDayAgenda,
15789
18107
  getSpanningEventsForDay,
18108
+ getSpanningEventsForDayAgenda,
15790
18109
  getValid12Hour,
15791
18110
  getValidArrow12Hour,
15792
18111
  getValidArrowHour,
@@ -15796,10 +18115,12 @@ export {
15796
18115
  getValidMinuteOrSecond,
15797
18116
  getValidNumber,
15798
18117
  isMultiDayEvent,
18118
+ isMultiDayEventAgenda,
15799
18119
  isValid12Hour,
15800
18120
  isValidHour,
15801
18121
  isValidMinuteOrSecond,
15802
18122
  niceCeil,
18123
+ normalizeAttendDate,
15803
18124
  renderInsideBarLabel,
15804
18125
  pillLabelRenderer_default as renderPillLabel,
15805
18126
  resolveChartMargins,
@@ -15810,12 +18131,16 @@ export {
15810
18131
  setMinutes,
15811
18132
  setSeconds,
15812
18133
  sortEvents,
18134
+ sortEventsAgenda,
15813
18135
  toast2 as toast,
15814
18136
  useCalendarDnd,
18137
+ useCalendarDndAgenda,
15815
18138
  useChartHighlights,
15816
18139
  useCurrentTimeIndicator,
18140
+ useCurrentTimeIndicatorAgenda,
15817
18141
  useDrag,
15818
18142
  useEventVisibility,
18143
+ useEventVisibilityAgenda,
15819
18144
  useIsMobile,
15820
18145
  useTheme
15821
18146
  };