const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let decimal_js = require("decimal.js");
decimal_js = require_runtime.__toESM(decimal_js);
//#region src/components/Sales/Checkout/utils.ts
/**
* @title: 预约商品信息
* @description:
* @param {any} data
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-02-19 09:26
*/
const formatBookings = (list) => {
	let bookings = [];
	bookings = list.map((item) => {
		var _product$product_bund;
		const newOriginData = require_objectSpread2._objectSpread2({}, item._originData || {});
		const product = (newOriginData === null || newOriginData === void 0 ? void 0 : newOriginData.product) || {};
		const discount_list = product === null || product === void 0 ? void 0 : product.discount_list;
		const main_product_discount = discount_list === null || discount_list === void 0 ? void 0 : discount_list.filter((d) => {
			var _d$metadata;
			return !((_d$metadata = d.metadata) === null || _d$metadata === void 0 ? void 0 : _d$metadata.custom_product_bundle_map_id);
		});
		if (main_product_discount === null || main_product_discount === void 0 ? void 0 : main_product_discount.length) product.metadata = { product_discount_difference: handleProductDiscountDifference([main_product_discount]) };
		console.log("main_product_discount", main_product_discount);
		if (product === null || product === void 0 || (_product$product_bund = product.product_bundle) === null || _product$product_bund === void 0 ? void 0 : _product$product_bund.length) {
			var _product$product_bund2, _product$product_bund3;
			product.product_bundle = product === null || product === void 0 || (_product$product_bund2 = product.product_bundle) === null || _product$product_bund2 === void 0 || (_product$product_bund3 = _product$product_bund2.map) === null || _product$product_bund3 === void 0 ? void 0 : _product$product_bund3.call(_product$product_bund2, (v) => {
				var _item$selectedBundle, _item$selectedBundle$;
				const bundle_item_discount = [];
				item === null || item === void 0 || (_item$selectedBundle = item.selectedBundle) === null || _item$selectedBundle === void 0 || (_item$selectedBundle$ = _item$selectedBundle.forEach) === null || _item$selectedBundle$ === void 0 || _item$selectedBundle$.call(_item$selectedBundle, (s) => {
					if ((s === null || s === void 0 ? void 0 : s.id) === (v === null || v === void 0 ? void 0 : v.bundle_id) && (s === null || s === void 0 ? void 0 : s.group_id) === (v === null || v === void 0 ? void 0 : v.bundle_group_id) && (s === null || s === void 0 ? void 0 : s._bundle_product_id) === (v === null || v === void 0 ? void 0 : v.bundle_product_id)) bundle_item_discount.push(...(s === null || s === void 0 ? void 0 : s.discount_list) || []);
				});
				console.log("bundle_item_discount", bundle_item_discount);
				const newBundleItem = require_objectSpread2._objectSpread2({}, v || {});
				if (bundle_item_discount === null || bundle_item_discount === void 0 ? void 0 : bundle_item_discount.length) {
					var _bundle_item_discount;
					newBundleItem.metadata = {
						custom_product_bundle_map_id: bundle_item_discount === null || bundle_item_discount === void 0 || (_bundle_item_discount = bundle_item_discount[0]) === null || _bundle_item_discount === void 0 || (_bundle_item_discount = _bundle_item_discount.metadata) === null || _bundle_item_discount === void 0 ? void 0 : _bundle_item_discount.custom_product_bundle_map_id,
						product_discount_difference: handleProductDiscountDifference(bundle_item_discount)
					};
				}
				return newBundleItem;
			});
		}
		newOriginData.product = product;
		return newOriginData;
	});
	console.log("bookings>>>>", bookings);
	return bookings;
};
const handleProductDiscountDifference = (discount_list) => {
	return (discount_list === null || discount_list === void 0 ? void 0 : discount_list.reduce((pre, cur) => {
		var _cur$metadata;
		return pre.plus(new decimal_js.default((cur === null || cur === void 0 || (_cur$metadata = cur.metadata) === null || _cur$metadata === void 0 ? void 0 : _cur$metadata.product_discount_difference) || 0));
	}, new decimal_js.default(0))).toNumber();
};
/**
* @title: 格式化下单接口数据
* @description:
* @param {any} state saledModel数据源
* @param {boolean} excludeDisabled 是否需要排除购物车中失效商品
* @Author: xiangfeng.xue
* @Date: 2025-01-21 17:57
*/
const formatValues = (params) => {
	const { state, otherValue, platform, excludeDisabled, extra } = params;
	let values = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
		type: "event_booking_v2",
		platform: platform === "pc" ? "PC" : "H5",
		sales_channel: "my_pisel",
		order_sales_channel: "online_store",
		bookings: [],
		shop_note: "",
		schedule_date: ""
	}, extra || {}), otherValue || {});
	console.log("values", values);
	let data = [];
	if (excludeDisabled) {
		var _state$cartData$cartI, _state$cartData$cartI2;
		data = (_state$cartData$cartI = state.cartData.cartItems) === null || _state$cartData$cartI === void 0 || (_state$cartData$cartI2 = _state$cartData$cartI.filter) === null || _state$cartData$cartI2 === void 0 ? void 0 : _state$cartData$cartI2.call(_state$cartData$cartI, (v) => v.disabled !== true);
	} else data = state.cartData.cartItems;
	values.is_deposit = data.find((v) => v.deposit) ? 1 : 0;
	values.bookings = formatBookings(data);
	return values;
};
/**
* @title: 获取拉开表单弹窗参数
* @param state
*/
const getFormParams = (state) => {
	var _state$cartData;
	return {
		product_id: ((state === null || state === void 0 || (_state$cartData = state.cartData) === null || _state$cartData === void 0 ? void 0 : _state$cartData.cartItems) || []).map((item) => {
			var _item$_originData;
			return (_item$_originData = item._originData) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.product) === null || _item$_originData === void 0 ? void 0 : _item$_originData.product_id;
		}),
		appointment_type: "event_booking_v2"
	};
};
//#endregion
exports.formatValues = formatValues;
exports.getFormParams = getFormParams;
