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