{"version":3,"file":"ResourcesWeekViewRow.mjs","names":[],"sources":["../../../src/components/ResourcesWeekView/ResourcesWeekViewRow.tsx"],"sourcesContent":["import { Box, GetStylesApi, UnstyledButton } from '@mantine/core';\nimport { getLabel, ScheduleLabelsOverride } from '../../labels';\nimport { ScheduleMode, ScheduleResourceData, ScheduleResourceGroup } from '../../types';\nimport {\n  DayTimeInterval,\n  getBusinessHoursMod,\n  ResourceGroupInfo,\n  ResourcesGridControlsRef,\n} from '../../utils';\nimport type { ResourcesWeekViewFactory } from './ResourcesWeekView';\n\nexport interface ResourcesWeekViewRowProps {\n  resource: ScheduleResourceData;\n  resourceIndex: number;\n  weekdays: string[];\n  slots: DayTimeInterval[];\n  getStyles: GetStylesApi<ResourcesWeekViewFactory>;\n  children?: React.ReactNode;\n  labels?: ScheduleLabelsOverride;\n  highlightBusinessHours?: boolean;\n  businessHours?: [string, string];\n  withEventsDragAndDrop?: boolean;\n  onRowSlotsDragOver?: (\n    e: React.DragEvent<HTMLDivElement>,\n    resourceId: string | number,\n    resourceIndex: number\n  ) => void;\n  onRowSlotsDragLeave?: () => void;\n  onRowSlotsDrop?: (\n    e: React.DragEvent<HTMLDivElement>,\n    resourceId: string | number,\n    resourceIndex: number\n  ) => void;\n  onSlotClick?: (\n    resourceId: string | number,\n    day: string,\n    slotTime: string,\n    event: React.MouseEvent<HTMLButtonElement>\n  ) => void;\n  dropTargetSlotIndex?: number;\n  mode?: ScheduleMode;\n  slotsRef?: ResourcesGridControlsRef;\n  firstSlotIndex?: { resourceIndex: number; slotIndex: number };\n  onSlotKeyDown?: (\n    event: React.KeyboardEvent<HTMLButtonElement>,\n    resourceIndex: number,\n    slotIndex: number\n  ) => void;\n  withDragSlotSelect?: boolean;\n  onSlotPointerDown?: (\n    event: React.PointerEvent<HTMLButtonElement>,\n    index: number,\n    group: string\n  ) => void;\n  isSlotDragSelected?: (index: number, group: string) => boolean;\n  rowSlotsContainerRef?: (node: HTMLDivElement | null) => void;\n  renderResourceLabel?: (resource: ScheduleResourceData) => React.ReactNode;\n  renderGroupLabel?: (group: ScheduleResourceGroup) => React.ReactNode;\n  scrolledX?: boolean;\n  groupInfo?: ResourceGroupInfo | null;\n  allDayCount?: number;\n}\n\nexport function ResourcesWeekViewRow({\n  resource,\n  resourceIndex,\n  weekdays,\n  slots,\n  getStyles,\n  children,\n  labels,\n  highlightBusinessHours,\n  businessHours,\n  withEventsDragAndDrop,\n  onRowSlotsDragOver,\n  onRowSlotsDragLeave,\n  onRowSlotsDrop,\n  onSlotClick,\n  dropTargetSlotIndex,\n  mode,\n  slotsRef,\n  firstSlotIndex,\n  onSlotKeyDown,\n  withDragSlotSelect,\n  onSlotPointerDown,\n  isSlotDragSelected,\n  rowSlotsContainerRef,\n  renderResourceLabel,\n  renderGroupLabel,\n  scrolledX,\n  groupInfo,\n  allDayCount,\n}: ResourcesWeekViewRowProps) {\n  const slotGroup = String(resource.id);\n\n  const items = weekdays.flatMap((day, dayIndex) =>\n    slots.map((slot, slotIndex) => {\n      const flatIndex = dayIndex * slots.length + slotIndex;\n      const isDropTarget = dropTargetSlotIndex === flatIndex;\n      const isFirstSlot =\n        firstSlotIndex?.resourceIndex === resourceIndex && firstSlotIndex?.slotIndex === flatIndex;\n      const isDragSelected = isSlotDragSelected?.(flatIndex, slotGroup) || false;\n\n      return (\n        <UnstyledButton\n          key={`${day}-${slot.startTime}`}\n          ref={(node) => {\n            if (!slotsRef?.current) {\n              return;\n            }\n            if (!slotsRef.current[resourceIndex]) {\n              slotsRef.current[resourceIndex] = [];\n            }\n            const row = slotsRef.current[resourceIndex];\n            if (node) {\n              row[flatIndex] = node;\n            } else {\n              delete row[flatIndex];\n              while (row.length > 0 && row[row.length - 1] == null) {\n                row.length -= 1;\n              }\n            }\n          }}\n          {...getStyles('resourcesWeekViewRowSlot')}\n          mod={{\n            'hour-start': slot.isHourStart,\n            ...getBusinessHoursMod({\n              time: slot.startTime,\n              businessHours,\n              highlightBusinessHours,\n            }),\n            'drop-target': isDropTarget,\n            'drag-selected': isDragSelected,\n            static: mode === 'static',\n          }}\n          aria-label={`${getLabel('resourceSlot', labels)} ${resource.label} ${day} ${slot.startTime} - ${slot.endTime}`}\n          tabIndex={mode === 'static' ? -1 : isFirstSlot ? 0 : -1}\n          data-drag-slot-index={withDragSlotSelect && mode !== 'static' ? flatIndex : undefined}\n          data-drag-slot-group={withDragSlotSelect && mode !== 'static' ? slotGroup : undefined}\n          onKeyDown={(e) => {\n            if (onSlotKeyDown) {\n              onSlotKeyDown(e, resourceIndex, flatIndex);\n            }\n          }}\n          onPointerDown={\n            withDragSlotSelect && mode !== 'static'\n              ? (e) => onSlotPointerDown?.(e, flatIndex, slotGroup)\n              : undefined\n          }\n          onClick={\n            mode === 'static' || !onSlotClick\n              ? undefined\n              : (e) => onSlotClick(resource.id, day, slot.startTime, e)\n          }\n          onDragOver={\n            withEventsDragAndDrop && mode !== 'static' ? (e) => e.preventDefault() : undefined\n          }\n        />\n      );\n    })\n  );\n\n  const isGroupStart = groupInfo?.position === 'first' || groupInfo?.position === 'only';\n  const groupCell =\n    groupInfo !== undefined ? (\n      groupInfo !== null ? (\n        <Box\n          {...getStyles('resourcesWeekViewGroupColumn')}\n          mod={{ 'scrolled-x': scrolledX, 'group-position': groupInfo.position }}\n        >\n          {isGroupStart && (\n            <span\n              style={\n                groupInfo.count > 1\n                  ? {\n                      transform: `translateY(calc((${groupInfo.count - 1} * (var(--resources-week-view-row-height) + 1px)) / 2))`,\n                    }\n                  : undefined\n              }\n            >\n              {renderGroupLabel ? renderGroupLabel(groupInfo.group) : groupInfo.group.label}\n            </span>\n          )}\n        </Box>\n      ) : (\n        <Box\n          {...getStyles('resourcesWeekViewGroupColumnEmpty')}\n          mod={{ 'scrolled-x': scrolledX }}\n        />\n      )\n    ) : null;\n\n  return (\n    <Box {...getStyles('resourcesWeekViewRow')}>\n      {groupCell}\n      <Box\n        {...getStyles('resourcesWeekViewResourceLabel')}\n        mod={{ 'scrolled-x': scrolledX, 'has-groups': groupInfo !== undefined }}\n      >\n        {renderResourceLabel ? renderResourceLabel(resource) : resource.label}\n      </Box>\n      <Box\n        ref={rowSlotsContainerRef}\n        {...getStyles('resourcesWeekViewRowSlots', {\n          style: allDayCount\n            ? {\n                minHeight: `max(var(--resources-week-view-row-height), calc(${allDayCount} * (var(--resources-week-view-all-day-height) + 2px) + 4px))`,\n              }\n            : undefined,\n        })}\n        onDragOver={\n          withEventsDragAndDrop && mode !== 'static'\n            ? (e) => onRowSlotsDragOver?.(e, resource.id, resourceIndex)\n            : undefined\n        }\n        onDragLeave={withEventsDragAndDrop && mode !== 'static' ? onRowSlotsDragLeave : undefined}\n        onDrop={\n          withEventsDragAndDrop && mode !== 'static'\n            ? (e) => onRowSlotsDrop?.(e, resource.id, resourceIndex)\n            : undefined\n        }\n      >\n        {children}\n        {items}\n      </Box>\n    </Box>\n  );\n}\n"],"mappings":";;;;;;AA+DA,SAAgB,qBAAqB,EACnC,UACA,eACA,UACA,OACA,WACA,UACA,QACA,wBACA,eACA,uBACA,oBACA,qBACA,gBACA,aACA,qBACA,MACA,UACA,gBACA,eACA,oBACA,mBACA,oBACA,sBACA,qBACA,kBACA,WACA,WACA,eAC4B;CAC5B,MAAM,YAAY,OAAO,SAAS,EAAE;CAEpC,MAAM,QAAQ,SAAS,SAAS,KAAK,aACnC,MAAM,KAAK,MAAM,cAAc;EAC7B,MAAM,YAAY,WAAW,MAAM,SAAS;EAC5C,MAAM,eAAe,wBAAwB;EAC7C,MAAM,cACJ,gBAAgB,kBAAkB,iBAAiB,gBAAgB,cAAc;EACnF,MAAM,iBAAiB,qBAAqB,WAAW,SAAS,KAAK;EAErE,OACE,oBAAC,gBAAD;GAEE,MAAM,SAAS;IACb,IAAI,CAAC,UAAU,SACb;IAEF,IAAI,CAAC,SAAS,QAAQ,gBACpB,SAAS,QAAQ,iBAAiB,CAAC;IAErC,MAAM,MAAM,SAAS,QAAQ;IAC7B,IAAI,MACF,IAAI,aAAa;SACZ;KACL,OAAO,I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