const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_floorRoomCardUtils = require("../floorRoomCard/floorRoomCardUtils.js");
const require_mapRowToFloorRoomCardData = require("../floorRoomCard/mapRowToFloorRoomCardData.js");
const require_ReservationFloorRoomCard = require("../floorRoomCard/ReservationFloorRoomCard.js");
const require_reservationMock = require("./reservationMock.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./ReservationCards.less");
//#region src/plus/pisellReservation/floorMap/reservationCards.tsx
const I18N_BOUND = "pisell-reservation.room-kind-bound";
const I18N_CARD_HINT_SELECT_ROW = "pisell-reservation.card-placeholder.hint-select-row";
const I18N_CARD_HINT_BIND_DATASOURCE = "pisell-reservation.card-placeholder.hint-bind-datasource";
const I18N_CARD_HINT_NEW_SLOT = "pisell-reservation.card-placeholder.hint-new-slot";
const I18N_CARD_HINT_ROW_NOT_FOUND = "pisell-reservation.card-placeholder.hint-row-not-found";
function findReservationRow(item, dataSources) {
	return (0, _pisell_materials.findFloorMapRowByDataBinding)(item, dataSources);
}
function getReservationPlaceholderCopy(item, dataSources) {
	const el = item._sceneElement;
	const kindLabel = _pisell_utils.locales.getText(I18N_BOUND);
	const title = ((el === null || el === void 0 ? void 0 : el.name) != null ? String(el.name).trim() : "") || kindLabel;
	const reason = (0, _pisell_materials.getFloorMapBindingPlaceholderReason)(item, dataSources);
	let hint;
	switch (reason) {
		case "missing_data_source_key":
			hint = _pisell_utils.locales.getText(I18N_CARD_HINT_BIND_DATASOURCE);
			break;
		case "missing_record_id":
			hint = _pisell_utils.locales.getText(I18N_CARD_HINT_SELECT_ROW);
			break;
		case "new_unsaved_slot":
			hint = _pisell_utils.locales.getText(I18N_CARD_HINT_NEW_SLOT);
			break;
		default: hint = _pisell_utils.locales.getText(I18N_CARD_HINT_ROW_NOT_FOUND);
	}
	const shape = item.elementKind === "reservationBoundRoundTable" || item.shape === "circle" ? "circle" : "rect";
	return {
		title,
		hint,
		shape
	};
}
function ReservationNoDataPlaceholder(props) {
	const { title, hint, shape } = props;
	return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-reservation-card-placeholder", shape === "circle" && "pisell-reservation-card-placeholder--circle") }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-card-placeholder-title" }, title), hint ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-card-placeholder-hint" }, hint) : null);
}
function boundTableCardShape(item) {
	return item.elementKind === "reservationBoundRoundTable" || item.shape === "circle" ? "circle" : "rect";
}
function renderReservationBoundRoomCardInner(item, dataSources, options) {
	var _item$_sceneElement, _row$completeBookingC;
	const row = findReservationRow(item, dataSources);
	const cardShape = boundTableCardShape(item);
	if (!row) {
		const ph = getReservationPlaceholderCopy(item, dataSources);
		return /* @__PURE__ */ react.default.createElement(ReservationNoDataPlaceholder, {
			title: ph.title,
			hint: ph.hint,
			shape: ph.shape
		});
	}
	/**
	* 「按业务字段算出来的房间标题」与历史一致：先 main_field、再 code、最后 sceneName 兜底。
	* 不动 displayRoomTitleFromRow 本身，避免下游（bookingDetailModal 等）被联动改坏。
	*/
	const recordTitle = require_floorRoomCardUtils.displayRoomTitleFromRow(row, ((_item$_sceneElement = item._sceneElement) === null || _item$_sceneElement === void 0 ? void 0 : _item$_sceneElement.name) != null ? String(item._sceneElement.name).trim() : void 0);
	const data = require_mapRowToFloorRoomCardData.mapPisellReservationRowToFloorRoomCardData(row, (0, _pisell_materials.resolveSceneElementDisplayTitle)({
		sceneElement: item._sceneElement,
		recordTitle,
		fallback: row.code || _pisell_utils.locales.getText(I18N_BOUND)
	}));
	/**
	* 资源卡标题旁拼「接口返回的订单计数」：`资源名 (N/M)`。
	* - N：`row.completeBookingCount`（已完成数），缺失按 0 展示；
	* - M：`row.bookingCount`（总数），来自 `salesEmbeddedResourceListToTableRows`
	*   从 `sales.getResourceBookingList` 资源行顶层 `bookingCount`；
	* - 仅在 `M > 0` 时整体渲染，避免空态卡出现 `(0/0)`；
	* - 不再用 `data.bookings.length` 自行换算（语义上「订单数」可能 ≠ 平面图当前
	*   时刻可见的 bookings 数，例如已结账 / 未付款也算单但不渲染卡）；
	* - **写法上不拼到 `main_field` 末尾**：标题字符串在大卡 header 里会随
	*   宽度 ellipsis，先拼会导致长资源名（如 `小包 01（10 人）`）把 `(N/M)`
	*   一起裁掉；改为通过结构化字段 `data.bookingCount` /
	*   `data.completeBookingCount` 透传，由 {@link RoomCardHeaderView}
	*   渲染为独立 `flex-shrink: 0` 节点，保证计数常驻可见；
	* - 入口集中：所有 floor 资源卡（方桌 / 圆桌 / partyBench / barSeat 以及
	*   通用 `bound` kind）都从 {@link renderReservationBoundRoomCardInner} 走；
	* - 不回写 row 或 sceneElement，`displayRoomTitleFromRow` / detailModal
	*   等用到的原始标题不受影响。
	*/
	const dataWithCount = row.bookingCount != null && row.bookingCount > 0 ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, data), {}, {
		bookingCount: row.bookingCount,
		completeBookingCount: (_row$completeBookingC = row.completeBookingCount) !== null && _row$completeBookingC !== void 0 ? _row$completeBookingC : 0
	}) : data;
	const layoutH = item.height != null && Number.isFinite(item.height) && item.height > 0 ? item.height : item.width;
	return /* @__PURE__ */ react.default.createElement(require_ReservationFloorRoomCard.ReservationFloorRoomCard, {
		data: dataWithCount,
		shellShape: cardShape,
		hideHeaderCapacity: true,
		elementLayoutHeightPx: layoutH != null && Number.isFinite(layoutH) && layoutH > 0 && cardShape === "circle" ? layoutH : void 0,
		viewportScale: options === null || options === void 0 ? void 0 : options.viewportScale
	});
}
function getReservationRenderItemByKind(dataSources) {
	const bound = (item, _index, options) => renderReservationBoundRoomCardInner(item, dataSources, options);
	return {
		[_pisell_materials.FLOOR_MAP_IMAGE_ELEMENT_KIND]: (item, _index, _options) => (0, _pisell_materials.renderFloorMapFallbackPlaceholder)(item),
		[_pisell_materials.FLOOR_MAP_BUILTIN_SHAPE_ELEMENT_KIND]: (item, _index, _options) => (0, _pisell_materials.renderFloorMapFallbackPlaceholder)(item),
		[require_reservationMock.RESERVATION_BOUND_TABLE_ELEMENT_KIND]: bound,
		[require_reservationMock.RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND]: bound,
		reservationTable: bound,
		reservationPartyBench: bound,
		reservationBarSeat: bound
	};
}
//#endregion
exports.findReservationRow = findReservationRow;
exports.getReservationRenderItemByKind = getReservationRenderItemByKind;
