function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
// @ts-nocheck
import React from 'react';
import { DownOutlined } from '@ant-design/icons';
import { courtDaySummary, dayOccupancy, fmtDate, formatHourLabel } from "../utils/bookingCalendarDateUtils";
import { frozenColWidth } from "../const/bookingCalendarConstants";
import { CALENDAR_WEEKDAY_IDS, tCal } from "../calendarI18n";
import { getGridBookingRowStateClasses } from "../utils/BookingCalendarStyle";
import { getRemainingToneClass } from "../bookingCalendarViewShared";
/**
 * 周视图：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,
    overflowPopover = _ref.overflowPopover,
    setOverflowPopover = _ref.setOverflowPopover,
    overflowListModal = _ref.overflowListModal,
    setOverflowListModal = _ref.setOverflowListModal,
    overflowPanelRef = _ref.overflowPanelRef;
  var props = calendarProps;
  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: "p-2 md:p-4 relative flex min-h-0 flex-1 flex-col"
  }, /*#__PURE__*/React.createElement("div", {
    className: "theme-panel rounded-3xl border min-w-[980px] min-h-0 max-h-none flex-1 overflow-auto"
  }, /*#__PURE__*/React.createElement("div", {
    className: "grid",
    style: {
      gridTemplateColumns: "".concat(frozenColWidth, "px repeat(").concat(weekDays.length, ", minmax(150px, 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(150px, 1fr))"),
      isolation: 'isolate'
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "sticky left-0 z-30 w-[132px] min-w-[132px] max-w-[132px] px-3 py-4 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 dayItems = bookings.filter(function (b) {
      return b.date === key;
    });
    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 p-3 text-center shadow-[0_8px_16px_rgba(0,0,0,0.06)] ".concat(isLight ? 'theme-border theme-text' : 'border-zinc-800', " ").concat(i >= 5 ? isLight ? 'bg-violet-200' : 'bg-violet-900' : isLight ? 'theme-panel-soft' : 'bg-[#1a1a22]')
    }, /*#__PURE__*/React.createElement("div", {
      className: "text-sm ".concat(isLight ? 'theme-text-faint' : 'text-zinc-400')
    }, tCal(CALENDAR_WEEKDAY_IDS[i])), /*#__PURE__*/React.createElement("div", {
      className: "mt-1 text-3xl font-semibold"
    }, day.getDate()), /*#__PURE__*/React.createElement("div", {
      className: "mt-2 flex items-center justify-center gap-1"
    }, dayItems.some(function (b) {
      return b.kind === 'booking';
    }) && /*#__PURE__*/React.createElement("span", {
      className: "h-2.5 w-2.5 rounded-full bg-violet-500"
    }), (dayItems.some(function (b) {
      return b.kind === 'block';
    }) || fullyBooked) && /*#__PURE__*/React.createElement("span", {
      className: "h-2.5 w-2.5 rounded-full bg-red-500"
    })));
  })), visibleCourtRows.map(function (row) {
    return /*#__PURE__*/React.createElement(React.Fragment, {
      key: row.id
    }, row.kind === 'group' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
      className: "sticky left-0 z-20 w-[132px] min-w-[132px] max-w-[132px] border-b px-2.5 py-2 shadow-[8px_0_16px_rgba(0,0,0,0.08)] ".concat(isLight ? 'border-slate-200 bg-gradient-to-b from-slate-100 to-slate-50' : 'border-zinc-800/80 bg-gradient-to-b from-[#252038] to-[#1a1628]')
    }, props.renderResourceCell ? props.renderResourceCell({
      view: 'week',
      row: {
        kind: 'group',
        id: row.id,
        label: row.label,
        count: row.count,
        collapsed: row.collapsed
      },
      isLight: isLight,
      onToggleGroup: function onToggleGroup(label) {
        return setCollapsedGroups(function (prev) {
          return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, label, !prev[label]));
        });
      }
    }) : /*#__PURE__*/React.createElement("button", {
      type: "button",
      "aria-expanded": !row.collapsed,
      onClick: function onClick() {
        return setCollapsedGroups(function (prev) {
          return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, row.label, !prev[row.label]));
        });
      },
      className: "flex w-full items-center gap-2 rounded-lg px-1 py-1 text-left transition-colors ".concat(isLight ? 'hover:bg-white/60' : 'hover:bg-white/[0.04] active:bg-white/[0.07]')
    }, /*#__PURE__*/React.createElement(DownOutlined, {
      style: {
        fontSize: 15
      },
      className: "shrink-0 transition-transform duration-200 ".concat(isLight ? 'text-slate-500' : 'text-zinc-500', " ").concat(row.collapsed ? '-rotate-90' : 'rotate-0'),
      "aria-hidden": true
    }), /*#__PURE__*/React.createElement("div", {
      className: "flex min-w-0 flex-1 items-center gap-1.5"
    }, /*#__PURE__*/React.createElement("span", {
      className: "truncate text-[13px] font-semibold leading-snug ".concat(isLight ? 'text-slate-800' : 'text-zinc-100')
    }, row.label), /*#__PURE__*/React.createElement("span", {
      className: "shrink-0 rounded-md px-1.5 py-0.5 text-[10px] font-semibold tabular-nums ".concat(isLight ? 'bg-violet-100 text-violet-800' : 'bg-zinc-800/90 text-zinc-300 ring-1 ring-zinc-600/40')
    }, row.count)))), weekDays.map(function (day) {
      var key = fmtDate(day);
      var groupCourts = visibleCourts.filter(function (court) {
        return court.type === row.label;
      });
      /** 分子：当日时间轴上无任何占用（无预约、无锁台）的资源数；分母：该类型下资源总数 */
      var idleCount = groupCourts.filter(function (court) {
        var s = courtDaySummary(court.id, key, bookings, hourSlots, slotStepHours);
        return s.occupiedHours.length === 0;
      }).length;
      var ratio = groupCourts.length > 0 ? idleCount / groupCourts.length : 0;
      return /*#__PURE__*/React.createElement("div", {
        key: "".concat(row.id, "-").concat(key),
        className: "border-b border-l p-3 text-center ".concat(isLight ? 'theme-border theme-panel-soft' : 'border-zinc-800 bg-[#151a2f]')
      }, /*#__PURE__*/React.createElement("div", {
        className: "text-xs font-semibold ".concat(getRemainingToneClass(ratio, isLight))
      }, idleCount, "/", groupCourts.length));
    })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
      className: "sticky left-0 z-20 w-[132px] min-w-[132px] max-w-[132px] border-b px-3 py-3 align-top shadow-[8px_0_16px_rgba(0,0,0,0.06)] ".concat(isLight ? 'theme-sticky theme-border' : 'border-zinc-800 bg-[#1a1a22]')
    }, props.renderResourceCell ? props.renderResourceCell({
      view: 'week',
      row: {
        kind: 'court',
        id: row.id,
        name: row.name,
        type: row.type
      },
      isLight: isLight
    }) : /*#__PURE__*/React.createElement("div", {
      className: "font-semibold text-[16px] leading-tight break-all"
    }, row.name)), weekDays.map(function (day) {
      var key = fmtDate(day);
      var summary = courtDaySummary(row.id, key, bookings, hourSlots, slotStepHours);
      var previewItems = summary.items.slice(0, 3);
      var moreItems = summary.items.slice(3);
      var moreCount = moreItems.length;
      var showMoreTile = moreCount > 0 && previewItems.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);
        },
        className: "relative flex flex-col justify-start min-h-[148px] border-b border-l p-3 text-left align-top transition ".concat(isLight ? 'theme-border' : '', " ").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 hover:bg-violet-100/80' : 'bg-[#1c1630] hover:bg-[#241c3f]' : isLight ? 'theme-grid-cell hover:bg-violet-50/60' : 'bg-zinc-900 hover:bg-zinc-800')
      }, /*#__PURE__*/React.createElement("div", {
        className: "absolute left-3 top-3 text-[13px] text-zinc-400"
      }, key), /*#__PURE__*/React.createElement("div", {
        className: "absolute right-3 top-3 flex gap-1"
      }, summary.occupiedHours.length > 0 && /*#__PURE__*/React.createElement("span", {
        className: "h-2.5 w-2.5 rounded-full bg-violet-500"
      }), (summary.hasBlock || summary.fullyBooked) && /*#__PURE__*/React.createElement("span", {
        className: "h-2.5 w-2.5 rounded-full bg-red-500"
      })), summary.fullyBooked ? /*#__PURE__*/React.createElement("div", {
        className: "mt-8 rounded-lg bg-zinc-700/70 px-2 py-1 text-xs"
      }, tCal('pisell2.recordBoard.calendar.week.fullyBooked')) : summary.items.length > 0 ? /*#__PURE__*/React.createElement("div", {
        className: "mt-8 flex flex-col items-start gap-1.5 w-full"
      }, previewItems.map(function (item, idx) {
        var isLastVisible = idx === previewItems.length - 1;
        var shrinkForMore = showMoreTile && isLastVisible;
        var layoutClassName = "rounded-lg px-3 py-2 text-xs text-left ".concat(getGridBookingRowStateClasses(item), " ").concat(shrinkForMore ? 'flex-1 min-w-0' : 'w-full');
        return /*#__PURE__*/React.createElement("div", {
          key: idx,
          className: "flex w-full items-stretch gap-2"
        }, props.renderMonthWeekBooking ? /*#__PURE__*/React.createElement("div", {
          className: shrinkForMore ? 'flex-1 min-w-0' : 'w-full'
        }, props.renderMonthWeekBooking({
          item: item,
          dateKey: key,
          view: 'week',
          isLight: isLight,
          layoutClassName: layoutClassName,
          onOpenDetail: openBookingDetail,
          onDragStart: function onDragStart(it) {
            return setDraggingItem(it);
          },
          draggable: false
        })) : /*#__PURE__*/React.createElement("button", {
          type: "button",
          onClick: function onClick(e) {
            e.stopPropagation();
            openBookingDetail(item);
          },
          className: layoutClassName
        }, /*#__PURE__*/React.createElement("div", {
          className: "truncate"
        }, item.name), /*#__PURE__*/React.createElement("div", {
          className: "mt-1 opacity-80"
        }, formatHourLabel(item.startHour), " -", ' ', formatHourLabel(item.endHour))), shrinkForMore && /*#__PURE__*/React.createElement("div", {
          className: "relative h-[52px] w-[52px] shrink-0",
          ref: (overflowPopover === null || overflowPopover === void 0 ? void 0 : overflowPopover.courtId) === row.id && (overflowPopover === null || overflowPopover === void 0 ? void 0 : overflowPopover.date) === key ? overflowPanelRef : null
        }, /*#__PURE__*/React.createElement("button", {
          onMouseEnter: function onMouseEnter(e) {
            e.stopPropagation();
            setOverflowPopover({
              courtId: row.id,
              date: key,
              items: moreItems,
              pinned: false
            });
          },
          onClick: function onClick(e) {
            e.stopPropagation();
            setOverflowPopover(null);
            setOverflowListModal(function (prev) {
              return prev && prev.scope === row.id && prev.date === key ? null : {
                scope: row.id,
                date: key,
                title: tCal('pisell2.recordBoard.calendar.overflow.listTitleAllBookings', {
                  date: key
                }),
                items: summary.items.filter(function (x) {
                  return x.kind === 'booking';
                })
              };
            });
          },
          className: "flex h-[52px] w-[52px] items-center justify-center rounded-xl bg-violet-700/90 text-sm font-semibold text-white"
        }, "+", moreCount)));
      })) : /*#__PURE__*/React.createElement("div", {
        className: "mt-8 rounded-lg border border-dashed border-zinc-700 px-2 py-2 text-xs text-zinc-500"
      }, tCal('pisell2.recordBoard.calendar.week.available')));
    })));
  })))));
}