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 from 'react';
import { TeamOutlined } from '@ant-design/icons';
import { formatDataRecordOptionLabel } from "./floorMapDataRecordLabel";
import { parseNestedPathSegments } from "./floorMapResourcePickerTypes";

/** @deprecated 使用 PisellCardPickerItem */

/** 平面图资源选择卡片 meta：在通用 meta 基础上确保 id 存在，便于搜索文本拼接 */

function pickField(record, key) {
  var raw = record[key];
  if (raw == null) return null;
  var t = String(raw).trim();
  return t ? t : null;
}

/** 人数/容量：无值或为 0 时不展示 */
export function resolveResourcePickerCapacity(record) {
  var _pickField;
  var raw = (_pickField = pickField(record, 'capacityLabel')) !== null && _pickField !== void 0 ? _pickField : pickField(record, 'capacity');
  if (!raw) return undefined;
  var num = Number(raw);
  if (!Number.isNaN(num) && num <= 0) return undefined;
  return raw;
}
function resolveReservationAreaRaw(record) {
  return pickField(record, 'area');
}

/**
 * 预约桌位：从 `area` 解析路径，最多 3 段。
 * 当前资源多为单段（如 `party_room1`）；将来 `广东/中山/三乡` 会自动出现二、三级筛选行。
 */
export function getFloorMapResourcePickerCategoryPath(record) {
  return parseNestedPathSegments(resolveReservationAreaRaw(record), 3);
}

/** 平面图 / 预约：area 最多三级；仅展示 chip，不显示行左侧「区域」等标签 */
export function getFloorMapCardPickerCategoryConfig() {
  return {
    mode: 'nested',
    levels: [{}, {}, {}],
    getCategoryPath: getFloorMapResourcePickerCategoryPath
  };
}

/**
 * 把 capacity 字符串包装成「人数图标 + 数值」badge。
 * 抽出来便于业务侧组合（如再追加 status badge 等）。
 */
export function buildResourceCapacityBadge(capacity) {
  if (!capacity) return null;
  return {
    text: capacity,
    icon: /*#__PURE__*/React.createElement(TeamOutlined, {
      'aria-hidden': true
    })
  };
}

/**
 * 小卡片主标题 + 标签（人数等；区域已在筛选区展示，副文案不再重复 area）。
 */
export function getFloorMapResourcePickerCardMeta(record) {
  var _record$id;
  var title = formatDataRecordOptionLabel(record);
  var idStr = String((_record$id = record.id) !== null && _record$id !== void 0 ? _record$id : '').trim();
  var capacity = resolveResourcePickerCapacity(record);
  var capacityBadge = buildResourceCapacityBadge(capacity);
  return {
    id: idStr,
    title: title,
    subtitles: [],
    badges: capacityBadge ? [capacityBadge] : []
  };
}
export function floorMapResourcePickerRecordSearchText(record) {
  var _meta$badges;
  var meta = getFloorMapResourcePickerCardMeta(record);
  var areaRaw = resolveReservationAreaRaw(record);
  var badgeTexts = ((_meta$badges = meta.badges) !== null && _meta$badges !== void 0 ? _meta$badges : []).map(function (b) {
    return b.text;
  });
  return [meta.title, areaRaw].concat(_toConsumableArray(badgeTexts), _toConsumableArray(meta.subtitles), [meta.id]).filter(Boolean).join(' ').toLowerCase();
}