{"version":3,"file":"WeekViewDay.mjs","names":[],"sources":["../../../src/components/WeekView/WeekViewDay.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport { Box, GetStylesApi, UnstyledButton } from '@mantine/core';\nimport { useDatesContext } from '@mantine/dates';\nimport { getLabel, ScheduleLabelsOverride } from '../../labels';\nimport { DateStringValue, DateTimeStringValue, DayOfWeek, ScheduleMode } from '../../types';\nimport {\n  BusinessHoursValue,\n  clampIntervalMinutes,\n  DayTimeInterval,\n  getBusinessHoursMod,\n} from '../../utils';\nimport type { WeekViewControlsRef } from './handle-week-view-key-down';\nimport type { WeekViewFactory } from './WeekView';\n\nexport interface WeekViewDayProps {\n  /** Date to display */\n  day: Date | DateStringValue;\n\n  /** Index of this day in the week */\n  dayIndex: number;\n\n  /** Slots intervals */\n  slots: DayTimeInterval[];\n\n  /** Number of minutes for each interval, used to calculate slot height */\n  intervalMinutes: number;\n\n  /** `useStyles` return value of `WeekView` */\n  getStyles: GetStylesApi<WeekViewFactory>;\n\n  /** Indices of weekend days, 0-6, where 0 is Sunday and 6 is Saturday. The default value is defined by `DatesProvider`. */\n  weekendDays?: DayOfWeek[];\n\n  /** Events list */\n  children?: React.ReactNode;\n\n  /** Labels override */\n  labels?: ScheduleLabelsOverride;\n\n  /** If set to true, highlights business hours with white background */\n  highlightBusinessHours?: boolean;\n\n  /** Business hours range in `HH:mm:ss` format, or per-day record keyed by day of the week */\n  businessHours?: BusinessHoursValue;\n\n  /** If true, slots are drop targets for drag and drop */\n  withEventsDragAndDrop?: boolean;\n\n  /** Called when dragging over day slots container */\n  onDaySlotsDragOver?: (e: React.DragEvent<HTMLDivElement>, day: string, dayIndex: number) => void;\n\n  /** Called when dragging leaves day slots container */\n  onDaySlotsDragLeave?: () => void;\n\n  /** Called when dropping on day slots container */\n  onDaySlotsDrop?: (e: React.DragEvent<HTMLDivElement>, day: string, dayIndex: number) => void;\n\n  /** Called when slot is clicked */\n  onSlotClick?: (day: string, slotTime: string, event: React.MouseEvent<HTMLButtonElement>) => void;\n\n  /** Index of the slot that is currently a drop target */\n  dropTargetSlotIndex?: number;\n\n  /** Interaction mode: 'default' allows all interactions, 'static' disables event interactions */\n  mode?: ScheduleMode;\n\n  /** Ref for keyboard navigation */\n  slotsRef?: WeekViewControlsRef;\n\n  /** Index of the first focusable slot */\n  firstSlotIndex?: { dayIndex: number; slotIndex: number };\n\n  /** Keyboard event handler for slots */\n  onSlotKeyDown?: (\n    event: React.KeyboardEvent<HTMLButtonElement>,\n    dayIndex: number,\n    slotIndex: number\n  ) => void;\n\n  /** Called when Arrow Up is pressed on the first slot, used to navigate to all-day slot */\n  onFirstSlotArrowUp?: (dayIndex: number) => void;\n\n  /** If set, enables drag-to-select time slot ranges */\n  withDragSlotSelect?: boolean;\n\n  /** Called when pointer down on a slot for drag selection */\n  onSlotPointerDown?: (\n    event: React.PointerEvent<HTMLButtonElement>,\n    index: number,\n    group: string\n  ) => void;\n\n  /** Function to check if a slot is drag-selected */\n  isSlotDragSelected?: (index: number, group: string) => boolean;\n\n  /** Ref callback for the day slots container */\n  daySlotsContainerRef?: (node: HTMLDivElement | null) => void;\n\n  /** Function to get additional props for each time slot */\n  getTimeSlotProps?: (data: {\n    start: DateTimeStringValue;\n    end: DateTimeStringValue;\n  }) => Record<string, any> | undefined;\n}\n\nexport function WeekViewDay({\n  day,\n  dayIndex,\n  slots,\n  intervalMinutes,\n  getStyles,\n  weekendDays,\n  children,\n  labels,\n  highlightBusinessHours,\n  businessHours,\n  withEventsDragAndDrop,\n  onDaySlotsDragOver,\n  onDaySlotsDragLeave,\n  onDaySlotsDrop,\n  onSlotClick,\n  dropTargetSlotIndex,\n  mode,\n  slotsRef,\n  firstSlotIndex,\n  onSlotKeyDown,\n  onFirstSlotArrowUp,\n  withDragSlotSelect,\n  onSlotPointerDown,\n  isSlotDragSelected,\n  daySlotsContainerRef,\n  getTimeSlotProps,\n}: WeekViewDayProps) {\n  const ctx = useDatesContext();\n  const dayOfWeek = dayjs(day).day() as DayOfWeek;\n  const weekend = ctx.getWeekendDays(weekendDays).includes(dayOfWeek);\n  const today = dayjs(day).isSame(dayjs(), 'day');\n\n  const dayGroup = dayjs(day).format('YYYY-MM-DD');\n\n  const items = slots.map((slot, slotIndex) => {\n    const isDropTarget = dropTargetSlotIndex === slotIndex;\n    const isFirstSlot =\n      firstSlotIndex?.dayIndex === dayIndex && firstSlotIndex?.slotIndex === slotIndex;\n    const isDragSelected = isSlotDragSelected?.(slotIndex, dayGroup) || false;\n    const slotStart = `${dayGroup} ${slot.startTime}` as DateTimeStringValue;\n    const slotEnd = `${dayGroup} ${slot.endTime}` as DateTimeStringValue;\n    const { onClick: externalOnClick, ...externalSlotProps } =\n      getTimeSlotProps?.({ start: slotStart, end: slotEnd }) || {};\n\n    const handleClick =\n      mode === 'static'\n        ? undefined\n        : (e: React.MouseEvent<HTMLButtonElement>) => {\n            onSlotClick?.(String(day), slot.startTime, e);\n            externalOnClick?.(e);\n          };\n\n    return (\n      <UnstyledButton\n        key={slot.startTime}\n        ref={(node) => {\n          if (node && slotsRef?.current) {\n            if (!slotsRef.current[dayIndex]) {\n              slotsRef.current[dayIndex] = [];\n            }\n            slotsRef.current[dayIndex][slotIndex] = node;\n          }\n        }}\n        {...getStyles('weekViewDaySlot')}\n        mod={{\n          'hour-start': slot.isHourStart,\n          ...getBusinessHoursMod({\n            time: slot.startTime,\n            businessHours,\n            highlightBusinessHours,\n            dayOfWeek,\n          }),\n          'drop-target': isDropTarget,\n          'drag-selected': isDragSelected,\n          static: mode === 'static',\n        }}\n        __vars={{ '--slot-size': `${clampIntervalMinutes(intervalMinutes) / 60}` }}\n        aria-label={`${getLabel('timeSlot', labels)} ${dayGroup} ${slot.startTime} - ${slot.endTime}`}\n        tabIndex={mode === 'static' ? -1 : isFirstSlot ? 0 : -1}\n        data-drag-slot-index={withDragSlotSelect && mode !== 'static' ? slotIndex : undefined}\n        data-drag-slot-group={withDragSlotSelect && mode !== 'static' ? dayGroup : undefined}\n        onKeyDown={(e) => {\n          if (slotIndex === 0 && e.key === 'ArrowUp' && onFirstSlotArrowUp) {\n            e.preventDefault();\n            onFirstSlotArrowUp(dayIndex);\n          } else if (onSlotKeyDown) {\n            onSlotKeyDown(e, dayIndex, slotIndex);\n          }\n        }}\n        onPointerDown={\n          withDragSlotSelect && mode !== 'static'\n            ? (e) => onSlotPointerDown?.(e, slotIndex, dayGroup)\n            : undefined\n        }\n        onClick={handleClick}\n        onDragOver={\n          withEventsDragAndDrop && mode !== 'static' ? (e) => e.preventDefault() : undefined\n        }\n        {...externalSlotProps}\n      />\n    );\n  });\n\n  return (\n    <Box {...getStyles('weekViewDay')} mod={{ today, weekend }}>\n      <Box\n        ref={daySlotsContainerRef}\n        mod={{ today }}\n        {...getStyles('weekViewDaySlots')}\n        onDragOver={\n          withEventsDragAndDrop && mode !== 'static'\n            ? (e) => onDaySlotsDragOver?.(e, String(day), dayIndex)\n            : undefined\n        }\n        onDragLeave={withEventsDragAndDrop && mode !== 'static' ? onDaySlotsDragLeave : undefined}\n        onDrop={\n          withEventsDragAndDrop && mode !== 'static'\n            ? (e) => onDaySlotsDrop?.(e, String(day), dayIndex)\n            : undefined\n        }\n      >\n        {children}\n        {items}\n      </Box>\n    </Box>\n  );\n}\n"],"mappings":";;;;;;;;;AAyGA,SAAgB,YAAY,EAC1B,KACA,UACA,OACA,iBACA,WACA,aACA,UACA,QACA,wBACA,eACA,uBACA,oBACA,qBACA,gBACA,aACA,qBACA,MACA,UACA,gBACA,eACA,oBACA,oBACA,mBACA,oBACA,sBACA,oBACmB;CACnB,MAAM,MAAM,gBAAgB;CAC5B,MAAM,YAAY,MAAM,GAAG,CAAC,CAAC,IAAI;CACjC,MAAM,UAAU,IAAI,eAAe,WAAW,CAAC,CAAC,SAAS,SAAS;CAClE,MAAM,QAAQ,MAAM,GAAG,CAAC,CAAC,OAAO,MAAM,GAAG,KAAK;CAE9C,MAAM,WAAW,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY;CAE/C,MAA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