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); }
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 _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 _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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Spin } from 'antd';
import { getText } from "../../../../locales";
import { getCurrentLocale } from "../../../../utils/locale";
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext";
import { DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST } from "../../types";
import { DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS, getVenueWallStatusToneMap, matchesResourceWallStatusSortField, parseRecordBoardToolbarSortParam, venueWallOccupiedSortRank } from "./venueWallUtils";
import { VenueWallCard } from "./VenueWallCard";
import { ResourceWallControlPanel } from "./ResourceWallControlPanel";
import { ResourceWallViewportToolbar } from "./ResourceWallViewportToolbar";
import "./ResourceWallViewport.less";

/** 与 {@link RecordBoardResourceWallProps.filterFieldKey} 默认一致 */
export var DEFAULT_RESOURCE_WALL_FILTER_FIELD_KEY = 'resource_wall_resource_ids';

/** 伪全屏偏好：刷新后若为 `1` 自动恢复 body 固定视口（与按钮状态一致） */
var RESOURCE_WALL_PSEUDO_FULLSCREEN_STORAGE_KEY = 'pisell.recordBoard.resourceWall.pseudoFullscreen';
function readStoredPseudoFullscreen() {
  try {
    return typeof window !== 'undefined' && window.localStorage.getItem(RESOURCE_WALL_PSEUDO_FULLSCREEN_STORAGE_KEY) === '1';
  } catch (_unused) {
    return false;
  }
}
function persistPseudoFullscreen(on) {
  try {
    if (typeof window !== 'undefined') {
      window.localStorage.setItem(RESOURCE_WALL_PSEUDO_FULLSCREEN_STORAGE_KEY, on ? '1' : '0');
    }
  } catch (_unused2) {
    /* quota / private mode */
  }
}
var FILTER_PARAMS_FIELD = 'filter';
var LAYOUT_PRESETS = [{
  key: '1x1',
  label: '1 × 1',
  cols: 1,
  rows: 1
}, {
  key: '1x2',
  label: '1 × 2',
  cols: 2,
  rows: 1
}, {
  key: '2x3',
  label: '2 × 3',
  cols: 3,
  rows: 2
}, {
  key: '3x2',
  label: '3 × 2',
  cols: 2,
  rows: 3
}, {
  key: '3x3',
  label: '3 × 3',
  cols: 3,
  rows: 3
}, {
  key: 'custom',
  label: '',
  cols: 3,
  rows: 2
}];
var DEFAULT_OCCUPIED = '#6f4ae6';
var DEFAULT_AVAILABLE = '#94a3b8';

/**
 * RecordBoard 大屏资源墙主视口：`cards` 提供全量卡数据；可见列表由
 * `searchParams.filter.values[filterFieldKey]` 中的资源 id 与 `cards` 交集决定。
 * 若 ToolBar `searchParams.sort` 指向状态列（默认字段名 `status`），则按占用态重排展示顺序。
 * 支持网格分页轮播、浅深外观、伪全屏与控制台（布局 / 配色 / 选中资源）。
 */
export var PisellRecordBoardResourceWallView = function PisellRecordBoardResourceWallView(props) {
  var _props$filterFieldKey, _ctx$searchParams3, _appearanceTheme$appe, _pagedGroups$currentP;
  var className = props.className,
    style = props.style,
    loading = props.loading,
    cardsProp = props.cards,
    statusToneOverridesProp = props.statusToneOverrides,
    onStatusToneOverridesChange = props.onStatusToneOverridesChange,
    appearanceThemeProp = props.appearanceTheme,
    onAppearanceThemeChange = props.onAppearanceThemeChange,
    appearanceModeProp = props.appearanceMode,
    onAppearanceModeChange = props.onAppearanceModeChange,
    resourceWallLayoutProp = props.resourceWallLayout,
    onResourceWallLayoutChange = props.onResourceWallLayoutChange,
    statusSortFieldKeysProp = props.statusSortFieldKeys;
  var ctx = useRecordBoardContext();
  var filterKey = (_props$filterFieldKey = props.filterFieldKey) !== null && _props$filterFieldKey !== void 0 ? _props$filterFieldKey : DEFAULT_RESOURCE_WALL_FILTER_FIELD_KEY;
  var statusSortFieldKeys = useMemo(function () {
    return statusSortFieldKeysProp != null && statusSortFieldKeysProp.length > 0 ? statusSortFieldKeysProp : _toConsumableArray(DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS);
  }, [statusSortFieldKeysProp]);
  var _useState = useState({}),
    _useState2 = _slicedToArray(_useState, 2),
    localToneOverrides = _useState2[0],
    setLocalToneOverrides = _useState2[1];
  /** 六态标注覆盖：有受控回调则只上报；否则写本地 state（演示 / 未持久化宿主） */
  var emitToneOverrides = useCallback(function (next) {
    onStatusToneOverridesChange === null || onStatusToneOverridesChange === void 0 || onStatusToneOverridesChange(next);
    if (onStatusToneOverridesChange == null) {
      setLocalToneOverrides(next);
    }
  }, [onStatusToneOverridesChange]);
  var _useState3 = useState({}),
    _useState4 = _slicedToArray(_useState3, 2),
    internalAppearanceTheme = _useState4[0],
    setInternalAppearanceTheme = _useState4[1];
  var appearanceTheme = appearanceThemeProp !== null && appearanceThemeProp !== void 0 ? appearanceThemeProp : internalAppearanceTheme;
  /** 占用/空闲底色与六态覆盖按浅、深槽位写入主题对象 */
  var persistAppearanceTheme = useCallback(function (next) {
    onAppearanceThemeChange === null || onAppearanceThemeChange === void 0 || onAppearanceThemeChange(next);
    if (onAppearanceThemeChange == null) {
      setInternalAppearanceTheme(next);
    }
  }, [onAppearanceThemeChange]);

  /**
   * 资源墙可见 id：未写键、非数组、空数组一律视为「无选中」→ 不展示任何卡片。
   * 有非空 string[] 时按该顺序展示：**仅渲染能在 `cards` 里命中的**；命中不到的 id（例如磁盘残留的
   * 旧店铺 / 已删资源）直接剔除，不再回退成「数字占位卡」。磁盘侧由宿主（如 PisellReservation）
   * 水合后清洗并回写 localStorage，避免下次继续飘过来。
   */
  var filterValues = useMemo(function () {
    var _ctx$searchParams;
    var f = (_ctx$searchParams = ctx.searchParams) === null || _ctx$searchParams === void 0 ? void 0 : _ctx$searchParams.filter;
    if (!f || _typeof(f) !== 'object' || f === null) return undefined;
    var v = f.values;
    if (v === null || v === undefined || _typeof(v) !== 'object' || Array.isArray(v)) {
      return undefined;
    }
    return v;
  }, [ctx.searchParams]);
  var hasResourceWallFilterKey = filterValues != null && Object.prototype.hasOwnProperty.call(filterValues, filterKey);
  var selectedRaw = hasResourceWallFilterKey ? filterValues[filterKey] : undefined;
  var wallSelectedIds = useMemo(function () {
    if (!hasResourceWallFilterKey) return [];
    if (!Array.isArray(selectedRaw)) return [];
    var seen = new Set();
    var out = [];
    var _iterator = _createForOfIteratorHelper(selectedRaw),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var x = _step.value;
        var t = String(x).trim();
        if (!t || seen.has(t)) continue;
        seen.add(t);
        out.push(t);
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return out;
  }, [hasResourceWallFilterKey, selectedRaw]);
  var cards = cardsProp !== null && cardsProp !== void 0 ? cardsProp : [];
  /** 按 resourceId 建表，便于按筛选 id 顺序 O(1) 取卡 */
  var cardByResourceId = useMemo(function () {
    var m = new Map();
    var _iterator2 = _createForOfIteratorHelper(cards),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var c = _step2.value;
        m.set(String(c.resourceId), c);
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    return m;
  }, [cards]);

  /**
   * 仅渲染「筛选 id 序列 ∩ cards」；缺数据的 id 直接跳过。
   * 若当前 `searchParams.sort` 指向状态列（见 statusSortFieldKeys），在筛选顺序上做稳定排序：
   * desc → 占用态在前；asc → 空闲态在前。
   */
  var visibleCards = useMemo(function () {
    var _ctx$searchParams2;
    if (!wallSelectedIds.length) {
      return [];
    }
    var result = [];
    var _iterator3 = _createForOfIteratorHelper(wallSelectedIds),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var id = _step3.value;
        var hit = cardByResourceId.get(String(id));
        if (hit) result.push(hit);
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var parsed = parseRecordBoardToolbarSortParam((_ctx$searchParams2 = ctx.searchParams) === null || _ctx$searchParams2 === void 0 ? void 0 : _ctx$searchParams2.sort);
    if (parsed && matchesResourceWallStatusSortField(parsed.field, statusSortFieldKeys)) {
      var dir = parsed.dir;
      var indexed = result.map(function (card, idx) {
        return {
          card: card,
          idx: idx
        };
      });
      indexed.sort(function (a, b) {
        var ra = venueWallOccupiedSortRank(a.card);
        var rb = venueWallOccupiedSortRank(b.card);
        if (ra !== rb) {
          return dir === 'asc' ? ra - rb : rb - ra;
        }
        return a.idx - b.idx;
      });
      return indexed.map(function (x) {
        return x.card;
      });
    }
    return result;
  }, [cardByResourceId, wallSelectedIds, (_ctx$searchParams3 = ctx.searchParams) === null || _ctx$searchParams3 === void 0 ? void 0 : _ctx$searchParams3.sort, statusSortFieldKeys]);

  /** 顶栏时钟 / 日期展示 */
  var _useState5 = useState(function () {
      return new Date();
    }),
    _useState6 = _slicedToArray(_useState5, 2),
    now = _useState6[0],
    setNow = _useState6[1];
  useEffect(function () {
    var id = window.setInterval(function () {
      return setNow(new Date());
    }, 1000);
    return function () {
      return window.clearInterval(id);
    };
  }, []);

  /** 浅深主题：双受控（props + onChange）时完全由外部驱动，否则用内部 state */
  var _useState7 = useState('light'),
    _useState8 = _slicedToArray(_useState7, 2),
    internalAppearanceMode = _useState8[0],
    setInternalAppearanceMode = _useState8[1];
  var appearanceModeControlled = appearanceModeProp !== undefined && onAppearanceModeChange != null;
  var appearanceMode = appearanceModeControlled ? appearanceModeProp : internalAppearanceMode;
  var setAppearanceMode = useCallback(function (m) {
    onAppearanceModeChange === null || onAppearanceModeChange === void 0 || onAppearanceModeChange(m);
    if (!appearanceModeControlled) {
      setInternalAppearanceMode(m);
    }
  }, [appearanceModeControlled, onAppearanceModeChange]);
  var _useState9 = useState(false),
    _useState10 = _slicedToArray(_useState9, 2),
    showControlPanel = _useState10[0],
    setShowControlPanel = _useState10[1];
  var closeControlPanel = useCallback(function () {
    setShowControlPanel(false);
  }, []);
  var _useState11 = useState(0),
    _useState12 = _slicedToArray(_useState11, 2),
    currentPage = _useState12[0],
    setCurrentPage = _useState12[1];
  var _useState13 = useState(readStoredPseudoFullscreen),
    _useState14 = _slicedToArray(_useState13, 2),
    pseudoFullscreen = _useState14[0],
    setPseudoFullscreen = _useState14[1];
  var togglePseudoFullscreen = useCallback(function () {
    setPseudoFullscreen(function (prev) {
      var next = !prev;
      persistPseudoFullscreen(next);
      return next;
    });
  }, []);
  var shellRef = useRef(null);

  /** 伪全屏：给 body 挂类名，配合 less 撑满视口且压住部分宿主布局 */
  useEffect(function () {
    var cls = 'pisell-resource-wall-fixed-viewport';
    if (typeof document === 'undefined') return;
    if (pseudoFullscreen) {
      document.body.classList.add(cls);
    } else {
      document.body.classList.remove(cls);
    }
    return function () {
      document.body.classList.remove(cls);
    };
  }, [pseudoFullscreen]);

  /** 布局持久化：有 `onResourceWallLayoutChange` 时为受控；否则本地默认 + `setLayoutState` 补丁 */
  var layoutPersisted = onResourceWallLayoutChange != null;
  var _useState15 = useState(function () {
      return _objectSpread({}, DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST);
    }),
    _useState16 = _slicedToArray(_useState15, 2),
    internalLayout = _useState16[0],
    setInternalLayout = _useState16[1];
  var layoutState = layoutPersisted ? _objectSpread(_objectSpread({}, DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST), resourceWallLayoutProp !== null && resourceWallLayoutProp !== void 0 ? resourceWallLayoutProp : {}) : internalLayout;
  var setLayoutState = useCallback(function (patch) {
    if (layoutPersisted) {
      onResourceWallLayoutChange(_objectSpread(_objectSpread(_objectSpread({}, DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST), resourceWallLayoutProp !== null && resourceWallLayoutProp !== void 0 ? resourceWallLayoutProp : {}), patch));
    } else {
      setInternalLayout(function (prev) {
        return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST), prev), patch);
      });
    }
  }, [layoutPersisted, resourceWallLayoutProp, onResourceWallLayoutChange]);
  var layoutKey = layoutState.layoutKey,
    customCols = layoutState.customCols,
    customRows = layoutState.customRows,
    pageDurationSec = layoutState.pageDurationSec,
    boardingSoonBeforeMin = layoutState.boardingSoonBeforeMin,
    heroMaxWidthRatio = layoutState.heroMaxWidthRatio;
  var localeKey = getCurrentLocale();
  var layoutPresetsWithI18n = useMemo(function () {
    return LAYOUT_PRESETS.map(function (p) {
      return _objectSpread(_objectSpread({}, p), {}, {
        label: p.key === 'custom' ? getText('pisell-resource-wall-layout-custom') : p.label
      });
    });
  }, [localeKey]);

  /** 当前外观模式下的槽位：占用/空闲底色 + 六态覆盖（含未持久化时的 props 回退） */
  var modeSlot = (_appearanceTheme$appe = appearanceTheme[appearanceMode]) !== null && _appearanceTheme$appe !== void 0 ? _appearanceTheme$appe : {};
  var occupiedCardColor = modeSlot.occupiedCardColor != null && modeSlot.occupiedCardColor !== '' ? modeSlot.occupiedCardColor : DEFAULT_OCCUPIED;
  var availableCardColor = modeSlot.availableCardColor != null && modeSlot.availableCardColor !== '' ? modeSlot.availableCardColor : DEFAULT_AVAILABLE;
  var modeToneOverrides = modeSlot.statusToneOverrides;
  var hasModeToneOverrides = modeToneOverrides != null && Object.keys(modeToneOverrides).length > 0;
  var statusToneOverrides = hasModeToneOverrides ? modeToneOverrides : statusToneOverridesProp !== undefined ? statusToneOverridesProp : localToneOverrides;

  /** 解析当前选中的预设（含 custom 行列钳位） */
  var selectedLayout = useMemo(function () {
    var _layoutPresetsWithI;
    if (layoutKey === 'custom') {
      return {
        key: 'custom',
        label: getText('pisell-resource-wall-layout-custom'),
        cols: Math.max(1, Math.min(6, customCols)),
        rows: Math.max(1, Math.min(6, customRows))
      };
    }
    return (_layoutPresetsWithI = layoutPresetsWithI18n.find(function (p) {
      return p.key === layoutKey;
    })) !== null && _layoutPresetsWithI !== void 0 ? _layoutPresetsWithI : layoutPresetsWithI18n[2];
  }, [layoutKey, customCols, customRows, layoutPresetsWithI18n]);
  var pageCapacity = selectedLayout.cols * selectedLayout.rows;
  /** 按单页容量切分可见卡，用于轮播与指示条 */
  var pagedGroups = useMemo(function () {
    var chunks = [];
    for (var i = 0; i < visibleCards.length; i += pageCapacity) {
      chunks.push(visibleCards.slice(i, i + pageCapacity));
    }
    return chunks;
  }, [visibleCards, pageCapacity]);
  var totalPages = Math.max(1, pagedGroups.length);
  /** 当前页要渲染的卡；无分页时退化为首屏 capacity 张 */
  var renderCards = (_pagedGroups$currentP = pagedGroups[currentPage]) !== null && _pagedGroups$currentP !== void 0 ? _pagedGroups$currentP : visibleCards.slice(0, pageCapacity);

  /** 控制台展示与顶栏一致的当前页 / 总页（1-based 在文案 replace 时处理） */
  var controlCarouselPager = useMemo(function () {
    return {
      currentPage: currentPage,
      totalPages: totalPages
    };
  }, [currentPage, totalPages]);

  /** 总页数变小时收回当前页索引，避免越界 */
  useEffect(function () {
    setCurrentPage(function (p) {
      return totalPages > 0 ? Math.min(p, totalPages - 1) : 0;
    });
  }, [totalPages]);

  /** 多页时按 `pageDurationSec` 自动轮播当前页 */
  useEffect(function () {
    if (totalPages <= 1) {
      setCurrentPage(0);
      return;
    }
    var ms = Math.max(3, pageDurationSec) * 1000;
    var timer = window.setInterval(function () {
      setCurrentPage(function (p) {
        return (p + 1) % totalPages;
      });
    }, ms);
    return function () {
      return window.clearInterval(timer);
    };
  }, [totalPages, pageDurationSec]);

  /** 网格容量或可见卡数量变化时回到第一页 */
  useEffect(function () {
    setCurrentPage(0);
  }, [pageCapacity, visibleCards.length]);

  /**
   * 写入 `filter.values[filterKey]`；`ids` 可为 `[]`（大屏不展示）。
   * 宿主合并 `onSearch` 时请保留该键；删掉键时本视图同样按「无选中」处理（不展示）。
   */
  var mergeFilterResourceIds = useCallback(function (ids) {
    var _ctx$searchParams4, _filterValue$values, _ctx$onSearch;
    var sp = (_ctx$searchParams4 = ctx.searchParams) !== null && _ctx$searchParams4 !== void 0 ? _ctx$searchParams4 : {};
    var filterValue = sp[FILTER_PARAMS_FIELD];
    var currentValues = (_filterValue$values = filterValue === null || filterValue === void 0 ? void 0 : filterValue.values) !== null && _filterValue$values !== void 0 ? _filterValue$values : {};
    var nextFilter = _objectSpread(_objectSpread({}, filterValue), {}, {
      values: _objectSpread(_objectSpread({}, currentValues), {}, _defineProperty({}, filterKey, ids))
    });
    (_ctx$onSearch = ctx.onSearch) === null || _ctx$onSearch === void 0 || _ctx$onSearch.call(ctx, _objectSpread(_objectSpread({}, sp), {}, _defineProperty({}, FILTER_PARAMS_FIELD, nextFilter)));
  }, [ctx, filterKey]);

  /** 控制台「应用」：同步筛选 id、布局持久化、当前外观槽位下的占用/空闲色与六态覆盖 */
  var handleControlApply = useCallback(function (payload) {
    mergeFilterResourceIds(payload.resourceIds);
    setLayoutState({
      layoutKey: payload.layoutKey,
      customCols: payload.customCols,
      customRows: payload.customRows,
      pageDurationSec: payload.pageDurationSec,
      boardingSoonBeforeMin: payload.boardingSoonBeforeMin,
      heroMaxWidthRatio: payload.heroMaxWidthRatio
    });
    var nextSlot = _objectSpread(_objectSpread({}, appearanceTheme[appearanceMode]), {}, {
      occupiedCardColor: payload.occupiedCardColor,
      availableCardColor: payload.availableCardColor,
      statusToneOverrides: payload.statusToneOverrides
    });
    persistAppearanceTheme(_objectSpread(_objectSpread({}, appearanceTheme), {}, _defineProperty({}, appearanceMode, nextSlot)));
    emitToneOverrides(payload.statusToneOverrides);
  }, [mergeFilterResourceIds, emitToneOverrides, appearanceTheme, appearanceMode, persistAppearanceTheme, setLayoutState]);

  /** 注入 i18n 后的完整六态表（含控制台覆盖），下发各 {@link VenueWallCard} */
  var statusToneMap = useMemo(function () {
    return getVenueWallStatusToneMap(statusToneOverrides);
  }, [statusToneOverrides]);

  /** 浅色态与历史实现一致（扁平顶栏 + 灰底内容区）；深色仅微调背景与顶栏，不套「卡片套卡片」大圆角壳 */
  var isDark = appearanceMode === 'dark';
  var pageBg = isDark ? '#0f172a' : '#f5f7fb';
  var headerBg = isDark ? '#1e293b' : '#ffffff';
  var headerBorder = isDark ? '1px solid #334155' : '1px solid #e2e8f0';
  var clockColor = isDark ? '#f1f5f9' : '#0f172a';
  var mutedText = isDark ? '#94a3b8' : '#64748b';
  var toolbarBtnBorder = isDark ? '1px solid #475569' : '1px solid #e2e8f0';
  var toolbarBtnBg = isDark ? '#334155' : '#ffffff';
  var toolbarBtnBgActive = isDark ? '#475569' : '#f1f5f9';
  var countdownSec = Math.max(3, pageDurationSec);
  var shell = /*#__PURE__*/React.createElement("div", {
    ref: shellRef,
    className: "pisell-resource-wall-shell".concat(className ? " ".concat(className) : ''),
    style: _objectSpread({
      flex: 1,
      minHeight: 0,
      display: 'flex',
      flexDirection: 'column',
      overflow: 'hidden',
      background: pageBg,
      color: clockColor
    }, style)
  }, /*#__PURE__*/React.createElement(ResourceWallViewportToolbar, {
    now: now,
    appearanceMode: appearanceMode,
    onAppearanceModeChange: setAppearanceMode,
    pseudoFullscreen: pseudoFullscreen,
    onTogglePseudoFullscreen: togglePseudoFullscreen,
    onOpenControlPanel: function onOpenControlPanel() {
      return setShowControlPanel(true);
    },
    headerBorder: headerBorder,
    headerBg: headerBg,
    clockColor: clockColor,
    mutedText: mutedText,
    toolbarBtnBorder: toolbarBtnBorder,
    toolbarBtnBg: toolbarBtnBg,
    toolbarBtnBgActive: toolbarBtnBgActive
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      minHeight: 0,
      padding: 12,
      display: 'flex',
      flexDirection: 'column',
      gap: 10
    }
  }, totalPages > 1 ? /*#__PURE__*/React.createElement("div", {
    style: {
      flexShrink: 0,
      display: 'flex',
      alignItems: 'center',
      gap: 12
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 13,
      fontWeight: 600,
      color: mutedText,
      whiteSpace: 'nowrap'
    }
  }, getText('pisell-resource-wall-page-indicator').replace('{cur}', String(currentPage + 1)).replace('{total}', String(totalPages))), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      height: 4,
      borderRadius: 2,
      overflow: 'hidden',
      background: isDark ? 'rgba(255,255,255,0.1)' : 'rgba(15,23,42,0.08)'
    }
  }, /*#__PURE__*/React.createElement("div", {
    key: "".concat(currentPage, "-").concat(countdownSec),
    className: "pisell-resource-wall-page-countdown-bar",
    style: {
      height: '100%',
      width: '100%',
      background: occupiedCardColor,
      animationDuration: "".concat(countdownSec, "s")
    }
  }))) : null, /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      minHeight: 0,
      height: '100%',
      display: 'grid',
      gap: 16,
      gridTemplateColumns: "repeat(".concat(selectedLayout.cols, ", minmax(0, 1fr))"),
      gridTemplateRows: "repeat(".concat(selectedLayout.rows, ", minmax(0, 1fr))")
    }
  }, renderCards.map(function (card) {
    return /*#__PURE__*/React.createElement(VenueWallCard, {
      key: String(card.resourceId),
      card: card,
      wallNowMs: now.getTime(),
      boardingSoonBeforeMin: boardingSoonBeforeMin,
      occupiedCardColor: occupiedCardColor,
      availableCardColor: availableCardColor,
      heroMaxWidthRatio: heroMaxWidthRatio,
      statusToneMap: statusToneMap,
      appearance: appearanceMode
    });
  }))), /*#__PURE__*/React.createElement(ResourceWallControlPanel, {
    open: showControlPanel,
    onClose: closeControlPanel,
    isDark: isDark,
    layoutPresets: layoutPresetsWithI18n,
    layoutKey: layoutKey,
    customCols: customCols,
    customRows: customRows,
    pageDurationSec: pageDurationSec,
    occupiedCardColor: occupiedCardColor,
    availableCardColor: availableCardColor,
    boardingSoonBeforeMin: boardingSoonBeforeMin,
    statusToneOverrides: statusToneOverrides,
    selectedResourceIds: wallSelectedIds,
    carouselPager: controlCarouselPager,
    heroMaxWidthRatio: heroMaxWidthRatio,
    onApply: handleControlApply
  }));

  /** 控制台打开时仍挂载 shell，避免整页 Spin 卸载弹层导致草稿丢失（全选后无法勾掉） */
  if (loading && !showControlPanel) {
    return /*#__PURE__*/React.createElement("div", {
      className: className,
      style: _objectSpread({
        flex: 1,
        minHeight: 0,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        background: pageBg
      }, style)
    }, /*#__PURE__*/React.createElement(Spin, null));
  }
  return shell;
};