require("../../../../_virtual/_rolldown/runtime.js");
const require_utils = require("./utils.js");
let react = require("react");
//#region src/pro/skuDetailModal/components/weighing/useWeighing.ts
/**
* 推导当前选中 variant（或商品根级）的称重状态及计价所需配置。
*
* 价格来源规则（对齐 getSelectedUnitPrice）：
* - 有 variant：取 variant.base_price ?? variant.original_price
* - 无 variant：取 productData.base_price ?? productData._extend?.price
*/
const useWeighing = ({ productData, skuValue }) => {
	return (0, react.useMemo)(() => {
		var _ref, _source$base_price, _ref2, _pd$base_price, _pd$_extend;
		const pd = productData;
		const variantId = skuValue === null || skuValue === void 0 ? void 0 : skuValue.product_variant_id;
		if (Array.isArray(pd === null || pd === void 0 ? void 0 : pd.variant) && pd.variant.length > 0 && !variantId) return { isWeighingProduct: false };
		const source = require_utils.resolveWeighingSource(productData, variantId);
		if (!(Number((source === null || source === void 0 ? void 0 : source.open_sold_weight) || 0) === 1)) return { isWeighingProduct: false };
		const basePrice = variantId ? Number((_ref = (_source$base_price = source === null || source === void 0 ? void 0 : source.base_price) !== null && _source$base_price !== void 0 ? _source$base_price : source === null || source === void 0 ? void 0 : source.original_price) !== null && _ref !== void 0 ? _ref : 0) : Number((_ref2 = (_pd$base_price = pd === null || pd === void 0 ? void 0 : pd.base_price) !== null && _pd$base_price !== void 0 ? _pd$base_price : pd === null || pd === void 0 || (_pd$_extend = pd._extend) === null || _pd$_extend === void 0 ? void 0 : _pd$_extend.price) !== null && _ref2 !== void 0 ? _ref2 : 0);
		return {
			isWeighingProduct: true,
			scalePriceProduct: {
				id: productData.id,
				variant_id: skuValue.product_variant_id,
				price: basePrice,
				unit: source === null || source === void 0 ? void 0 : source.unit,
				unit_value: Number(source === null || source === void 0 ? void 0 : source.unit_value) || 1
			}
		};
	}, [productData, skuValue === null || skuValue === void 0 ? void 0 : skuValue.product_variant_id]);
};
//#endregion
exports.useWeighing = useWeighing;
