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); }
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, { useMemo, useState, useEffect } from 'react';
import { Spin } from 'antd';
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext";
import { VenueWallCard } from "./VenueWallCard";

/** 与 {@link RecordBoardResourceWallProps.filterFieldKey} 默认一致 */
export var DEFAULT_RESOURCE_WALL_FILTER_FIELD_KEY = 'resource_wall_resource_ids';
var LAYOUT_PRESETS = [{
  key: '1x1',
  cols: 1,
  rows: 1
}, {
  key: '1x2',
  cols: 2,
  rows: 1
}, {
  key: '2x3',
  cols: 3,
  rows: 2
}, {
  key: '3x2',
  cols: 2,
  rows: 3
}, {
  key: '3x3',
  cols: 3,
  rows: 3
}];

/**
 * 大屏资源墙主视口：卡片数据来自 props；可见资源 id 来自
 * `searchParams.filter.values[filterFieldKey]` 与 `cards[].resourceId` 交集。
 */
export var PisellRecordBoardResourceWallView = function PisellRecordBoardResourceWallView(props) {
  var _props$filterFieldKey, _ctx$searchParams;
  var className = props.className,
    style = props.style,
    loading = props.loading,
    cardsProp = props.cards;
  var ctx = useRecordBoardContext();
  var filterKey = (_props$filterFieldKey = props.filterFieldKey) !== null && _props$filterFieldKey !== void 0 ? _props$filterFieldKey : DEFAULT_RESOURCE_WALL_FILTER_FIELD_KEY;
  var selectedRaw = (_ctx$searchParams = ctx.searchParams) === null || _ctx$searchParams === void 0 || (_ctx$searchParams = _ctx$searchParams.filter) === null || _ctx$searchParams === void 0 || (_ctx$searchParams = _ctx$searchParams.values) === null || _ctx$searchParams === void 0 ? void 0 : _ctx$searchParams[filterKey];
  var selectedIds = useMemo(function () {
    if (!Array.isArray(selectedRaw)) return null;
    return selectedRaw.map(function (x) {
      return String(x);
    });
  }, [selectedRaw]);
  var cards = cardsProp !== null && cardsProp !== void 0 ? cardsProp : [];
  var visibleCards = useMemo(function () {
    if (selectedIds == null || selectedIds.length === 0) {
      return cards;
    }
    var set = new Set(selectedIds);
    return cards.filter(function (c) {
      return set.has(String(c.resourceId));
    });
  }, [cards, selectedIds]);
  var _useState = useState(function () {
      return new Date();
    }),
    _useState2 = _slicedToArray(_useState, 2),
    now = _useState2[0],
    setNow = _useState2[1];
  /** 墙钟与「时:分」展示对齐：秒级 tick，分钟变化时无需再等整段长间隔 */
  useEffect(function () {
    var id = window.setInterval(function () {
      return setNow(new Date());
    }, 1000);
    return function () {
      return window.clearInterval(id);
    };
  }, []);
  var selectedLayout = LAYOUT_PRESETS[2];
  var shell = /*#__PURE__*/React.createElement("div", {
    className: className,
    style: _objectSpread({
      flex: 1,
      minHeight: 0,
      display: 'flex',
      flexDirection: 'column',
      overflow: 'hidden',
      background: '#f5f7fb',
      color: '#0f172a'
    }, style)
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      flexShrink: 0,
      borderBottom: '1px solid #e2e8f0',
      padding: '16px 24px',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between',
      gap: 16,
      background: '#fff'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      fontSize: 22,
      fontWeight: 600,
      letterSpacing: '-0.02em'
    }
  }, now.toLocaleTimeString([], {
    hour: '2-digit',
    minute: '2-digit',
    hour12: false
  }), ' ', "\xB7", ' ', now.toLocaleDateString('en-GB', {
    day: '2-digit',
    month: 'short',
    year: 'numeric'
  }))), /*#__PURE__*/React.createElement("div", {
    style: {
      flex: 1,
      minHeight: 0,
      padding: 12
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      height: '100%',
      display: 'grid',
      gap: 16,
      gridTemplateColumns: "repeat(".concat(selectedLayout.cols, ", minmax(0, 1fr))"),
      gridTemplateRows: "repeat(".concat(selectedLayout.rows, ", minmax(0, 1fr))")
    }
  }, visibleCards.slice(0, selectedLayout.cols * selectedLayout.rows).map(function (card, index) {
    return /*#__PURE__*/React.createElement(VenueWallCard, {
      key: "".concat(card.resourceId, "-").concat(index),
      card: card
    });
  }))));
  if (loading) {
    return /*#__PURE__*/React.createElement("div", {
      className: className,
      style: _objectSpread({
        flex: 1,
        minHeight: 0,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        background: '#f5f7fb'
      }, style)
    }, /*#__PURE__*/React.createElement(Spin, null));
  }
  return shell;
};