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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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); }
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 _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; }
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; }
import React, { useEffect, useMemo, useReducer, useRef } from 'react';
import { FloorRoomCardFromData } from "./FloorRoomCardFromData";
import { FloorRoomCardDensityContext, isFloorRoomCardTooltipDensity, toFloorRoomCardUiDensity, useResolvedFloorRoomCardDensity } from "./floorRoomCardDensity";
import { getFloorRoomCardPrimaryBooking, getFloorRoomCardType, resolveFloorRoomCardProgressPercent } from "./floorRoomCardUtils";
import { FLOOR_ROOM_CARD_DISC_EDGE_RING_ENABLED } from "./floorRoomCardDiscEdge";
import { RoomCardDiscEdgeProgress } from "./views/RoomCardDiscEdgeProgress";
import { RoomCardRectEdgeProgress } from "./views/RoomCardRectEdgeProgress";

/** 圆桌单条占用外缘环：与 buildCardBodyViewModel.showEdgeProgressRing 条件一致 */
function resolveCircleSingleOccupiedDiscEdgeProgress(data) {
  var t = getFloorRoomCardType(data);
  if (t !== 'payed' && t !== 'payment_required' && t !== 'timeout') {
    return null;
  }
  var booking = getFloorRoomCardPrimaryBooking(data);
  if (!booking) return null;
  return {
    percent: resolveFloorRoomCardProgressPercent(booking),
    isTimeout: t === 'timeout'
  };
}
function resolveRectSingleOccupiedEdgeProgress(data) {
  var t = getFloorRoomCardType(data);
  if (t !== 'payed' && t !== 'payment_required' && t !== 'timeout') {
    return null;
  }
  var booking = getFloorRoomCardPrimaryBooking(data);
  if (!booking) return null;
  return {
    percent: resolveFloorRoomCardProgressPercent(booking),
    isTimeout: t === 'timeout'
  };
}

/**
 * 平面图绑定桌位：RoomCard 视觉（demo 样式）+ 业务行映射数据。
 * 内层为 {@link FloorRoomCardFromData}；本组件仅外包根节点并每分钟触发重绘以刷新倒计时/进度。
 *
 * **视觉大卡 vs Tooltip 小卡**：根节点 `data-density` 仅 comfortable / micro；
 * **方桌**仅测量档 **micro** 为小卡壳；**圆桌** **mini / micro** 为小卡壳。正文仍用解析档区分 mini/micro。
 */
export function ReservationFloorRoomCard(props) {
  var _data$bookings$length, _data$bookings, _data$bookings$length2, _data$bookings2;
  var data = props.data,
    _props$theme = props.theme,
    theme = _props$theme === void 0 ? 'default' : _props$theme,
    _props$shellShape = props.shellShape,
    shellShape = _props$shellShape === void 0 ? 'rect' : _props$shellShape,
    elementLayoutHeightPx = props.elementLayoutHeightPx,
    _props$hideHeaderCapa = props.hideHeaderCapacity,
    hideHeaderCapacity = _props$hideHeaderCapa === void 0 ? false : _props$hideHeaderCapa,
    _props$density = props.density,
    density = _props$density === void 0 ? 'auto' : _props$density,
    _props$viewportScale = props.viewportScale,
    viewportScale = _props$viewportScale === void 0 ? 1 : _props$viewportScale,
    _props$discUnifiedLay = props.discUnifiedLayoutEnabled,
    discUnifiedLayoutEnabled = _props$discUnifiedLay === void 0 ? true : _props$discUnifiedLay,
    _props$tooltipTimeDen = props.tooltipTimeDensityEnabled,
    tooltipTimeDensityEnabled = _props$tooltipTimeDen === void 0 ? true : _props$tooltipTimeDen;
  var rootRef = useRef(null);
  /** 含 Next，bookings 长度 >1 即按多条卡：强制大卡密度与缩放策略 */
  var isMultiCard = ((_data$bookings$length = (_data$bookings = data.bookings) === null || _data$bookings === void 0 ? void 0 : _data$bookings.length) !== null && _data$bookings$length !== void 0 ? _data$bookings$length : 0) > 1;
  var autoResolvedDensity = useResolvedFloorRoomCardDensity({
    rootRef: rootRef,
    density: density,
    viewportScale: viewportScale
  });
  /** 内层组件用解析档（含 mini/micro），以便正文窄屏分支与 buildModel 一致 */
  var resolvedDensity = useMemo(function () {
    if (isMultiCard) return 'comfortable';
    return density === 'auto' ? autoResolvedDensity : density;
  }, [isMultiCard, density, autoResolvedDensity]);
  /** 根节点 data-density：方桌仅 micro 为小卡壳；圆桌 mini/micro 为小卡壳 */
  var uiDensity = useMemo(function () {
    return toFloorRoomCardUiDensity(resolvedDensity, shellShape);
  }, [resolvedDensity, shellShape]);
  var shapeData = shellShape === 'circle' ? {
    'data-shape': 'circle'
  } : {};
  var discEdgeProgress = FLOOR_ROOM_CARD_DISC_EDGE_RING_ENABLED && shellShape === 'circle' ? resolveCircleSingleOccupiedDiscEdgeProgress(data) : null;
  var rootCardType = getFloorRoomCardType(data);
  var reservedHaloEnabled = rootCardType === 'not_arrived' || rootCardType === 'late' || rootCardType === 'multi_reserved';
  var rectEdgeProgress = shellShape === 'rect' && isFloorRoomCardTooltipDensity(resolvedDensity, shellShape) && ((_data$bookings$length2 = (_data$bookings2 = data.bookings) === null || _data$bookings2 === void 0 ? void 0 : _data$bookings2.length) !== null && _data$bookings$length2 !== void 0 ? _data$bookings$length2 : 0) === 1 ? resolveRectSingleOccupiedEdgeProgress(data) : null;
  var vs = Number.isFinite(viewportScale) && viewportScale > 0 ? viewportScale : 1;
  /** 传入内层的是 min(scale,1)；与 scale(1/vs) + 小布局盒配合，只在缩小时放大图元绘制以抵消 zoom */
  var viewportCompensateScale = isMultiCard ? 1 : Math.min(vs, 1);
  var _useReducer = useReducer(function (x) {
      return x + 1;
    }, 0),
    _useReducer2 = _slicedToArray(_useReducer, 2),
    bumpLayoutTick = _useReducer2[1];
  useEffect(function () {
    var id = window.setInterval(function () {
      bumpLayoutTick();
    }, 60000);
    return function () {
      return window.clearInterval(id);
    };
  }, []);
  return /*#__PURE__*/React.createElement("div", _extends({
    ref: rootRef,
    className: "pisell-res-floor-room-card",
    "data-theme": theme === 'default' ? undefined : theme,
    "data-density": uiDensity,
    "data-disc-layout": discUnifiedLayoutEnabled ? 'unified' : 'legacy',
    "data-tooltip-time": tooltipTimeDensityEnabled && isFloorRoomCardTooltipDensity(resolvedDensity, shellShape) ? 'on' : 'off',
    "data-reserved-halo": reservedHaloEnabled ? 'on' : 'off',
    "data-rect-edge-progress": rectEdgeProgress ? 'on' : 'off',
    style: _defineProperty({}, '--floor-card-vs', String(viewportCompensateScale))
  }, shapeData), /*#__PURE__*/React.createElement(FloorRoomCardDensityContext.Provider, {
    value: resolvedDensity
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-res-floor-room-card__viewport-compensate"
  }, /*#__PURE__*/React.createElement(FloorRoomCardFromData, {
    data: data,
    shellShape: shellShape,
    elementLayoutHeightPx: elementLayoutHeightPx,
    hideHeaderCapacity: hideHeaderCapacity,
    discUnifiedLayoutEnabled: discUnifiedLayoutEnabled,
    tooltipTimeDensityEnabled: tooltipTimeDensityEnabled
  }), discEdgeProgress ? /*#__PURE__*/React.createElement(RoomCardDiscEdgeProgress, {
    percent: discEdgeProgress.percent,
    isTimeout: discEdgeProgress.isTimeout
  }) : null, rectEdgeProgress ? /*#__PURE__*/React.createElement(RoomCardRectEdgeProgress, {
    percent: rectEdgeProgress.percent,
    isTimeout: rectEdgeProgress.isTimeout
  }) : null)));
}