const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_index = require("../../../../pro/pisellNumberSelector/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/plus/saleDetail/components/CartItems/index.tsx
const { LineItem } = _pisell_materials.ProductCard;
const STATUS_OPTIONS = [
	{
		key: "new",
		labelKey: "pisell2.sale-detail.status.new",
		color: "#91caff"
	},
	{
		key: "confirmed",
		labelKey: "pisell2.sale-detail.status.confirmed",
		color: "#b7eb8f"
	},
	{
		key: "arrived",
		labelKey: "pisell2.sale-detail.status.arrived",
		color: "#d3adf7"
	},
	{
		key: "started",
		labelKey: "pisell2.sale-detail.status.started",
		color: "#fffb8f"
	},
	{
		key: "cancelled",
		labelKey: "pisell2.sale-detail.status.cancelled",
		color: "#bfbfbf",
		danger: true
	},
	{
		key: "no_show",
		labelKey: "pisell2.sale-detail.status.no_show",
		color: "#ffa39e",
		danger: true
	},
	{
		key: "completed",
		labelKey: "pisell2.sale-detail.status.completed",
		color: "#ffd591"
	}
];
const getBookingQuantity = (item) => {
	var _ref, _ref2, _item$_extend$product, _item$_extend;
	return (_ref = (_ref2 = (_item$_extend$product = item === null || item === void 0 || (_item$_extend = item._extend) === null || _item$_extend === void 0 || (_item$_extend = _item$_extend.product) === null || _item$_extend === void 0 ? void 0 : _item$_extend.num) !== null && _item$_extend$product !== void 0 ? _item$_extend$product : item === null || item === void 0 ? void 0 : item.num) !== null && _ref2 !== void 0 ? _ref2 : item === null || item === void 0 ? void 0 : item.number) !== null && _ref !== void 0 ? _ref : 1;
};
function CartItems({ dataSource, sales, className }) {
	const [statusLoading, setStatusLoading] = (0, react.useState)(false);
	const cart = Array.isArray(dataSource) ? {
		bookings: [],
		items: dataSource
	} : dataSource || {
		bookings: [],
		items: []
	};
	const bookings = cart.bookings || [];
	const items = cart.items || [];
	const statusOptions = (0, react.useMemo)(() => STATUS_OPTIONS.map((option) => ({
		key: option.key,
		label: _pisell_utils.locales.getText(option.labelKey),
		color: option.color,
		danger: option.danger
	})), []);
	(0, react.useCallback)(function() {
		var _ref3 = require_asyncToGenerator._asyncToGenerator(function* (status) {
			const next = status.trim();
			if (!next) {
				antd.message.error(_pisell_utils.locales.getText("pisell2.sale-detail.status-empty-error"));
				return;
			}
			if (!(sales === null || sales === void 0 ? void 0 : sales.setBookingStatus)) return;
			setStatusLoading(true);
			try {
				yield sales.setBookingStatus(next);
				antd.message.success(_pisell_utils.locales.getText("pisell1.text.edit-status-success"));
			} catch (e) {
				var _e$message;
				antd.message.error(String((_e$message = e === null || e === void 0 ? void 0 : e.message) !== null && _e$message !== void 0 ? _e$message : e));
			} finally {
				setStatusLoading(false);
			}
		});
		return function(_x) {
			return _ref3.apply(this, arguments);
		};
	}(), [sales]);
	const renderQuantityAction = (item) => [{
		key: "update_number",
		text: /* @__PURE__ */ react.default.createElement(require_index.default, {
			enablePriceAdjust: true,
			min: 1,
			className: "pisell-sale-detail-cart-items__quantity-selector",
			value: getBookingQuantity(item),
			onChange: () => {}
		}),
		color: "#667085"
	}];
	return /* @__PURE__ */ react.default.createElement("section", { className: className ? `pisell-sale-detail-cart-items ${className}` : "pisell-sale-detail-cart-items" }, bookings.map((item) => {
		var _item$metadata;
		return /* @__PURE__ */ react.default.createElement(LineItem, {
			key: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.unique_identification_number) || item.booking_id,
			itemType: "booking",
			type: "a9",
			rightActions: renderQuantityAction(item),
			escapeDom: ".pisell-number-selector-popover",
			dataSource: item,
			statusOptions,
			statusLoading,
			onBookingStatusChange: void 0,
			onAction: () => {},
			onDelete: () => {},
			onNote: () => {},
			onCard: () => {},
			onPromotion: () => {},
			isShowNote: true,
			disabledEdit: true,
			isShowDelete: false,
			isShowAmountFooter: true,
			isShowImage: true,
			maxSpecsCount: 1,
			scenario: "booking2",
			onGift: () => {}
		});
	}), items.map((item) => {
		var _item$metadata2;
		return /* @__PURE__ */ react.default.createElement(LineItem, {
			key: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.unique_identification_number) || item.order_detail_id || item.product_id,
			itemType: "product",
			type: "a9",
			rightActions: renderQuantityAction(item),
			escapeDom: ".pisell-number-selector-popover",
			dataSource: item,
			onAction: () => {},
			onDelete: () => {},
			onNote: () => {},
			onLike: () => {},
			onEditProduct: () => {},
			onCard: () => {},
			onChangeResource: () => {},
			onChangeHolder: () => {},
			onAddHolder: () => {},
			isShowNote: true,
			isShowPackageNote: true,
			disabledEdit: true,
			isShowChangeResource: false,
			isShowChangeHolder: false,
			isShowDelete: false,
			isShowHolder: false,
			isShowAddHolderButton: false,
			isShowEditProduct: false,
			isShowAmountFooter: true,
			isShowImage: true,
			maxSpecsCount: 1,
			scenario: "booking2",
			onGift: () => {}
		});
	}));
}
//#endregion
exports.CartItems = CartItems;
