const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/plus/salesSdk/demo/components/CartPanel.tsx
function pickItemKey(item, index) {
	var _item$_identity$uniqu, _item$_identity;
	return (_item$_identity$uniqu = item === null || item === void 0 || (_item$_identity = item._identity) === null || _item$_identity === void 0 ? void 0 : _item$_identity.unique_identification_number) !== null && _item$_identity$uniqu !== void 0 ? _item$_identity$uniqu : `${item.product_id}-${item.product_variant_id}-${index}`;
}
const CartPanel = ({ cart, readOnly, onRemoveError, onRemoveSuccess, onEditBookingError }) => {
	const handleRemove = function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (item) {
			try {
				yield cart.removeItem(item);
				onRemoveSuccess === null || onRemoveSuccess === void 0 || onRemoveSuccess(item);
			} catch (e) {
				onRemoveError === null || onRemoveError === void 0 || onRemoveError(e);
			}
		});
		return function handleRemove(_x) {
			return _ref2.apply(this, arguments);
		};
	}();
	const handleEditBooking = function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* (item) {
			try {
				yield cart.editCartLineBooking(item);
			} catch (e) {
				console.error("[SalesSdk Demo] editCartLineBooking failed", e);
				onEditBookingError === null || onEditBookingError === void 0 || onEditBookingError(e);
			}
		});
		return function handleEditBooking(_x2) {
			return _ref3.apply(this, arguments);
		};
	}();
	const hasBooking = (item) => {
		var _item$_extend;
		return ((_item$_extend = item._extend) === null || _item$_extend === void 0 ? void 0 : _item$_extend.booking) != null;
	};
	cart.bookings.length + cart.items.length;
	return /* @__PURE__ */ react.default.createElement("section", { className: "sales-sdk-demo__panel" }, /* @__PURE__ */ react.default.createElement("div", { className: "sales-sdk-demo__section-title" }, /* @__PURE__ */ react.default.createElement("h3", null, "Cart Items"), /* @__PURE__ */ react.default.createElement("span", null, cart.items.length, " item(s)")), cart.items.length > 0 ? /* @__PURE__ */ react.default.createElement("div", { className: "sales-sdk-demo__items" }, cart.items.map((item, index) => {
		const itemKey = pickItemKey(item, index);
		return /* @__PURE__ */ react.default.createElement("article", {
			className: "sales-sdk-demo__item",
			key: itemKey
		}, /* @__PURE__ */ react.default.createElement("div", { className: "sales-sdk-demo__item-main" }, item.cover ? /* @__PURE__ */ react.default.createElement("img", {
			src: item.cover,
			alt: item.title
		}) : null, /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("h4", null, item.title || "Untitled product"), /* @__PURE__ */ react.default.createElement("p", null, "Variant: ", item.variant_title || "-", " / Qty: ", item.num), /* @__PURE__ */ react.default.createElement("p", null, "Price: ", item.selling_price || "-", " / Original:", " ", item.original_price || "-"), /* @__PURE__ */ react.default.createElement("p", null, "Schedule: ", item.start_at || "-", " - ", item.end_at || "-"), item.note ? /* @__PURE__ */ react.default.createElement("p", null, "Note: ", item.note) : null)), readOnly ? null : /* @__PURE__ */ react.default.createElement("div", { className: "sales-sdk-demo__item-actions" }, hasBooking(item) ? /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			className: "sales-sdk-demo__secondary",
			onClick: () => handleEditBooking(item)
		}, "编辑资源") : null, /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			className: "sales-sdk-demo__danger",
			onClick: () => handleRemove(item)
		}, "remove")));
	})) : /* @__PURE__ */ react.default.createElement("div", { className: "sales-sdk-demo__empty" }, "No cart item loaded."));
};
//#endregion
exports.CartPanel = CartPanel;
