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); }
import { getText } from "../../../../locales";
import { clamp, deriveVenueWallStatus, formatDurationHM, formatVenueWallCountdown } from "./venueWallUtils";

/** 与平面图 empty / reserved / occupied 对齐的三种大屏展示态 */

/**
 * 标题胶囊 5 态：在 floorLike 三大类基础上，把 `late` 与 `expired` 拆出独立色与文案，
 * 与当前区一档强调色（红）对齐。
 */

/** 由 {@link buildVenueWallCardPresentation} 产出，供 VenueWallCard 渲染层使用 */

function resolveFloorLikeStatus(statusKey) {
  if (statusKey === 'available') return 'empty';
  if (statusKey === 'boardingSoon' || statusKey === 'late') return 'reserved';
  return 'occupied';
}
function resolveHeaderStatusKey(statusKey) {
  if (statusKey === 'available') return 'empty';
  if (statusKey === 'boardingSoon') return 'reserved';
  if (statusKey === 'late') return 'late';
  if (statusKey === 'expired') return 'expired';
  return 'occupied';
}
function headerLabelForKey(key) {
  switch (key) {
    case 'empty':
      /** 空闲态：右上胶囊与当前区文案统一为「Not in use」 */
      return getText('pisell-resource-wall-card-current-not-in-use');
    case 'reserved':
      return getText('pisell-resource-wall-floor-status-reserved');
    case 'late':
      return getText('pisell-resource-wall-floor-status-late');
    case 'expired':
      return getText('pisell-resource-wall-floor-status-expired');
    default:
      return getText('pisell-resource-wall-floor-status-occupied');
  }
}
function sanitizeContact(booking) {
  var _booking$trim;
  var c = (_booking$trim = booking === null || booking === void 0 ? void 0 : booking.trim()) !== null && _booking$trim !== void 0 ? _booking$trim : '';
  if (c === 'Available to Book') return '';
  return c;
}

/**
 * 占用中进度条：**已使用时间占比**（左空右满随进行而增长）。
 * - 有场次起止：`elapsedMs / durationMs`
 * - 无起止：仍以 60 分为近似总长，`(60 - 剩余精确分) / 60`
 */
function resolveInUseProgressPercent(args) {
  var card = args.card,
    wallNowMs = args.wallNowMs,
    liveRemainingPreciseMin = args.liveRemainingPreciseMin;
  var end = card.sessionEndMs;
  var start = card.sessionStartMs;
  if (end != null && start != null && Number.isFinite(end) && Number.isFinite(start) && end > start) {
    var durationMs = end - start;
    var elapsedMs = Math.min(Math.max(0, wallNowMs - start), durationMs);
    return clamp(elapsedMs / durationMs * 100, 0, 100);
  }
  var denomMin = 60;
  var elapsedPreciseMin = denomMin - liveRemainingPreciseMin;
  return clamp(elapsedPreciseMin / denomMin * 100, 0, 100);
}

/**
 * 纯函数：三态大屏文案 + 进度 + 条件跑马灯。
 * 右上角标题栏仅保留 empty/reserved/occupied；迟到/超时只出现在当前区一档主提示。
 */
export function buildVenueWallCardPresentation(args) {
  var _toneMap$statusKey, _toneMap$late, _toneMap$expired, _card$currentTime;
  var card = args.card,
    toneMap = args.toneMap,
    wallNowMs = args.wallNowMs,
    liveRemainingMin = args.liveRemainingMin,
    liveRemainingPreciseMin = args.liveRemainingPreciseMin,
    liveStartsInMin = args.liveStartsInMin,
    liveLateMin = args.liveLateMin,
    boardingSoonBeforeMin = args.boardingSoonBeforeMin,
    idleMain = args.idleMain,
    idleSub = args.idleSub,
    availableCardColor = args.availableCardColor;
  var statusKey = deriveVenueWallStatus(_objectSpread(_objectSpread({}, card), {}, {
    remainingMin: liveRemainingMin
  }));
  var floorLikeStatus = resolveFloorLikeStatus(statusKey);
  var headerStatusKey = resolveHeaderStatusKey(statusKey);
  var headerStatusLabel = headerLabelForKey(headerStatusKey);
  var tone = (_toneMap$statusKey = toneMap[statusKey]) !== null && _toneMap$statusKey !== void 0 ? _toneMap$statusKey : toneMap.inUse;
  var endingSoonTone = toneMap.endingSoon;
  var boardingTone = toneMap.boardingSoon;
  var lateTone = (_toneMap$late = toneMap.late) !== null && _toneMap$late !== void 0 ? _toneMap$late : boardingTone;
  var expiredTone = (_toneMap$expired = toneMap.expired) !== null && _toneMap$expired !== void 0 ? _toneMap$expired : endingSoonTone;
  var cardVariant = floorLikeStatus === 'occupied' ? 'occupied' : 'accent';
  var mainOnOccupied = '#ffffff';
  /**
   * 占用卡内次级文案默认色（下一预约区等）；「当前预约」标题/时段/联系人在 VenueWallCard 内单独铺纯白 + 阴影。
   */
  var subOnOccupied = 'rgba(255,255,255,0.88)';
  var mainColor = cardVariant === 'occupied' ? mainOnOccupied : idleMain;
  var subColor = cardVariant === 'occupied' ? subOnOccupied : idleSub;
  var surfaceAccentColor = availableCardColor;
  if (floorLikeStatus === 'reserved') {
    surfaceAccentColor = boardingTone.color;
  }
  var timeRangeLine = ((_card$currentTime = card.currentTime) !== null && _card$currentTime !== void 0 ? _card$currentTime : '').trim();
  var contactLine = sanitizeContact(card.currentBooking);
  var primaryEmphasisLine = '';
  var primaryEmphasisColor = mainColor;
  var progress = 0;
  var progressColor = mainOnOccupied;
  var showProgress = false;
  var rmDisplay = Math.max(0, liveRemainingMin);
  var endingWindowMin = Math.max(1, boardingSoonBeforeMin);
  var inEndingSoonWindow = floorLikeStatus === 'occupied' && liveRemainingMin >= 0 && liveRemainingMin <= endingWindowMin;

  /** 临近结束（含剩余 0）时跑马灯；已过期/负剩余不展示 */
  var showEndingSoonMarquee = floorLikeStatus === 'occupied' && inEndingSoonWindow && statusKey !== 'expired';
  if (statusKey === 'available') {
    primaryEmphasisLine = '';
    primaryEmphasisColor = mainColor;
  } else if (statusKey === 'boardingSoon') {
    /** 仅「占用中」展示进度条；预约中仅文案与色 */
    primaryEmphasisLine = getText('pisell-resource-wall-card-starts-in').replace('{n}', formatDurationHM(liveStartsInMin));
    primaryEmphasisColor = boardingTone.color;
  } else if (statusKey === 'late') {
    primaryEmphasisLine = getText('pisell-resource-wall-card-late').replace('{n}', formatDurationHM(Math.max(0, Math.floor(liveLateMin))));
    primaryEmphasisColor = lateTone.color;
  } else if (statusKey === 'inUse' || statusKey === 'endingSoon' || statusKey === 'expired') {
    showProgress = true;
    var sessionEndedNoOvertimeCopy = statusKey === 'expired' || liveRemainingMin < 0;
    if (sessionEndedNoOvertimeCopy) {
      /** 已结束/超时：进度条满格表示时段已用尽 */
      progress = 100;
      progressColor = expiredTone.color;
      if (liveRemainingMin < 0) {
        primaryEmphasisLine = formatVenueWallCountdown(liveRemainingMin);
      } else {
        primaryEmphasisLine = getText('pisell-resource-wall-countdown-zero-overtime');
      }
      primaryEmphasisColor = expiredTone.color;
    } else {
      progress = resolveInUseProgressPercent({
        card: card,
        wallNowMs: wallNowMs,
        liveRemainingPreciseMin: liveRemainingPreciseMin
      });
      progressColor = statusKey === 'endingSoon' || inEndingSoonWindow ? endingSoonTone.color : mainOnOccupied;
      primaryEmphasisLine = formatVenueWallCountdown(rmDisplay);
      primaryEmphasisColor = statusKey === 'endingSoon' || inEndingSoonWindow ? endingSoonTone.color : mainOnOccupied;
    }
  }
  var marqueeText = showEndingSoonMarquee ? getText('pisell-resource-wall-marquee-ending-soon') : '';

  /** 跑马灯文案固定白色 */
  var marqueeColor = showEndingSoonMarquee ? '#ffffff' : cardVariant === 'occupied' ? 'rgba(255,255,255,0.92)' : endingSoonTone.color;

  /** 与当前区一档状态字同色相叠底（快结束时与倒计时一致） */
  var marqueeShellBackground = showEndingSoonMarquee ? primaryEmphasisColor : 'transparent';

  /** 标题胶囊主色：迟到/超时取各自 tone（红），其余沿用既有规则（empty=avail、reserved=boarding、occupied=白） */
  var headerStatusColor;
  if (headerStatusKey === 'empty') headerStatusColor = availableCardColor;else if (headerStatusKey === 'reserved') headerStatusColor = boardingTone.color;else if (headerStatusKey === 'late') headerStatusColor = lateTone.color;else if (headerStatusKey === 'expired') headerStatusColor = expiredTone.color;else headerStatusColor = '#ffffff';
  return {
    statusKey: statusKey,
    floorLikeStatus: floorLikeStatus,
    headerStatusKey: headerStatusKey,
    headerStatusLabel: headerStatusLabel,
    headerStatusColor: headerStatusColor,
    cardVariant: cardVariant,
    mainColor: mainColor,
    subColor: subColor,
    surfaceAccentColor: surfaceAccentColor,
    primaryEmphasisLine: primaryEmphasisLine,
    primaryEmphasisColor: primaryEmphasisColor,
    timeRangeLine: timeRangeLine,
    contactLine: contactLine,
    showProgress: showProgress,
    progress: progress,
    progressColor: progressColor,
    showEndingSoonMarquee: showEndingSoonMarquee,
    marqueeText: marqueeText,
    marqueeColor: marqueeColor,
    marqueeShellBackground: marqueeShellBackground
  };
}