function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
// @ts-nocheck
import React, { useMemo } from 'react';
import { assignLanesByInterval, bookingIntersectsDateWindow, courtDaySummary, dayOccupancy, fmtDate, formatHourLabel, formatShortMonthDay, getBookingSegmentForDate, isCrossDayBooking } from "../utils/bookingCalendarDateUtils";
import { CALENDAR_EMPTY_DASHED_SLOT_CLASSNAME, dayRowHeight, frozenColWidth, RESOURCE_VIEW_BOOKING_CARD_EST_PX, RESOURCE_VIEW_CELL_PADDING_Y_PX, RESOURCE_VIEW_MORE_TILE_MIN_PX, WEEK_VIEW_MAX_LANE } from "../const/bookingCalendarConstants";
import { CALENDAR_WEEKDAY_IDS, tCal } from "../calendarI18n";
import { getGridBookingRowStateClasses } from "../utils/BookingCalendarStyle";
import { CalendarGridBookingClipMarkers, getRemainingToneClass } from "../bookingCalendarViewShared";
import { BookingCalendarGroupRowHeader } from "./BookingCalendarGroupRowHeader";
import { mapAxisSpan, dayGridUnit } from "../utils/bookingCalendarAxis";

/** 周 / 资源 / 月共享一套行内 lane 抢占 + +N 溢出参数 */
var WEEK_VIEW_OVERLAY_CELL_PAD = 4;
var WEEK_VIEW_OVERLAY_LANE_GAP = 4;

/**
 * 周视图：7 日网格 + 左侧分组（可折叠），单元格调起日视图；格内 drop 触发改期草稿。
 */
export function BookingCalendarWeekView(_ref) {
  var calendarProps = _ref.calendarProps,
    isLight = _ref.isLight,
    weekDays = _ref.weekDays,
    bookings = _ref.bookings,
    courts = _ref.courts,
    hourSlots = _ref.hourSlots,
    slotStepHours = _ref.slotStepHours,
    visibleCourts = _ref.visibleCourts,
    visibleCourtRows = _ref.visibleCourtRows,
    isBusinessHour = _ref.isBusinessHour,
    goToDayFromCell = _ref.goToDayFromCell,
    handleGridDropMove = _ref.handleGridDropMove,
    openBookingDetail = _ref.openBookingDetail,
    setDraggingItem = _ref.setDraggingItem,
    setCollapsedGroups = _ref.setCollapsedGroups,
    setOverflowListModal = _ref.setOverflowListModal,
    tickFillMode = _ref.tickFillMode;
  var props = calendarProps;
  var todayKey = fmtDate(new Date());
  /** 与下方 grid `minmax(…px, 1fr)` 一致：窄屏由外层 overflow-auto + min-w-0 定视口宽，本值撑开 scrollWidth */
  var weekDayColMinPx = 150;
  var weekGridMinWidthPx = frozenColWidth + weekDays.length * weekDayColMinPx;

  /* --------------------- 跨日 booking lane 抢占（行内 absolute overlay） ---------------------
   * 周视图 cell 是「日列」粒度，与资源视图同款：
   *   - 同一资源 + 同一天的两条 booking 视觉上必须 stack（不论小时）→ lane 用 'day' 粒度
   *   - 跨日 booking 一条横跨 startCol..endCol；落在本周外的端点 clipped + ◀/▶
   *   - lane >= MAX_LANE 的 booking 按它命中的每天累计到 cell-level +N tile
   */
  var weekDateSet = useMemo(function () {
    var s = new Set();
    var _iterator = _createForOfIteratorHelper(weekDays),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var _d = _step.value;
        s.add(fmtDate(_d));
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return s;
  }, [weekDays]);
  var dateKeyToCol = useMemo(function () {
    var m = new Map();
    weekDays.forEach(function (d, i) {
      return m.set(fmtDate(d), i);
    });
    return m;
  }, [weekDays]);
  var weekFirstKey = useMemo(function () {
    return weekDays[0] ? fmtDate(weekDays[0]) : '';
  }, [weekDays]);
  var weekLastKey = useMemo(function () {
    return weekDays.length > 0 ? fmtDate(weekDays[weekDays.length - 1]) : '';
  }, [weekDays]);

  /**
   * 仅与本周相交的 booking 才进 lane 抢占 / 行高计算。
   * 后端为支持跨日 banner 续画把请求下界外推 30 天，`bookings` 会带历史周的数据；
   * 若直接全量算 lane，切到「本周没数据但上周有」的资源行时会保留上周 lane 数 → 行高被撑高。
   */
  var bookingsByCourt = useMemo(function () {
    var m = new Map();
    if (!weekFirstKey || !weekLastKey) return m;
    var _iterator2 = _createForOfIteratorHelper(bookings),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var b = _step2.value;
        if (!(b !== null && b !== void 0 && b.courtId)) continue;
        if (!bookingIntersectsDateWindow(b, weekFirstKey, weekLastKey)) continue;
        var cid = String(b.courtId);
        var arr = m.get(cid);
        if (arr) arr.push(b);else m.set(cid, [b]);
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    return m;
  }, [bookings, weekFirstKey, weekLastKey]);
  var courtRowMetrics = useMemo(function () {
    var m = new Map();
    var _iterator3 = _createForOfIteratorHelper(bookingsByCourt),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _step3$value = _slicedToArray(_step3.value, 2),
          cid = _step3$value[0],
          items = _step3$value[1];
        var _assignLanesByInterva = assignLanesByInterval(items, 'day'),
          lanes = _assignLanesByInterva.lanes,
          laneCount = _assignLanesByInterva.laneCount;
        var entries = [];
        var overflowByDate = new Map();
        var seenIds = new Set();
        var _iterator4 = _createForOfIteratorHelper(items),
          _step4;
        try {
          for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
            var _it$endDate;
            var it = _step4.value;
            var idKey = String(it.id);
            if (seenIds.has(idKey)) continue;
            seenIds.add(idKey);
            var lane = lanes.get(idKey);
            if (lane === undefined) continue;
            entries.push({
              item: it,
              lane: lane
            });
            if (lane < WEEK_VIEW_MAX_LANE) continue;
            // lane 溢出：枚举该 booking 命中的本周内每一天
            var startStr = String(it.date);
            var endStr = String((_it$endDate = it.endDate) !== null && _it$endDate !== void 0 ? _it$endDate : it.date);
            var startDate = new Date("".concat(startStr, "T00:00:00"));
            var endDate = new Date("".concat(endStr, "T00:00:00"));
            var cur = new Date(startDate);
            while (cur.getTime() <= endDate.getTime()) {
              var k = fmtDate(cur);
              if (weekDateSet.has(k)) {
                var arr = overflowByDate.get(k);
                if (arr) arr.push(it);else overflowByDate.set(k, [it]);
              }
              cur.setDate(cur.getDate() + 1);
            }
          }
        } catch (err) {
          _iterator4.e(err);
        } finally {
          _iterator4.f();
        }
        m.set(cid, {
          entries: entries,
          laneCount: laneCount,
          overflowByDate: overflowByDate
        });
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    return m;
  }, [bookingsByCourt, weekDateSet]);

  /** 每行行高（与资源视图同口径，但下界由 dayRowHeight 抬到能容纳 1 条 pill 的高度） */
  var courtRowHeightPx = useMemo(function () {
    var padY = RESOURCE_VIEW_CELL_PADDING_Y_PX;
    var cardH = RESOURCE_VIEW_BOOKING_CARD_EST_PX;
    var gap = WEEK_VIEW_OVERLAY_LANE_GAP;
    var moreH = RESOURCE_VIEW_MORE_TILE_MIN_PX;
    var m = new Map();
    courtRowMetrics.forEach(function (metric, cid) {
      var visibleLanes = Math.min(metric.laneCount, WEEK_VIEW_MAX_LANE);
      var hasOverflow = metric.laneCount > WEEK_VIEW_MAX_LANE;
      if (visibleLanes === 0) {
        m.set(cid, dayRowHeight);
        return;
      }
      var content = visibleLanes * cardH + (visibleLanes - 1) * gap;
      if (hasOverflow) content += gap + moreH;
      m.set(cid, Math.max(dayRowHeight, padY + content));
    });
    return m;
  }, [courtRowMetrics]);
  return /*#__PURE__*/React.createElement("div", {
    key: "week-".concat(fmtDate(weekDays[0])),
    className: "flex min-h-0 flex-1 flex-col"
  }, /*#__PURE__*/React.createElement("div", {
    className: "relative flex min-h-0 min-w-0 flex-1 flex-col"
  }, /*#__PURE__*/React.createElement("div", {
    className: "theme-panel pisell-scroll-hidden min-h-0 min-w-0 max-h-none flex-1 overflow-auto touch-pan-x touch-pan-y select-none",
    style: {
      overscrollBehavior: 'none'
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "grid",
    style: {
      minWidth: weekGridMinWidthPx,
      gridTemplateColumns: "".concat(frozenColWidth, "px repeat(").concat(weekDays.length, ", minmax(").concat(weekDayColMinPx, "px, 1fr))")
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "grid sticky top-0 z-50",
    style: {
      gridColumn: '1 / -1',
      gridTemplateColumns: "".concat(frozenColWidth, "px repeat(").concat(weekDays.length, ", minmax(").concat(weekDayColMinPx, "px, 1fr))"),
      isolation: 'isolate'
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "sticky left-0 z-30 flex w-[132px] min-w-[132px] max-w-[132px] items-center px-2.5 py-3 font-semibold border-b shadow-[8px_0_16px_rgba(0,0,0,0.08)] ".concat(isLight ? 'theme-sticky theme-border theme-text' : 'bg-[#241d40] border-zinc-800')
  }, tCal('pisell2.recordBoard.calendar.week.headerCourtDate')), weekDays.map(function (day, i) {
    var key = fmtDate(day);
    var isToday = key === todayKey;
    var dayItems = bookings.filter(function (b) {
      return getBookingSegmentForDate(b, key) != null;
    });
    var fullyBooked = courts.every(function (court) {
      return hourSlots.filter(isBusinessHour).every(function (h) {
        return dayOccupancy(court.id, key, bookings, hourSlots, slotStepHours)[h];
      });
    });
    return /*#__PURE__*/React.createElement("div", {
      key: key,
      className: "relative z-20 border-b border-l px-1.5 py-2 text-center shadow-[0_8px_16px_rgba(0,0,0,0.06)] ".concat(isLight ? 'theme-border theme-text' : 'border-zinc-800', " ").concat(isToday ? isLight ? 'bg-gradient-to-b from-violet-50 to-white' : 'bg-gradient-to-b from-violet-950 to-[#1a1a22]' : isLight ? 'theme-panel-soft' : 'bg-[#1a1a22]')
    }, /*#__PURE__*/React.createElement("div", {
      className: "text-sm leading-tight ".concat(isLight ? 'theme-text-faint' : 'text-zinc-400')
    }, tCal(CALENDAR_WEEKDAY_IDS[i])), /*#__PURE__*/React.createElement("div", {
      className: "mt-0.5 flex justify-center"
    }, /*#__PURE__*/React.createElement("span", {
      className: "grid h-10 w-10 place-items-center text-3xl font-semibold leading-none",
      "aria-label": isToday ? 'Today' : undefined
    }, day.getDate())));
  })), visibleCourtRows.map(function (row) {
    var _courtRowHeightPx$get;
    if (row.kind === 'group') {
      /* group 行：保持原有 1 sticky + 7 freeRatio cell 布局，无 booking 渲染需求 */
      return /*#__PURE__*/React.createElement(React.Fragment, {
        key: row.id
      }, /*#__PURE__*/React.createElement(BookingCalendarGroupRowHeader, {
        isLight: isLight,
        view: "week",
        row: {
          id: row.id,
          label: row.label,
          count: row.count,
          collapsed: row.collapsed
        },
        renderResourceCell: props.renderResourceCell,
        setCollapsedGroups: setCollapsedGroups
      }), weekDays.map(function (day) {
        var key = fmtDate(day);
        var groupCourts = visibleCourts.filter(function (court) {
          return court.type === row.label;
        });
        var noRatioCell = groupCourts.length === 0;
        var total = groupCourts.length;
        var remaining = 0;
        var ratio = 0;
        if (!noRatioCell) {
          var busyCount = groupCourts.filter(function (court) {
            var summary = courtDaySummary(court.id, key, bookings, hourSlots, slotStepHours);
            return summary.items.length > 0;
          }).length;
          remaining = total - busyCount;
          ratio = total > 0 ? remaining / total : 0;
        }
        return /*#__PURE__*/React.createElement("div", {
          key: "".concat(row.id, "-").concat(key),
          style: {
            minHeight: dayRowHeight
          },
          className: "flex h-full items-center justify-center border-b border-l px-1.5 py-1 text-center text-sm font-medium ".concat(isLight ? 'theme-border' : 'border-zinc-800', " ").concat(noRatioCell ? isLight ? 'bg-slate-100 theme-text-faint' : 'bg-zinc-800/80 text-zinc-500' : isLight ? 'theme-panel-soft' : 'bg-[#151a2f] text-zinc-300')
        }, noRatioCell ? /*#__PURE__*/React.createElement("div", {
          className: "text-xs opacity-60"
        }, "\u2014") : /*#__PURE__*/React.createElement("div", {
          className: "text-xs font-semibold leading-none ".concat(getRemainingToneClass(ratio, isLight))
        }, tCal('pisell2.recordBoard.calendar.day.freeRatio', {
          remaining: remaining,
          total: total
        })));
      }));
    }

    /* court 行：跨整行容器 + 内部嵌套 grid + absolute overlay 跨格 ----------- */
    return /*#__PURE__*/React.createElement(CourtWeekRow, {
      key: row.id,
      row: row,
      isLight: isLight,
      weekDays: weekDays,
      weekDayColMinPx: weekDayColMinPx,
      bookings: bookings,
      hourSlots: hourSlots,
      slotStepHours: slotStepHours,
      metric: courtRowMetrics.get(String(row.id)),
      rowHeight: (_courtRowHeightPx$get = courtRowHeightPx.get(String(row.id))) !== null && _courtRowHeightPx$get !== void 0 ? _courtRowHeightPx$get : dayRowHeight,
      dateKeyToCol: dateKeyToCol,
      renderResourceCell: props.renderResourceCell,
      renderMonthWeekBooking: props.renderMonthWeekBooking,
      goToDayFromCell: goToDayFromCell,
      handleGridDropMove: handleGridDropMove,
      openBookingDetail: openBookingDetail,
      setDraggingItem: setDraggingItem,
      setOverflowListModal: setOverflowListModal,
      tickFillMode: tickFillMode
    });
  })))));
}

/* --------------------- 周视图 court 行（跨整行 + 内嵌 grid + overlay） ---------------------
 * 渲染结构（外层 grid 子项 1 个：`gridColumn: '1 / -1'`）：
 *   <div position:relative>
 *     <div display:grid 1+7 cols>           ← cell 层（着色 / dashed slot / drop / click）
 *       <sticky court name>
 *       <day cell × 7>
 *     </div>
 *     <div position:absolute left:132 right:0 top:0 bottom:0>
 *       <div position:relative 100%×100%>   ← overlay 层（pill + +N tile，pointer-events 各自接管）
 *         pills (absolute + 百分比 left/width 跨多日)
 *         +N tile (absolute + 百分比 单列)
 *       </div>
 *     </div>
 *   </div>
 *
 * cell 仍按 day 单独画 → 着色 / 选中 / drop 行为不变；overlay 浮在 cell 之上，pill 不影响 cell 自身高度。
 */
function CourtWeekRow(_ref2) {
  var _metric$laneCount, _hourSlots$, _hourSlots$length;
  var row = _ref2.row,
    isLight = _ref2.isLight,
    weekDays = _ref2.weekDays,
    weekDayColMinPx = _ref2.weekDayColMinPx,
    bookings = _ref2.bookings,
    hourSlots = _ref2.hourSlots,
    slotStepHours = _ref2.slotStepHours,
    metric = _ref2.metric,
    rowHeight = _ref2.rowHeight,
    dateKeyToCol = _ref2.dateKeyToCol,
    renderResourceCell = _ref2.renderResourceCell,
    renderMonthWeekBooking = _ref2.renderMonthWeekBooking,
    goToDayFromCell = _ref2.goToDayFromCell,
    handleGridDropMove = _ref2.handleGridDropMove,
    openBookingDetail = _ref2.openBookingDetail,
    setDraggingItem = _ref2.setDraggingItem,
    setOverflowListModal = _ref2.setOverflowListModal,
    tickFillMode = _ref2.tickFillMode;
  var lastColIdx = weekDays.length - 1;
  var firstKey = lastColIdx >= 0 ? fmtDate(weekDays[0]) : '';
  var lastKey = lastColIdx >= 0 ? fmtDate(weekDays[lastColIdx]) : '';

  /** lane 抢占 → pill 列跨度 + 视觉 clipping ----------- */
  var pills = useMemo(function () {
    if (!metric) return [];
    var out = [];
    var _iterator5 = _createForOfIteratorHelper(metric.entries),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _it$endDate2;
        var entry = _step5.value;
        var it = entry.item;
        if (entry.lane >= WEEK_VIEW_MAX_LANE) continue;
        var startStr = String(it.date);
        var endStr = String((_it$endDate2 = it.endDate) !== null && _it$endDate2 !== void 0 ? _it$endDate2 : it.date);
        var rawStartCol = dateKeyToCol.get(startStr);
        var rawEndCol = dateKeyToCol.get(endStr);
        var startCol = rawStartCol !== null && rawStartCol !== void 0 ? rawStartCol : -1;
        var endCol = rawEndCol !== null && rawEndCol !== void 0 ? rawEndCol : -1;
        var clippedLeft = rawStartCol === undefined && firstKey !== '' && startStr < firstKey;
        var clippedRight = rawEndCol === undefined && lastKey !== '' && endStr > lastKey;
        if (rawStartCol === undefined) startCol = clippedLeft ? 0 : -1;
        if (rawEndCol === undefined) endCol = clippedRight ? lastColIdx : -1;
        if (startCol < 0 || endCol < 0 || endCol < startCol) continue;
        out.push({
          key: "".concat(row.id, "\t").concat(it.id),
          item: it,
          lane: entry.lane,
          startCol: startCol,
          endCol: endCol,
          clippedLeft: clippedLeft,
          clippedRight: clippedRight,
          crossDay: isCrossDayBooking(it)
        });
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    return out;
  }, [metric, dateKeyToCol, firstKey, lastKey, lastColIdx, row.id]);

  /** lane 溢出 → 每天 cell-level +N tile ----------- */
  var moreTiles = useMemo(function () {
    if (!metric || metric.laneCount <= WEEK_VIEW_MAX_LANE) return [];
    var out = [];
    weekDays.forEach(function (day, ci) {
      var dk = fmtDate(day);
      var overflowItems = metric.overflowByDate.get(dk);
      if (!overflowItems || overflowItems.length === 0) return;
      var allHits = bookings.filter(function (b) {
        return String(b.courtId) === String(row.id) && getBookingSegmentForDate(b, dk) != null;
      });
      out.push({
        key: "".concat(row.id, "\t").concat(dk, "\tmore"),
        colIdx: ci,
        dateKey: dk,
        moreItems: overflowItems,
        moreCount: overflowItems.length,
        allItems: allHits
      });
    });
    return out;
  }, [metric, weekDays, bookings, row.id]);
  var padY = WEEK_VIEW_OVERLAY_CELL_PAD;
  var cardH = RESOURCE_VIEW_BOOKING_CARD_EST_PX;
  var gap = WEEK_VIEW_OVERLAY_LANE_GAP;
  var visibleLanes = Math.min((_metric$laneCount = metric === null || metric === void 0 ? void 0 : metric.laneCount) !== null && _metric$laneCount !== void 0 ? _metric$laneCount : 0, WEEK_VIEW_MAX_LANE);

  /* --------------------- pill / +N tile 百分比轴映射 ---------------------
   * 周列是弹性 1fr，无法按整 grid 列跨格 → pill 改 absolute + 百分比 left/width。
   * 默认 snap：startUnit=startCol、endUnit=endCol+1（整数列，与小时无关），
   * offset=startCol*(100/N)、size=(endCol-startCol+1)*(100/N)，与旧整列 gridColumn 像素等价。
   */
  var dayGridMin = (_hourSlots$ = hourSlots === null || hourSlots === void 0 ? void 0 : hourSlots[0]) !== null && _hourSlots$ !== void 0 ? _hourSlots$ : 0;
  var dayGridSpan = ((_hourSlots$length = hourSlots === null || hourSlots === void 0 ? void 0 : hourSlots.length) !== null && _hourSlots$length !== void 0 ? _hourSlots$length : 24) * (slotStepHours || 1);
  var pctAxis = {
    originUnit: 0,
    scalePerUnit: 100 / weekDays.length,
    // 每列百分比
    tickUnit: 1,
    minSize: 0
  };
  return /*#__PURE__*/React.createElement("div", {
    style: {
      gridColumn: '1 / -1',
      position: 'relative',
      minHeight: rowHeight
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'grid',
      gridTemplateColumns: "".concat(frozenColWidth, "px repeat(").concat(weekDays.length, ", minmax(").concat(weekDayColMinPx, "px, 1fr))"),
      minHeight: rowHeight
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "sticky left-0 z-30 flex h-full min-h-0 w-[132px] min-w-[132px] max-w-[132px] items-center border-b px-2.5 py-1.5 shadow-[8px_0_16px_rgba(0,0,0,0.06)] ".concat(isLight ? 'theme-sticky theme-border' : 'border-zinc-800 bg-[#1a1a22]'),
    style: {
      minHeight: rowHeight
    }
  }, renderResourceCell ? renderResourceCell({
    view: 'week',
    row: {
      kind: 'court',
      id: row.id,
      name: row.name,
      type: row.type
    },
    isLight: isLight
  }) : /*#__PURE__*/React.createElement("div", {
    className: "pisell-rb-cal-week-resource-name min-w-0 w-full font-semibold text-[16px] leading-tight"
  }, row.name)), weekDays.map(function (day) {
    var key = fmtDate(day);
    var summary = courtDaySummary(row.id, key, bookings, hourSlots, slotStepHours);
    var isEmpty = summary.items.length === 0;
    return /*#__PURE__*/React.createElement("button", {
      key: "".concat(row.id, "-").concat(key),
      onClick: function onClick() {
        return goToDayFromCell(day, row.id, "week-".concat(row.id, "-").concat(key));
      },
      onDragOver: function onDragOver(e) {
        return e.preventDefault();
      },
      onDrop: function onDrop(e) {
        e.preventDefault();
        handleGridDropMove(key, row.id);
      },
      style: {
        minHeight: rowHeight
      },
      className: "relative flex h-full flex-col justify-start border-b border-l p-1 text-left align-top transition outline-none ".concat(isLight ? 'theme-border' : 'border-zinc-700', " ").concat(summary.fullyBooked ? isLight ? 'bg-slate-100 theme-text-faint' : 'bg-zinc-800 text-zinc-500' : summary.hasBlock ? isLight ? 'bg-red-50 border-red-200' : 'bg-red-950/30 border-red-800/40' : summary.occupiedHours.length > 0 ? isLight ? 'bg-violet-50' : 'bg-[#1c1630]' : isLight ? 'theme-grid-cell' : 'bg-zinc-900')
    }, summary.fullyBooked ? /*#__PURE__*/React.createElement("div", {
      className: "min-h-[28px] w-full rounded-lg bg-zinc-700/70",
      "aria-hidden": true
    }) : isEmpty ? /*#__PURE__*/React.createElement("div", {
      className: "".concat(CALENDAR_EMPTY_DASHED_SLOT_CLASSNAME, " text-center ").concat(isLight ? 'border-[#d8d0eb] text-[#8f86a9]' : 'border-zinc-700 text-zinc-500'),
      "aria-hidden": true
    }) : null);
  })), /*#__PURE__*/React.createElement("div", {
    "aria-hidden": true,
    style: {
      position: 'absolute',
      top: 0,
      bottom: 0,
      left: frozenColWidth,
      right: 0,
      pointerEvents: 'none'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      position: 'relative',
      width: '100%',
      height: '100%'
    }
  }, pills.map(function (p) {
    var _p$item$endDate;
    // 0 点（午夜）是合法值，禁止用 || dayGridMin 兜底
    var startHourVal = Number.isFinite(Number(p.item.startHour)) ? Number(p.item.startHour) : dayGridMin;
    var endHourVal = Number.isFinite(Number(p.item.endHour)) ? Number(p.item.endHour) : dayGridMin;
    var startUnit = tickFillMode === 'snap' ? p.startCol : dayGridUnit(p.startCol, startHourVal, dayGridMin, dayGridSpan);
    var endUnit = tickFillMode === 'snap' ? p.endCol + 1 : dayGridUnit(p.endCol, endHourVal, dayGridMin, dayGridSpan);
    var sp = mapAxisSpan(pctAxis, startUnit, endUnit, tickFillMode);
    var radiusClass = p.crossDay ? "".concat(p.clippedLeft ? 'rounded-l-none' : 'rounded-l-lg', " ").concat(p.clippedRight ? 'rounded-r-none' : 'rounded-r-lg') : 'rounded-lg';
    var layoutClassName = "flex flex-col justify-center px-2.5 py-1.5 text-xs text-left w-full h-full ".concat(radiusClass, " ").concat(getGridBookingRowStateClasses(p.item));
    return /*#__PURE__*/React.createElement("div", {
      key: p.key,
      style: {
        position: 'absolute',
        left: "calc(".concat(sp.offset, "% + ").concat(padY, "px)"),
        width: "calc(".concat(sp.size, "% - ").concat(padY * 2, "px)"),
        top: padY + p.lane * (cardH + gap),
        height: cardH,
        pointerEvents: 'auto'
      },
      onDragOver: function onDragOver(e) {
        return e.preventDefault();
      },
      onDrop: function onDrop(e) {
        e.preventDefault();
        handleGridDropMove(p.item.date, String(row.id));
      }
    }, renderMonthWeekBooking ? /*#__PURE__*/React.createElement("div", {
      className: "relative h-full w-full min-h-0"
    }, renderMonthWeekBooking({
      item: p.item,
      dateKey: p.item.date,
      view: 'week',
      isLight: isLight,
      layoutClassName: layoutClassName,
      onOpenDetail: openBookingDetail,
      onDragStart: function onDragStart(it) {
        return setDraggingItem(it);
      },
      // 跨日 booking 暂不支持拖拽改约
      draggable: !p.crossDay
    }), /*#__PURE__*/React.createElement(CalendarGridBookingClipMarkers, {
      clippedLeft: p.clippedLeft,
      clippedRight: p.clippedRight
    })) : /*#__PURE__*/React.createElement("button", {
      type: "button",
      onClick: function onClick(e) {
        e.stopPropagation();
        openBookingDetail(p.item);
      },
      className: "relative ".concat(layoutClassName)
    }, p.clippedLeft && /*#__PURE__*/React.createElement("span", {
      "aria-hidden": true,
      className: "absolute left-0.5 top-1/2 -translate-y-1/2 text-[10px] leading-none opacity-80"
    }, "\u25C0"), p.clippedRight && /*#__PURE__*/React.createElement("span", {
      "aria-hidden": true,
      className: "absolute right-0.5 top-1/2 -translate-y-1/2 text-[10px] leading-none opacity-80"
    }, "\u25B6"), /*#__PURE__*/React.createElement("div", {
      className: "truncate"
    }, p.item.name), /*#__PURE__*/React.createElement("div", {
      className: "mt-1 opacity-80 truncate"
    }, p.crossDay ? "".concat(formatShortMonthDay(p.item.date), " ").concat(formatHourLabel(p.item.startHour), " - ").concat(formatShortMonthDay((_p$item$endDate = p.item.endDate) !== null && _p$item$endDate !== void 0 ? _p$item$endDate : p.item.date), " ").concat(formatHourLabel(p.item.endHour)) : "".concat(formatHourLabel(p.item.startHour), " - ").concat(formatHourLabel(p.item.endHour)))));
  }), moreTiles.map(function (t) {
    return /*#__PURE__*/React.createElement("div", {
      key: t.key,
      style: {
        position: 'absolute',
        left: "calc(".concat(t.colIdx * (100 / weekDays.length), "% + ").concat(padY, "px)"),
        width: "calc(".concat(100 / weekDays.length, "% - ").concat(padY * 2, "px)"),
        top: padY + visibleLanes * (cardH + gap),
        pointerEvents: 'auto'
      }
    }, /*#__PURE__*/React.createElement("button", {
      type: "button",
      onClick: function onClick(e) {
        e.stopPropagation();
        setOverflowListModal(function (prev) {
          return prev && prev.scope === row.id && prev.date === t.dateKey ? null : {
            scope: row.id,
            date: t.dateKey,
            title: tCal('pisell2.recordBoard.calendar.overflow.listTitleAllBookings', {
              date: t.dateKey
            }),
            items: t.allItems
          };
        });
      },
      style: {
        minHeight: RESOURCE_VIEW_MORE_TILE_MIN_PX
      },
      className: "flex w-full items-center justify-center rounded-xl bg-violet-700/90 px-2.5 py-1 text-xs font-semibold text-white"
    }, "+", t.moreCount));
  }))));
}