const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_mapRowToFloorRoomCardData = require("../../floorRoomCard/mapRowToFloorRoomCardData.js");
const require_FloorRoomCardFromData = require("../../floorRoomCard/FloorRoomCardFromData.js");
const require_bookingProductToProductCard = require("./bookingProductToProductCard.js");
const require_bookingDetailHostActions = require("./bookingDetailHostActions.js");
const require_bookingDetailModalConstants = require("./bookingDetailModalConstants.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_materials = require("@pisell/materials");
let _ant_design_icons = require("@ant-design/icons");
//#region src/plus/pisellReservation/components/bookingDetailModal/BookingDetailUnit.tsx
const BASE_ACTION_ITEMS = [
	{
		key: "action-edit",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.EditOutlined, null)
	},
	{
		key: "action-cart",
		icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-coins-hand" })
	},
	{
		key: "action-print",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PrinterOutlined, null)
	},
	{
		key: "action-list",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.UnorderedListOutlined, null)
	}
];
function buildActionItems(status, bookingRaw) {
	const statusAction = require_bookingDetailHostActions.isCompletedBookingRaw(bookingRaw) ? null : status === "occupied" ? {
		key: "action-complete",
		icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-check-square-broken" })
	} : {
		key: "action-start",
		icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-send-01" })
	};
	return [
		BASE_ACTION_ITEMS[1],
		BASE_ACTION_ITEMS[0],
		{
			key: "action-form",
			icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-edit-05" })
		},
		...statusAction ? [statusAction] : [],
		...BASE_ACTION_ITEMS.slice(2),
		{
			key: "action-close",
			icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.CloseCircleOutlined, null)
		}
	];
}
/**
* 单条 booking 单元：RoomCard + 操作栏 + 商品列表。
*/
function BookingDetailUnit(props) {
	const { bookingRaw, tableRow, isCancellingOrder, isCompletingBooking, getApp, onActionCellClick } = props;
	const data = (0, react.useMemo)(() => require_mapRowToFloorRoomCardData.buildDetailModalRoomCardData(bookingRaw, tableRow !== null && tableRow !== void 0 ? tableRow : null), [bookingRaw, tableRow]);
	const headerOverride = (0, react.useMemo)(() => require_mapRowToFloorRoomCardData.resolveBookingIdForHeader(bookingRaw), [bookingRaw]);
	const statusTag = (0, react.useMemo)(() => require_bookingDetailHostActions.resolveAppointmentStatusTag(bookingRaw), [bookingRaw]);
	const isCompleted = (0, react.useMemo)(() => require_bookingDetailHostActions.isCompletedBookingRaw(bookingRaw), [bookingRaw]);
	const items = (0, react.useMemo)(() => buildActionItems(data === null || data === void 0 ? void 0 : data.status, bookingRaw), [data === null || data === void 0 ? void 0 : data.status, bookingRaw]);
	const productSources = (0, react.useMemo)(() => require_bookingDetailHostActions.parseBookingProducts(bookingRaw).map((line, i) => require_bookingProductToProductCard.bookingProductLineToProductCardData(line, i, { app: getApp === null || getApp === void 0 ? void 0 : getApp() })), [bookingRaw, getApp]);
	const symbol = (0, react.useMemo)(() => require_bookingDetailHostActions.orderCurrencySymbol(bookingRaw.order), [bookingRaw.order]);
	return /* @__PURE__ */ react.default.createElement("div", { className: `${require_bookingDetailModalConstants.PREFIX}__booking-card` }, /* @__PURE__ */ react.default.createElement("div", {
		className: `${require_bookingDetailModalConstants.PREFIX}__room-card-slot pisell-res-floor-room-card`,
		onMouseDown: require_bookingDetailModalConstants.stopUiClick,
		onClick: require_bookingDetailModalConstants.stopUiClick
	}, /* @__PURE__ */ react.default.createElement(require_FloorRoomCardFromData.FloorRoomCardFromData, {
		data,
		shellShape: "rect",
		hideHeader: true,
		hideHeaderCapacity: true,
		headerMainFieldOverride: headerOverride,
		bodyStatusTag: statusTag
	})), /* @__PURE__ */ react.default.createElement("div", {
		className: isCompleted ? `${require_bookingDetailModalConstants.PREFIX}__action-grid ${require_bookingDetailModalConstants.PREFIX}__action-grid--cols-3` : `${require_bookingDetailModalConstants.PREFIX}__action-grid`,
		role: "group",
		"aria-label": require_bookingDetailModalConstants.t("action-grid-aria")
	}, items.map(({ key: ak, icon }) => {
		const tintClass = require_bookingDetailModalConstants.bookingDetailActionCellTintClass(ak);
		return /* @__PURE__ */ react.default.createElement("button", {
			key: ak,
			type: "button",
			className: tintClass ? `${require_bookingDetailModalConstants.PREFIX}__action-cell ${tintClass}` : `${require_bookingDetailModalConstants.PREFIX}__action-cell`,
			disabled: ak === "action-close" && isCancellingOrder || ak === "action-complete" && isCompletingBooking,
			onClick: (ev) => onActionCellClick(bookingRaw, ak, ev)
		}, react.default.isValidElement(icon) ? react.default.cloneElement(icon, {
			className: `${require_bookingDetailModalConstants.PREFIX}__action-icon`,
			"aria-hidden": true
		}) : null, /* @__PURE__ */ react.default.createElement("span", { className: `${require_bookingDetailModalConstants.PREFIX}__action-label` }, require_bookingDetailModalConstants.t(ak)));
	})), /* @__PURE__ */ react.default.createElement("div", { className: `${require_bookingDetailModalConstants.PREFIX}__products-section` }, /* @__PURE__ */ react.default.createElement("div", { className: `${require_bookingDetailModalConstants.PREFIX}__products-list` }, productSources.length === 0 ? /* @__PURE__ */ react.default.createElement("div", { className: `${require_bookingDetailModalConstants.PREFIX}__products-empty` }, require_bookingDetailModalConstants.t("empty-items")) : productSources.map((ds) => /* @__PURE__ */ react.default.createElement("div", {
		key: String(ds._id),
		className: `${require_bookingDetailModalConstants.PREFIX}__product-card-slot`
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.ProductCard, {
		dataSource: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, ds), {}, { symbol }),
		isShowImage: false,
		isShowHolder: false,
		isShowNote: false,
		isShowDelete: false,
		isShowPackageNote: false,
		isShowEditProduct: false
	}))))));
}
//#endregion
exports.BookingDetailUnit = BookingDetailUnit;
