/**
 * 月 / 周 / 资源格与 +N 弹层内单条预约。
 * - 格内（未传 `containerWidthPx`）：与日历默认 pill 一致（名称 + 时间行）。
 * - +N 弹层（传入实测 `containerWidthPx`）：与日视图同源 RoomCard。
 */
import React from 'react';
import { findMergedTableRowForBookingRaw } from "../data/calendarAdapter";
import { ReservationCalendarDayBookingRoomCard } from "./ReservationCalendarDayBookingRoomCard";
import { formatReservationCalendarHourLabel, formatReservationCalendarPillTimeLine, formatReservationCalendarShortMonthDay, isReservationCalendarCrossDayItem } from "./reservationCalendarPillLabels";
function ReservationCalendarGridCompactPill(props) {
  var _item$name, _item$name2;
  var args = props.args;
  var item = args.item,
    layoutClassName = args.layoutClassName,
    onOpenDetail = args.onOpenDetail,
    draggable = args.draggable,
    onDragStart = args.onDragStart,
    view = args.view;
  var openDetail = function openDetail(e) {
    e.stopPropagation();
    onOpenDetail(item);
  };
  var crossDay = isReservationCalendarCrossDayItem(item);
  return /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: layoutClassName,
    draggable: draggable,
    onDragStart: draggable && onDragStart ? function (e) {
      e.stopPropagation();
      onDragStart(item);
    } : undefined,
    onClick: openDetail
  }, view === 'month' ? /*#__PURE__*/React.createElement("span", {
    className: "block min-w-0 truncate text-xs"
  }, crossDay ? "".concat(formatReservationCalendarShortMonthDay(item.date), " ").concat(formatReservationCalendarHourLabel(item.startHour), " ").concat((_item$name = item.name) !== null && _item$name !== void 0 ? _item$name : '') : "".concat(formatReservationCalendarHourLabel(item.startHour), " ").concat((_item$name2 = item.name) !== null && _item$name2 !== void 0 ? _item$name2 : '')) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "min-w-0 truncate text-xs font-medium"
  }, item.name), /*#__PURE__*/React.createElement("div", {
    className: "mt-0.5 min-w-0 truncate text-[10px] leading-tight opacity-80"
  }, formatReservationCalendarPillTimeLine(item))));
}
export function ReservationCalendarGridBookingNode(props) {
  var _args$containerWidthP;
  var args = props.args,
    tables = props.tables;
  var item = args.item,
    layoutClassName = args.layoutClassName,
    onOpenDetail = args.onOpenDetail,
    draggable = args.draggable,
    onDragStart = args.onDragStart;
  var useFullCard = args.containerWidthPx != null && args.containerWidthPx > 0;
  var containerWidthPx = (_args$containerWidthP = args.containerWidthPx) !== null && _args$containerWidthP !== void 0 ? _args$containerWidthP : 0;
  var openDetail = function openDetail(e) {
    e.stopPropagation();
    onOpenDetail(item);
  };
  if (!useFullCard) {
    return /*#__PURE__*/React.createElement(ReservationCalendarGridCompactPill, {
      args: args
    });
  }
  if (item.kind === 'block') {
    return /*#__PURE__*/React.createElement("button", {
      type: "button",
      className: layoutClassName,
      onClick: openDetail
    }, /*#__PURE__*/React.createElement("div", {
      className: "truncate text-sm font-medium"
    }, item.name));
  }
  var raw = item.raw;
  if (!raw) {
    return /*#__PURE__*/React.createElement("button", {
      type: "button",
      className: layoutClassName,
      onClick: openDetail
    }, /*#__PURE__*/React.createElement("div", {
      className: "truncate text-sm"
    }, item.name));
  }
  var row = findMergedTableRowForBookingRaw(raw, tables);
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(layoutClassName, " relative min-h-0 cursor-pointer overflow-hidden"),
    draggable: draggable,
    onDragStart: draggable && onDragStart ? function (e) {
      e.stopPropagation();
      onDragStart(item);
    } : undefined,
    onClick: openDetail,
    onKeyDown: function onKeyDown(e) {
      if (e.key === 'Enter' || e.key === ' ') {
        e.preventDefault();
        e.stopPropagation();
        onOpenDetail(item);
      }
    },
    role: "button",
    tabIndex: 0
  }, /*#__PURE__*/React.createElement(ReservationCalendarDayBookingRoomCard, {
    raw: raw,
    tableRow: row !== null && row !== void 0 ? row : null,
    overlayWidthPx: containerWidthPx
  }));
}