import { displayRoomTitleFromRow } from "../floorRoomCard/floorRoomCardUtils.js";
import { mapPisellReservationRowToFloorRoomCardData } from "../floorRoomCard/mapRowToFloorRoomCardData.js";
import { ReservationFloorRoomCard } from "../floorRoomCard/ReservationFloorRoomCard.js";
import { RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND, RESERVATION_BOUND_TABLE_ELEMENT_KIND } from "./reservationMock.js";
import React from "react";
import { locales } from "@pisell/utils";
import { FLOOR_MAP_IMAGE_ELEMENT_KIND, findFloorMapRowByDataBinding, getFloorMapBindingPlaceholderReason, renderFloorMapFallbackPlaceholder } from "@pisell/materials";
import classNames from "classnames";
import "./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 findFloorMapRowByDataBinding(item, dataSources);
}
function getReservationPlaceholderCopy(item, dataSources) {
	const el = item._sceneElement;
	const kindLabel = locales.getText(I18N_BOUND);
	const title = ((el === null || el === void 0 ? void 0 : el.name) != null ? String(el.name).trim() : "") || kindLabel;
	const reason = getFloorMapBindingPlaceholderReason(item, dataSources);
	let hint;
	switch (reason) {
		case "missing_data_source_key":
			hint = locales.getText(I18N_CARD_HINT_BIND_DATASOURCE);
			break;
		case "missing_record_id":
			hint = locales.getText(I18N_CARD_HINT_SELECT_ROW);
			break;
		case "new_unsaved_slot":
			hint = locales.getText(I18N_CARD_HINT_NEW_SLOT);
			break;
		default: hint = 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.createElement("div", { className: classNames("pisell-reservation-card-placeholder", shape === "circle" && "pisell-reservation-card-placeholder--circle") }, /* @__PURE__ */ React.createElement("div", { className: "pisell-reservation-card-placeholder-title" }, title), hint ? /* @__PURE__ */ React.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) {
	var _item$_sceneElement;
	const row = findReservationRow(item, dataSources);
	const cardShape = boundTableCardShape(item);
	if (!row) {
		const ph = getReservationPlaceholderCopy(item, dataSources);
		return /* @__PURE__ */ React.createElement(ReservationNoDataPlaceholder, {
			title: ph.title,
			hint: ph.hint,
			shape: ph.shape
		});
	}
	const data = mapPisellReservationRowToFloorRoomCardData(row, displayRoomTitleFromRow(row, ((_item$_sceneElement = item._sceneElement) === null || _item$_sceneElement === void 0 ? void 0 : _item$_sceneElement.name) != null ? String(item._sceneElement.name).trim() : void 0) || row.code || locales.getText(I18N_BOUND));
	const layoutH = item.height != null && Number.isFinite(item.height) && item.height > 0 ? item.height : item.width;
	return /* @__PURE__ */ React.createElement(ReservationFloorRoomCard, {
		data,
		shellShape: cardShape,
		elementLayoutHeightPx: layoutH != null && Number.isFinite(layoutH) && layoutH > 0 && cardShape === "circle" ? layoutH : void 0
	});
}
function getReservationRenderItemByKind(dataSources) {
	const bound = (item, _index, _options) => renderReservationBoundRoomCardInner(item, dataSources);
	return {
		[FLOOR_MAP_IMAGE_ELEMENT_KIND]: (item, _index, _options) => renderFloorMapFallbackPlaceholder(item),
		[RESERVATION_BOUND_TABLE_ELEMENT_KIND]: bound,
		[RESERVATION_BOUND_ROUND_TABLE_ELEMENT_KIND]: bound,
		reservationTable: bound,
		reservationPartyBench: bound,
		reservationBarSeat: bound
	};
}
//#endregion
export { findReservationRow, getReservationRenderItemByKind };
