import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { getProductDetail } from "../../components/booking/info/service/serve.js";
import { filterVariantGroupByVariants } from "../../components/shoppingCart/utils.js";
import { Context } from "../../components/booking/info/model.js";
import useEngineContext from "../../hooks/useEngineContext.js";
import CompensatedPisellContainer from "../compensatedPisellContainer/index.js";
import withResponsive from "../../responsive/withResponsive.js";
import noteModal_default from "../../plus/noteModal/index.js";
import DiscountKeyboard from "../priceKeyboard/components/discountKeyboard/index.js";
import useLogger from "../../hooks/useLogger.js";
import NumericStepper from "../NumericStepper/index.js";
import stock_default from "../../shared/locales/stock.js";
import SKUOptionsSelection from "../../plus/skuOptionsSelection/index.js";
import { formatSelectedSkuItems, formatSelectedSkuMessage, getStockValidationResult, setHiddenStockAlertForToday } from "./utils.js";
import locales_default from "./locales.js";
import useToast$1 from "../../hooks/useToast.js";
import { getWeighedUnitPrice, isWeighingProduct } from "./components/weighing/utils.js";
import Weighing from "./components/weighing/index.js";
import { useWeighing } from "./components/weighing/useWeighing.js";
import React, { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
import { locales } from "@pisell/utils";
import Decimal from "decimal.js";
import { cloneDeep } from "lodash";
import { Button, Checkbox, Iconfont, PisellModal, PisellProcedure } from "@pisell/materials";
import classNames from "classnames";
import Delete_wght300_24px from "@pisell/icon/es/Delete_wght300_24px";
import "./index.less";
//#region src/pro/skuDetailModal/index.tsx
const DeleteIcon = Delete_wght300_24px;
const PisellProcedureComponent = PisellProcedure;
const getBodyScaleY = () => {
	if (typeof window === "undefined" || typeof document === "undefined") return 1;
	const transform = window.getComputedStyle(document.body).transform;
	if (!transform || transform === "none") return 1;
	const matrix = new DOMMatrixReadOnly(transform);
	return Math.sqrt(matrix.c * matrix.c + matrix.d * matrix.d) || 1;
};
const PcActionButtons = ({ isCreateMode, isShowNote, confirmLabel, onCancel, onRemove, onManualPriceChange, onOpenNote, onConfirm }) => {
	const auxiliaryActions = [isShowNote ? /* @__PURE__ */ React.createElement(Button, {
		key: "note",
		type: "default",
		size: "large",
		className: "sku-detail-side-actions-btn",
		onClick: onOpenNote
	}, locales.getText("pisell2.text.sku.detail.modal.btn.add.note")) : null, /* @__PURE__ */ React.createElement(Button, {
		key: "manual-price",
		type: "default",
		size: "large",
		onClick: onManualPriceChange,
		className: "sku-detail-side-actions-btn sku-detail-side-actions-price-btn"
	}, /* @__PURE__ */ React.createElement("span", { className: "sku-detail-content-footer-price-btn-text" }, locales.getText("pisell2.text.sku.detail.modal.btn.manual.price.change")))].filter(Boolean);
	return /* @__PURE__ */ React.createElement("div", { className: "sku-detail-side-actions" }, auxiliaryActions.length > 0 && /* @__PURE__ */ React.createElement("div", { className: "sku-detail-side-actions-list" }, auxiliaryActions), /* @__PURE__ */ React.createElement("div", { className: "sku-detail-side-actions-primary" }, isCreateMode ? /* @__PURE__ */ React.createElement(Button, {
		type: "default",
		size: "large",
		className: "sku-detail-side-actions-btn",
		onClick: onCancel
	}, locales.getText("pisell2.text.cancel") || "Cancel") : /* @__PURE__ */ React.createElement(Button, {
		type: "primary",
		danger: true,
		size: "large",
		icon: /* @__PURE__ */ React.createElement(DeleteIcon, null),
		className: "sku-detail-side-actions-btn",
		onClick: onRemove
	}, locales.getText("pisell2.text.sku.detail.modal.btn.remove")), /* @__PURE__ */ React.createElement(Button, {
		type: "primary",
		size: "large",
		onClick: onConfirm,
		className: "sku-detail-side-actions-btn sku-detail-side-actions-confirm-btn"
	}, /* @__PURE__ */ React.createElement("span", { className: "sku-detail-content-footer-confirm-btn-text" }, confirmLabel))));
};
const SkuDetailModal = ({ onConfirm, onRemove, onClose, variant }, ref) => {
	var _context$appHelper, _context$engine, _context$engine2, _bookingState$booking3, _bookingState$booking6, _productData$_extend2, _bookingState$booking12, _bookingState$booking13;
	const isMobile = variant === "phone";
	const [open, setOpen] = useState(false);
	const [productData, setProductData] = useState(null);
	const [note, setNote] = useState("");
	const [quantity, setQuantity] = useState(1);
	/**
	* @description 手动改价（单价维度）
	* - null 表示未设置过手动改价
	* - 只要设置过，右侧总价展示始终以该单价为准
	*/
	const [priceOverride, setPriceOverride] = useState(null);
	const [showPriceAdjustModal, setShowPriceAdjustModal] = useState(false);
	const [discounts, setDiscounts] = useState([]);
	const [noteModalOpen, setNoteModalOpen] = useState(false);
	const [weighingData, setWeighingData] = useState(null);
	const [skuValue, setSkuValue] = useState({
		price: 0,
		product_id: 0,
		product_variant_id: 0,
		bundle: [],
		option: []
	});
	const [skuDefaultValue, setSkuDefaultValue] = useState({
		product_id: 0,
		price: 0,
		product_variant_id: 0,
		bundle: [],
		option: []
	});
	const openParamsRef = useRef(null);
	/**
	* 左侧可滚动容器 ref
	* - 称重商品打开弹窗时，自动滚动到底部以完整展示称重模块
	*/
	const leftTopRef = useRef(null);
	const Toast = useToast$1();
	const logger = useLogger();
	/**
	* @description SKUOptionsSelection ref，用于触发内部校验与读取最终值
	*/
	const skuOptionsSelectionRef = useRef(null);
	/**
	* @description 库存提醒弹窗（允许缺货加入购物车时触发）
	*/
	const [stockAlertOpen, setStockAlertOpen] = useState(false);
	const [stockAlertDontShowAgainChecked, setStockAlertDontShowAgainChecked] = useState(false);
	const pendingConfirmDataRef = useRef(null);
	const [currentStep, setCurrentStep] = useState(0);
	const procedureRef = useRef(null);
	const [skuDetailConfig, setSkuDetailConfig] = useState({
		isShowStepper: true,
		isShowNote: true
	});
	const [bodyScaleY, setBodyScaleY] = useState(getBodyScaleY);
	const context = useEngineContext();
	const { store, getData, isWebPos } = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	/**
	* @description
	* booking state 需要从 Booking 的 Context 读取（与 editService 保持一致），不要用 store.getState()
	*/
	const { state: bookingState } = useContext(Context) || {};
	const symbol = getData("shop_symbol");
	locales.init(locales_default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	locales.init(stock_default, (context === null || context === void 0 || (_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.locale) || "en");
	useEffect(() => {
		const updateBodyScale = () => {
			setBodyScaleY(getBodyScaleY());
		};
		updateBodyScale();
		window.addEventListener("resize", updateBodyScale);
		const bodyObserver = new MutationObserver(updateBodyScale);
		bodyObserver.observe(document.body, {
			attributes: true,
			attributeFilter: ["style", "class"]
		});
		return () => {
			window.removeEventListener("resize", updateBodyScale);
			bodyObserver.disconnect();
		};
	}, []);
	const getDetailData = function() {
		var _ref = _asyncToGenerator(function* (data, open_deposit) {
			var _data$skuDetailConfig, _data$skuDetailConfig2, _data$is_eject;
			const isCallProductDetail = (_data$skuDetailConfig = data === null || data === void 0 || (_data$skuDetailConfig2 = data.skuDetailConfig) === null || _data$skuDetailConfig2 === void 0 ? void 0 : _data$skuDetailConfig2.isCallProductDetail) !== null && _data$skuDetailConfig !== void 0 ? _data$skuDetailConfig : false;
			const isEject = (_data$is_eject = data === null || data === void 0 ? void 0 : data.is_eject) !== null && _data$is_eject !== void 0 ? _data$is_eject : 0;
			const canUseLocalData = !(isCallProductDetail && isEject === 1);
			if (isWebPos && data.productData && canUseLocalData) return { data: data.productData };
			else return yield getProductDetail(String(data.id), {
				schedule_date: data.date,
				is_eject: data.is_eject,
				open_deposit
			});
		});
		return function getDetailData(_x, _x2) {
			return _ref.apply(this, arguments);
		};
	}();
	/**
	* @description 库存校验（受全局配置控制）
	* - stock_validation === 1：启用库存校验
	* - allow_add_to_cart_when_out_stock === 1：缺货允许加入购物车（弹窗提示）
	*/
	const stockValidation = useMemo(() => {
		var _bookingState$booking, _bookingState$booking2;
		return Number((_bookingState$booking = bookingState === null || bookingState === void 0 || (_bookingState$booking2 = bookingState.bookingConfig) === null || _bookingState$booking2 === void 0 || (_bookingState$booking2 = _bookingState$booking2.config) === null || _bookingState$booking2 === void 0 || (_bookingState$booking2 = _bookingState$booking2.stock_setting) === null || _bookingState$booking2 === void 0 ? void 0 : _bookingState$booking2.stock_validation) !== null && _bookingState$booking !== void 0 ? _bookingState$booking : 0);
	}, [bookingState === null || bookingState === void 0 || (_bookingState$booking3 = bookingState.bookingConfig) === null || _bookingState$booking3 === void 0 || (_bookingState$booking3 = _bookingState$booking3.config) === null || _bookingState$booking3 === void 0 ? void 0 : _bookingState$booking3.stock_setting]);
	const allowAddToCartWhenOutStock = useMemo(() => {
		var _bookingState$booking4, _bookingState$booking5;
		return Number((_bookingState$booking4 = bookingState === null || bookingState === void 0 || (_bookingState$booking5 = bookingState.bookingConfig) === null || _bookingState$booking5 === void 0 || (_bookingState$booking5 = _bookingState$booking5.config) === null || _bookingState$booking5 === void 0 || (_bookingState$booking5 = _bookingState$booking5.stock_setting) === null || _bookingState$booking5 === void 0 ? void 0 : _bookingState$booking5.allow_add_to_cart_when_out_stock) !== null && _bookingState$booking4 !== void 0 ? _bookingState$booking4 : 0);
	}, [bookingState === null || bookingState === void 0 || (_bookingState$booking6 = bookingState.bookingConfig) === null || _bookingState$booking6 === void 0 || (_bookingState$booking6 = _bookingState$booking6.config) === null || _bookingState$booking6 === void 0 ? void 0 : _bookingState$booking6.stock_setting]);
	/**
	* @description 当前商品是否存在 SKU 选择数据（套餐/单规格/组合规格）
	* - 当 bundle_group、option_group、variant_group 都不存在或为空数组时：
	*   - 不显示整个 SKUOptionsSelection
	*   - 步骤条不显示“选择套餐”这一步
	*
	* @note `ProductData` 类型里未显式声明这几个 group 字段，这里按运行时字段做兼容判断
	*/
	const hasSkuOptions = useMemo(() => {
		const data = productData;
		const hasVariantGroup = Array.isArray(data === null || data === void 0 ? void 0 : data.variant_group) && data.variant_group.length > 0;
		const hasOptionGroup = Array.isArray(data === null || data === void 0 ? void 0 : data.option_group) && data.option_group.length > 0;
		const hasBundleGroup = Array.isArray(data === null || data === void 0 ? void 0 : data.bundle_group) && data.bundle_group.length > 0;
		return hasVariantGroup || hasOptionGroup || hasBundleGroup;
	}, [productData]);
	/**
	* @description Procedure steps：根据是否存在 SKU 选择数据动态生成
	*/
	const procedureSteps = useMemo(() => {
		const items = [{
			title: locales.getText("pisell2.text.sku.detail.modal.step.details"),
			description: ""
		}];
		if (hasSkuOptions) items.push({
			title: locales.getText("pisell2.text.sku.detail.modal.step.select.bundle"),
			description: ""
		});
		return items;
	}, [hasSkuOptions]);
	const maxStepIndex = useMemo(() => Math.max(0, procedureSteps.length - 1), [procedureSteps]);
	/**
	* @description: 格式化组合规格数据
	* @param {any} config
	* @param {any} _variant
	* @param {any} apiData
	* @return {*}
	*/
	const formatVariant = (config, _variant, apiData) => {
		var _config$externalVaria;
		let variantData;
		if (config === null || config === void 0 || (_config$externalVaria = config.externalVariant) === null || _config$externalVaria === void 0 ? void 0 : _config$externalVaria.isCustom) {
			var _config$externalVaria2;
			let variant = _variant || [];
			if (config === null || config === void 0 || (_config$externalVaria2 = config.externalVariant) === null || _config$externalVaria2 === void 0 ? void 0 : _config$externalVaria2.formatVariant) {
				var _config$externalVaria3;
				variant = config === null || config === void 0 || (_config$externalVaria3 = config.externalVariant) === null || _config$externalVaria3 === void 0 ? void 0 : _config$externalVaria3.formatVariant(_variant || []);
			}
			const mergeData = _objectSpread2(_objectSpread2({}, apiData), {}, { variant });
			variantData = {
				variant,
				variant_group: filterVariantGroupByVariants(mergeData) || []
			};
		}
		return variantData;
	};
	useImperativeHandle(ref, () => ({ open: function() {
		var _ref4 = _asyncToGenerator(function* (data) {
			var _skuDetailConfig$isSh, _skuDetailConfig$isSh2, _skuDetailConfig$exte, _skuDetailConfig$useC, _skuDetailConfig$cust, _skuDetailConfig$isCa, _data$_extend, _data$_extend2, _ref3, _data$_extend3, _data$_extend4, _data$_extend$priceOv, _data$_extend5;
			setCurrentStep(0);
			setNoteModalOpen(false);
			logger === null || logger === void 0 || logger.addLog({
				type: "info",
				title: "sku_detail_modal_open",
				metadata: { data }
			});
			const skuDetailConfig = data.skuDetailConfig || {};
			const config = {
				isShowStepper: (_skuDetailConfig$isSh = skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.isShowStepper) !== null && _skuDetailConfig$isSh !== void 0 ? _skuDetailConfig$isSh : true,
				isShowNote: (_skuDetailConfig$isSh2 = skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.isShowNote) !== null && _skuDetailConfig$isSh2 !== void 0 ? _skuDetailConfig$isSh2 : true,
				externalVariant: (_skuDetailConfig$exte = skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.externalVariant) !== null && _skuDetailConfig$exte !== void 0 ? _skuDetailConfig$exte : {},
				useCustomData: (_skuDetailConfig$useC = skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.useCustomData) !== null && _skuDetailConfig$useC !== void 0 ? _skuDetailConfig$useC : false,
				customData: (_skuDetailConfig$cust = skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.customData) !== null && _skuDetailConfig$cust !== void 0 ? _skuDetailConfig$cust : {},
				isCallProductDetail: (_skuDetailConfig$isCa = skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.isCallProductDetail) !== null && _skuDetailConfig$isCa !== void 0 ? _skuDetailConfig$isCa : false
			};
			setSkuDetailConfig(config);
			if ("date" in data && !("_extend" in data)) {
				var _data$productData, _ref2, _is_eject, _hydratedData$_extend;
				logger === null || logger === void 0 || logger.addLog({
					type: "info",
					title: "sku_detail_modal_open_create",
					metadata: {}
				});
				openParamsRef.current = data;
				const productDetail = yield getDetailData(data, (getData === null || getData === void 0 ? void 0 : getData("bookingv2_deposit")) || 0);
				let apiData = (productDetail === null || productDetail === void 0 ? void 0 : productDetail.data) || {};
				if ((config === null || config === void 0 ? void 0 : config.useCustomData) && (config === null || config === void 0 ? void 0 : config.customData)) apiData = _objectSpread2(_objectSpread2({}, apiData), (config === null || config === void 0 ? void 0 : config.customData) || {});
				const basePrice = Number((apiData === null || apiData === void 0 ? void 0 : apiData.price) || 0);
				let variantData = formatVariant(config, data === null || data === void 0 || (_data$productData = data.productData) === null || _data$productData === void 0 ? void 0 : _data$productData.variant, apiData);
				const hydratedData = _objectSpread2(_objectSpread2(_objectSpread2({}, apiData), {}, {
					id: (apiData === null || apiData === void 0 ? void 0 : apiData.id) || data.id,
					product_id: (apiData === null || apiData === void 0 ? void 0 : apiData.product_id) || data.id
				}, variantData || {}), {}, { _extend: _objectSpread2(_objectSpread2({}, (apiData === null || apiData === void 0 ? void 0 : apiData._extend) || {}), {}, {
					product_name: (apiData === null || apiData === void 0 ? void 0 : apiData.title) || (apiData === null || apiData === void 0 ? void 0 : apiData.product_name) || "",
					quantity: 1,
					price: basePrice,
					total: basePrice,
					origin_total: basePrice,
					note: "",
					skuValue: {
						product_id: (apiData === null || apiData === void 0 ? void 0 : apiData.id) || data.id,
						product_variant_id: 0,
						bundle: [],
						option: []
					}
				}) });
				if (!(Number((_ref2 = (_is_eject = apiData === null || apiData === void 0 ? void 0 : apiData.is_eject) !== null && _is_eject !== void 0 ? _is_eject : data.is_eject) !== null && _ref2 !== void 0 ? _ref2 : 0) === 1 || (apiData === null || apiData === void 0 ? void 0 : apiData.open_sold_weight))) {
					var _extend, _bookingState$booking7;
					const stockResult = getStockValidationResult({
						value: hydratedData === null || hydratedData === void 0 || (_extend = hydratedData._extend) === null || _extend === void 0 ? void 0 : _extend.skuValue,
						data: hydratedData,
						bookingConfig: bookingState === null || bookingState === void 0 || (_bookingState$booking7 = bookingState.bookingConfig) === null || _bookingState$booking7 === void 0 ? void 0 : _bookingState$booking7.config
					});
					if (stockResult.shouldBlock) {
						Toast === null || Toast === void 0 || Toast.fail(locales.getText("pisell2.skuOptionsSelection.variantItemCard.soldOut"));
						return;
					}
					if (stockResult.shouldShowAlert) {
						setProductData(hydratedData);
						pendingConfirmDataRef.current = hydratedData;
						setStockAlertDontShowAgainChecked(false);
						setStockAlertOpen(true);
						return;
					}
					onConfirm === null || onConfirm === void 0 || onConfirm(hydratedData);
					modalCloseAction();
					return;
				}
				setProductData(hydratedData);
				setNote("");
				setQuantity(isWeighingProduct(apiData) ? 1 : (apiData === null || apiData === void 0 ? void 0 : apiData.min_num_unit) || 1);
				setDiscounts([]);
				setWeighingData(null);
				setSkuValue({
					product_id: hydratedData.id,
					product_variant_id: 0,
					bundle: [],
					option: []
				});
				setSkuDefaultValue({
					product_id: hydratedData.id,
					product_variant_id: 0,
					bundle: [],
					option: [],
					price: (hydratedData === null || hydratedData === void 0 || (_hydratedData$_extend = hydratedData._extend) === null || _hydratedData$_extend === void 0 ? void 0 : _hydratedData$_extend.price) || 0
				});
				setPriceOverride(null);
				setShowPriceAdjustModal(false);
				const hydratedAny = hydratedData;
				setCurrentStep(Array.isArray(hydratedAny === null || hydratedAny === void 0 ? void 0 : hydratedAny.variant_group) && hydratedAny.variant_group.length > 0 || Array.isArray(hydratedAny === null || hydratedAny === void 0 ? void 0 : hydratedAny.option_group) && hydratedAny.option_group.length > 0 || Array.isArray(hydratedAny === null || hydratedAny === void 0 ? void 0 : hydratedAny.bundle_group) && hydratedAny.bundle_group.length > 0 ? 1 : 0);
				setOpen(true);
				return;
			}
			logger === null || logger === void 0 || logger.addLog({
				type: "info",
				title: "sku_detail_modal_open_edit",
				metadata: {}
			});
			openParamsRef.current = null;
			const _data = cloneDeep(data);
			const variantData = formatVariant(config, _data === null || _data === void 0 ? void 0 : _data.variant, _data);
			if (variantData) {
				_data.variant_group = (variantData === null || variantData === void 0 ? void 0 : variantData.variant_group) || [];
				_data.variant = (variantData === null || variantData === void 0 ? void 0 : variantData.variant) || [];
			}
			setProductData(_data);
			console.log(_data, "_data");
			setNote((_data === null || _data === void 0 || (_data$_extend = _data._extend) === null || _data$_extend === void 0 ? void 0 : _data$_extend.note) || "");
			setQuantity(isWeighingProduct(_data) ? 1 : (_data === null || _data === void 0 || (_data$_extend2 = _data._extend) === null || _data$_extend2 === void 0 ? void 0 : _data$_extend2.quantity) || 1);
			setDiscounts((_data === null || _data === void 0 ? void 0 : _data.discount_list) || []);
			setWeighingData((_data === null || _data === void 0 || (_ref3 = _data._extend) === null || _ref3 === void 0 ? void 0 : _ref3.weighing) || null);
			const recordSkuValue = (_data === null || _data === void 0 || (_data$_extend3 = _data._extend) === null || _data$_extend3 === void 0 ? void 0 : _data$_extend3._skuValue) || (_data === null || _data === void 0 || (_data$_extend4 = _data._extend) === null || _data$_extend4 === void 0 ? void 0 : _data$_extend4.other) || {
				product_id: _data === null || _data === void 0 ? void 0 : _data.product_id,
				product_variant_id: 0,
				bundle: [],
				option: []
			};
			console.log(recordSkuValue, "skuValue");
			setSkuValue(recordSkuValue);
			setSkuDefaultValue(recordSkuValue);
			setPriceOverride((_data$_extend$priceOv = _data === null || _data === void 0 || (_data$_extend5 = _data._extend) === null || _data$_extend5 === void 0 ? void 0 : _data$_extend5.priceOverride) !== null && _data$_extend$priceOv !== void 0 ? _data$_extend$priceOv : null);
			setShowPriceAdjustModal(false);
			const dataAny = _data;
			setCurrentStep(Array.isArray(dataAny === null || dataAny === void 0 ? void 0 : dataAny.variant_group) && dataAny.variant_group.length > 0 || Array.isArray(dataAny === null || dataAny === void 0 ? void 0 : dataAny.option_group) && dataAny.option_group.length > 0 || Array.isArray(dataAny === null || dataAny === void 0 ? void 0 : dataAny.bundle_group) && dataAny.bundle_group.length > 0 ? 1 : 0);
			setTimeout(() => {
				logger === null || logger === void 0 || logger.addLog({
					type: "info",
					title: "sku_detail_modal_open_edit_show",
					metadata: {}
				});
				setOpen(true);
			}, 0);
		});
		return function open(_x3) {
			return _ref4.apply(this, arguments);
		};
	}() }));
	useMemo(() => {
		var _productData$_extend;
		const price = (productData === null || productData === void 0 || (_productData$_extend = productData._extend) === null || _productData$_extend === void 0 ? void 0 : _productData$_extend.price) || 0;
		return `${Number(price) < 0 ? "-" : ""}${symbol}${Math.abs(Number(price))}`;
	}, [productData === null || productData === void 0 || (_productData$_extend2 = productData._extend) === null || _productData$_extend2 === void 0 ? void 0 : _productData$_extend2.price, symbol]);
	/**
	* @title 商品单价（含套餐/单规格/组合规格）
	* @description
	* - 套餐：主商品价格 + 选择的套餐子商品（含其单规格）的总价
	* - 单规格：主商品价格 + 单规格加价
	* - 组合规格：使用选中变体价格作为主商品价格，再叠加 bundle/option
	*
	* @note 计算规则对齐 booking/utils.ts 的 getProductTotalPrice
	*/
	const activeSkuValue = useMemo(() => {
		return (skuValue === null || skuValue === void 0 ? void 0 : skuValue.product_id) ? skuValue : skuDefaultValue;
	}, [skuDefaultValue, skuValue]);
	const { isWeighingProduct: isWeighingProduct$1, scalePriceProduct } = useWeighing({
		productData,
		skuValue: activeSkuValue
	});
	const unitPrice = useMemo(() => {
		if (isWeighingProduct$1) return getWeighedUnitPrice({
			weighedTotalAmount: (weighingData === null || weighingData === void 0 ? void 0 : weighingData.total_amount) || 0,
			productData,
			skuValue: activeSkuValue
		});
		return getSelectedUnitPrice({
			productData,
			skuValue: activeSkuValue
		});
	}, [
		activeSkuValue,
		isWeighingProduct$1,
		productData,
		weighingData === null || weighingData === void 0 ? void 0 : weighingData.total_amount
	]);
	/**
	* @description 最终用于展示总价的单价
	* - 若设置过手动改价，则始终使用手动改价单价
	* - 否则使用 sku 计算出来的单价
	*/
	const displayUnitPrice = useMemo(() => {
		if (priceOverride === null || typeof priceOverride === "undefined") return unitPrice;
		return priceOverride;
	}, [priceOverride, unitPrice]);
	const showQuantityStepper = Boolean((skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.isShowStepper) && !isWeighingProduct$1);
	/**
	* @title 售价小计
	* @description
	* 小计展示的是「商品单价」（即主商品 + 套餐子商品 + 单规格/组合规格加价的合计）
	*/
	const subtotal = useMemo(() => {
		return new Decimal(unitPrice || 0);
	}, [unitPrice]);
	const subtotalText = useMemo(() => {
		return `${subtotal.toNumber() < 0 ? "-" : ""}${symbol}${subtotal.abs().toNumber().toFixed(2)}`;
	}, [subtotal, symbol]);
	const discountsCount = useMemo(() => {
		return (discounts === null || discounts === void 0 ? void 0 : discounts.length) || 0;
	}, [discounts]);
	/**
	* @title 折扣信息
	*/
	const totalDiscounts = useMemo(() => {
		if ((discounts === null || discounts === void 0 ? void 0 : discounts.length) > 0) return discounts.reduce((sum, discount) => {
			const _quantity = ["discount_card", "product_discount_card"].includes((discount === null || discount === void 0 ? void 0 : discount.type) || "") ? quantity : 1;
			return sum.plus(new Decimal((discount === null || discount === void 0 ? void 0 : discount.amount) || 0).mul(_quantity));
		}, new Decimal(0)).toNumber().toFixed(2);
		return "0.00";
	}, [discounts, quantity]);
	/**
	* @title 最终价格
	* @description 商品总价 = 商品单价 * 商品数量 - 折扣金额
	*/
	const finalTotal = useMemo(() => {
		const deTotal = new Decimal(displayUnitPrice || "0");
		const deQuantity = new Decimal(quantity || "1");
		return deTotal.mul(deQuantity).minus(new Decimal(totalDiscounts || 0));
	}, [
		displayUnitPrice,
		quantity,
		totalDiscounts
	]);
	const totalText = useMemo(() => {
		return `${finalTotal.toNumber() < 0 ? "-" : ""}${symbol}${finalTotal.abs().toNumber().toFixed(2)}`;
	}, [finalTotal, symbol]);
	/**
	* @description 价格变动展示（仅当设置过手动改价时展示）
	* - 展示手动改价的单价
	* - 展示相对 sku 单价的变动额： (priceOverride - unitPrice) * quantity
	*/
	const priceOverrideText = useMemo(() => {
		if (priceOverride === null || typeof priceOverride === "undefined") return "";
		const prefix = `(${locales.getText("pisell2.text.sku.detail.modal.price.override")} `;
		const overrideNumber = new Decimal(priceOverride || 0);
		return `${prefix}${overrideNumber.toNumber() < 0 ? "-" : ""}${symbol}${overrideNumber.abs().toNumber().toFixed(2)})`;
	}, [priceOverride, symbol]);
	const priceChangeText = useMemo(() => {
		if (priceOverride === null || typeof priceOverride === "undefined") return "";
		const diff = new Decimal(priceOverride || 0).minus(new Decimal(unitPrice || 0)).mul(new Decimal(quantity || 1));
		const diffNumber = diff.toNumber();
		return `${diffNumber > 0 ? "+" : diffNumber < 0 ? "-" : ""}${symbol}${diff.abs().toNumber().toFixed(2)}`;
	}, [
		priceOverride,
		unitPrice,
		quantity,
		symbol
	]);
	const selectedSpecificationItems = useMemo(() => {
		return formatSelectedSkuItems(activeSkuValue, symbol);
	}, [activeSkuValue, symbol]);
	const selectedSpecificationText = useMemo(() => {
		return formatSelectedSkuMessage(activeSkuValue, symbol);
	}, [activeSkuValue, symbol]);
	const pcConfirmButtonText = useMemo(() => {
		if (currentStep === 0 && hasSkuOptions) return locales.getText("pisell2.text.sku.detail.modal.btn.next");
		return locales.getText("pisell2.text.sku.detail.modal.btn.confirm");
	}, [currentStep, hasSkuOptions]);
	const modalCloseAction = () => {
		setOpen(false);
		setProductData(null);
		setNote("");
		setQuantity(1);
		setNoteModalOpen(false);
		setPriceOverride(null);
		setShowPriceAdjustModal(false);
		setDiscounts([]);
		setWeighingData(null);
		openParamsRef.current = null;
		setCurrentStep(0);
	};
	const handleCancel = () => {
		modalCloseAction();
		onClose === null || onClose === void 0 || onClose();
	};
	const handleConfirm = function() {
		var _ref5 = _asyncToGenerator(function* () {
			var _bookingState$booking8;
			if (!isMobile && currentStep === 0 && hasSkuOptions) {
				var _procedureRef$current, _procedureRef$current2;
				(_procedureRef$current = procedureRef.current) === null || _procedureRef$current === void 0 || (_procedureRef$current2 = _procedureRef$current.goToStep) === null || _procedureRef$current2 === void 0 || _procedureRef$current2.call(_procedureRef$current, 1);
				setCurrentStep(1);
				return;
			}
			/**
			* @description Confirm 前是否需要触发 SKU 选择校验
			* - required_option_validation 不为 0：需要校验（失败阻断）
			* - required_option_validation 为 0：不校验（无论成功/失败都允许提交）
			*
			* @note 配置缺失时默认走“需要校验”，保持更安全的默认行为
			*/
			const requiredOptionValidation = bookingState === null || bookingState === void 0 || (_bookingState$booking8 = bookingState.bookingConfig) === null || _bookingState$booking8 === void 0 || (_bookingState$booking8 = _bookingState$booking8.config) === null || _bookingState$booking8 === void 0 || (_bookingState$booking8 = _bookingState$booking8.product_setting_tab) === null || _bookingState$booking8 === void 0 ? void 0 : _bookingState$booking8.required_option_validation;
			if (Number(requiredOptionValidation !== null && requiredOptionValidation !== void 0 ? requiredOptionValidation : 1) !== 0 && hasSkuOptions) try {
				var _skuOptionsSelectionR, _skuOptionsSelectionR2;
				if (!(yield (_skuOptionsSelectionR = skuOptionsSelectionRef.current) === null || _skuOptionsSelectionR === void 0 || (_skuOptionsSelectionR2 = _skuOptionsSelectionR.validate) === null || _skuOptionsSelectionR2 === void 0 ? void 0 : _skuOptionsSelectionR2.call(_skuOptionsSelectionR))) return;
			} catch (error) {
				console.log("sku_detail_modal_validate_error>>>>>", error);
				return;
			}
			if (productData && onConfirm) {
				var _skuOptionsSelectionR3, _skuOptionsSelectionR4, _updatedData$_extend, _bookingState$booking9;
				/**
				* @description 优先从 SKUOptionsSelection ref 读取最新转换后的值
				*/
				const latestSkuValue = ((_skuOptionsSelectionR3 = skuOptionsSelectionRef.current) === null || _skuOptionsSelectionR3 === void 0 || (_skuOptionsSelectionR4 = _skuOptionsSelectionR3.getTransformValues) === null || _skuOptionsSelectionR4 === void 0 ? void 0 : _skuOptionsSelectionR4.call(_skuOptionsSelectionR3)) || skuValue || skuDefaultValue;
				const originTotal = new Decimal(unitPrice !== null && unitPrice !== void 0 ? unitPrice : 0).toNumber();
				const resolvedExtendPrice = getSourceUnitPrice({
					productData,
					skuValue: latestSkuValue
				});
				const weighing = isWeighingProduct$1 && weighingData ? weighingData : void 0;
				const updatedData = _objectSpread2(_objectSpread2({}, productData), {}, {
					discount_list: discounts || [],
					_extend: _objectSpread2(_objectSpread2({}, (productData === null || productData === void 0 ? void 0 : productData._extend) || {}), {}, {
						quantity,
						note,
						price: String(resolvedExtendPrice),
						other: getOtherFromSkuValue({
							productData,
							skuValue: latestSkuValue
						}),
						skuValue: getOtherFromSkuValue({
							productData,
							skuValue: latestSkuValue
						}),
						origin_total: originTotal,
						weighing
					}, priceOverride !== null && typeof priceOverride !== "undefined" ? { priceOverride } : {})
				});
				console.log("updatedData>>>>>>", updatedData, updatedData === null || updatedData === void 0 || (_updatedData$_extend = updatedData._extend) === null || _updatedData$_extend === void 0 ? void 0 : _updatedData$_extend.origin_total);
				const stockResult = getStockValidationResult({
					value: latestSkuValue,
					data: productData,
					bookingConfig: bookingState === null || bookingState === void 0 || (_bookingState$booking9 = bookingState.bookingConfig) === null || _bookingState$booking9 === void 0 ? void 0 : _bookingState$booking9.config
				});
				if (stockResult.shouldBlock) {
					Toast === null || Toast === void 0 || Toast.fail(locales.getText("pisell2.skuOptionsSelection.variantItemCard.soldOut"));
					return;
				}
				if (stockResult.shouldShowAlert) {
					pendingConfirmDataRef.current = updatedData;
					setStockAlertDontShowAgainChecked(false);
					setStockAlertOpen(true);
					return;
				}
				onConfirm(updatedData);
				modalCloseAction();
			}
		});
		return function handleConfirm() {
			return _ref5.apply(this, arguments);
		};
	}();
	const handleStockAlertCancel = () => {
		pendingConfirmDataRef.current = null;
		setStockAlertOpen(false);
		setStockAlertDontShowAgainChecked(false);
	};
	const handleStockAlertContinue = () => {
		var _bookingState$booking10, _bookingState$booking11;
		const pendingData = pendingConfirmDataRef.current;
		if (!pendingData) {
			setStockAlertOpen(false);
			return;
		}
		if (Number((_bookingState$booking10 = bookingState === null || bookingState === void 0 || (_bookingState$booking11 = bookingState.bookingConfig) === null || _bookingState$booking11 === void 0 || (_bookingState$booking11 = _bookingState$booking11.config) === null || _bookingState$booking11 === void 0 || (_bookingState$booking11 = _bookingState$booking11.stock_setting) === null || _bookingState$booking11 === void 0 ? void 0 : _bookingState$booking11.do_not_show_again_today) !== null && _bookingState$booking10 !== void 0 ? _bookingState$booking10 : 0) === 1 && stockAlertDontShowAgainChecked) setHiddenStockAlertForToday({ productId: Number((productData === null || productData === void 0 ? void 0 : productData.product_id) || 0) });
		onConfirm === null || onConfirm === void 0 || onConfirm(pendingData);
		pendingConfirmDataRef.current = null;
		setStockAlertOpen(false);
		modalCloseAction();
	};
	const handleRemove = () => {
		if (productData && onRemove) {
			onRemove(productData);
			modalCloseAction();
		}
	};
	const handleQuantityChange = (value) => {
		if (isWeighingProduct$1) return;
		if (value && value > 0) setQuantity(value);
	};
	useEffect(() => {
		if (isWeighingProduct$1 && quantity !== 1) setQuantity(1);
	}, [isWeighingProduct$1, quantity]);
	/**
	* 称重商品打开弹窗后，自动将左侧可滚动容器滚动到底部
	* - 仅 PC 模式下才有该容器（mobile 不渲染 leftContent）
	* - 使用双 RAF 等待 Weighing 子组件渲染完成后再滚动
	*/
	useEffect(() => {
		if (!open) return;
		if (isMobile) return;
		if (!isWeighingProduct$1) return;
		if (!productData) return;
		let raf1 = 0;
		let raf2 = 0;
		raf1 = requestAnimationFrame(() => {
			raf2 = requestAnimationFrame(() => {
				const el = leftTopRef.current;
				if (!el) return;
				el.scrollTop = el.scrollHeight;
			});
		});
		return () => {
			cancelAnimationFrame(raf1);
			cancelAnimationFrame(raf2);
		};
	}, [
		open,
		isMobile,
		isWeighingProduct$1,
		productData === null || productData === void 0 ? void 0 : productData._id,
		productData === null || productData === void 0 ? void 0 : productData.id
	]);
	const onNoteConfirm = (note) => {
		setNote(note);
		setNoteModalOpen(false);
	};
	const onNoteDelete = () => {
		setNote("");
		setNoteModalOpen(false);
	};
	const onNoteCancel = () => {
		setNoteModalOpen(false);
	};
	const handleManualPriceChange = () => {
		if (!productData) return;
		setShowPriceAdjustModal(true);
	};
	const handlePriceAdjustConfirm = (value) => {
		setPriceOverride(value);
		setDiscounts([]);
		setShowPriceAdjustModal(false);
	};
	const coverText = useMemo(() => {
		var _productData$title;
		const title = (productData === null || productData === void 0 || (_productData$title = productData.title) === null || _productData$title === void 0 ? void 0 : _productData$title.trim()) || "";
		if (!title) return "";
		return Array.from(title).slice(0, 2).join("");
	}, [productData === null || productData === void 0 ? void 0 : productData.title]);
	const isCreateMode = !!openParamsRef.current;
	const _containerClass = variant === "phone" ? ".pisell-sku-detail-drawer" : ".pisell-sku-detail-modal";
	const skuScrollParentSelector = `${_containerClass} .sku-detail-right-content`;
	const productDescription = (productData === null || productData === void 0 ? void 0 : productData.description) || "";
	const renderWeighingSection = () => {
		if (!isWeighingProduct$1) return null;
		return /* @__PURE__ */ React.createElement(Weighing, {
			key: String((productData === null || productData === void 0 ? void 0 : productData._id) || (productData === null || productData === void 0 ? void 0 : productData.id) || "weighing"),
			scalePriceProduct,
			currencySymbol: symbol,
			initialValue: weighingData !== null && weighingData !== void 0 ? weighingData : void 0,
			onChange: setWeighingData
		});
	};
	const leftContent = () => {
		return /* @__PURE__ */ React.createElement("div", { className: "sku-detail-left" }, /* @__PURE__ */ React.createElement("div", {
			className: "sku-detail-left-top",
			ref: leftTopRef
		}, /* @__PURE__ */ React.createElement("div", { className: "product-image" }, (productData === null || productData === void 0 ? void 0 : productData.cover) ? /* @__PURE__ */ React.createElement("img", { src: (productData === null || productData === void 0 ? void 0 : productData.cover) || "" }) : /* @__PURE__ */ React.createElement("div", { className: "product-cover-text" }, coverText)), /* @__PURE__ */ React.createElement("div", { className: "product-info" }, /* @__PURE__ */ React.createElement("div", { className: "product-info-left" }, /* @__PURE__ */ React.createElement("div", { className: "product-name" }, (productData === null || productData === void 0 ? void 0 : productData.title) || ""))), renderWeighingSection(), selectedSpecificationText && /* @__PURE__ */ React.createElement("div", { className: "selected-specification-section" }, /* @__PURE__ */ React.createElement("div", { className: "selected-specification-list" }, selectedSpecificationItems.map((item) => {
			if (item.type === "bundle") return /* @__PURE__ */ React.createElement("div", {
				key: item.key,
				className: "selected-specification-group selected-specification-group-bundle"
			}, /* @__PURE__ */ React.createElement("div", { className: "selected-specification-item selected-specification-item-bundle" }, /* @__PURE__ */ React.createElement("div", { className: "selected-specification-item-main" }, /* @__PURE__ */ React.createElement("span", { className: "selected-specification-item-label" }, item.label), item.meta ? /* @__PURE__ */ React.createElement("span", { className: "selected-specification-item-meta" }, item.meta) : null)), item.children && item.children.length > 0 ? /* @__PURE__ */ React.createElement("div", { className: "selected-specification-group-children" }, item.children.map((child) => /* @__PURE__ */ React.createElement("div", {
				key: child.key,
				className: "selected-specification-item selected-specification-item-bundleOption"
			}, /* @__PURE__ */ React.createElement("div", { className: "selected-specification-item-main" }, /* @__PURE__ */ React.createElement("span", { className: "selected-specification-item-label" }, child.label), child.meta ? /* @__PURE__ */ React.createElement("span", { className: "selected-specification-item-meta" }, child.meta) : null)))) : null);
			return /* @__PURE__ */ React.createElement("div", {
				key: item.key,
				className: `selected-specification-item selected-specification-item-${item.type}`
			}, /* @__PURE__ */ React.createElement("div", { className: "selected-specification-item-main" }, /* @__PURE__ */ React.createElement("span", { className: "selected-specification-item-label" }, item.label), item.meta ? /* @__PURE__ */ React.createElement("span", { className: "selected-specification-item-meta" }, item.meta) : null));
		})))), /* @__PURE__ */ React.createElement("div", { className: "sku-detail-left-bottom" }, (note || showQuantityStepper) && /* @__PURE__ */ React.createElement("div", { className: "sku-detail-side-meta" }, showQuantityStepper && /* @__PURE__ */ React.createElement("div", { className: "quantity-section quantity-section-right" }, /* @__PURE__ */ React.createElement("div", { className: "quantity-section-title" }, locales.getText("pisell2.text.sku.detail.modal.quantity")), /* @__PURE__ */ React.createElement(NumericStepper, {
			variant: "capsule",
			value: quantity,
			onChange: handleQuantityChange,
			min: 1,
			max: 99999
		})), note && /* @__PURE__ */ React.createElement("div", { className: "note-section note-section-right" }, /* @__PURE__ */ React.createElement("div", { className: "note-label" }, locales.getText("pisell2.text.sku.detail.modal.note")), /* @__PURE__ */ React.createElement("div", {
			className: "note-text",
			onClick: () => setNoteModalOpen(true)
		}, note))), /* @__PURE__ */ React.createElement("div", { className: "price-summary-section" }, /* @__PURE__ */ React.createElement("div", { className: "price-item" }, /* @__PURE__ */ React.createElement("div", null, locales.getText("pisell2.text.sku.detail.modal.subtotal")), /* @__PURE__ */ React.createElement("div", null, subtotalText)), /* @__PURE__ */ React.createElement("div", { className: "price-item" }, /* @__PURE__ */ React.createElement("div", null, locales.getText("pisell2.text.sku.detail.modal.discount"), discountsCount > 0 && /* @__PURE__ */ React.createElement("span", { className: "price-item-danger" }, "\xA0(", discountsCount, ")")), /* @__PURE__ */ React.createElement("div", { className: "price-item-danger" }, discountsCount > 0 ? "-" : "", symbol, totalDiscounts)), priceOverride !== null && typeof priceOverride !== "undefined" && /* @__PURE__ */ React.createElement("div", { className: "price-item" }, /* @__PURE__ */ React.createElement("div", { onClick: handleManualPriceChange }, locales.getText("pisell2.text.sku.detail.modal.manual.price.change"), /* @__PURE__ */ React.createElement("span", { className: "price-item-override" }, priceOverrideText)), /* @__PURE__ */ React.createElement("div", { className: "price-item-danger" }, priceChangeText)), /* @__PURE__ */ React.createElement("div", { className: "price-item-total" }, /* @__PURE__ */ React.createElement("div", null, locales.getText("pisell2.text.sku.detail.modal.total"), /* @__PURE__ */ React.createElement("span", { className: "price-item-total-gst" }, "（", (productData === null || productData === void 0 ? void 0 : productData.is_charge_tax) ? locales.getText("pisell2.text.sku.detail.modal.gst.incl") : locales.getText("pisell2.text.sku.detail.modal.gst.excl"), "）")), /* @__PURE__ */ React.createElement("div", null, totalText))), /* @__PURE__ */ React.createElement(PcActionButtons, {
			isCreateMode,
			isShowNote: !!(skuDetailConfig === null || skuDetailConfig === void 0 ? void 0 : skuDetailConfig.isShowNote),
			confirmLabel: pcConfirmButtonText,
			onCancel: handleCancel,
			onRemove: handleRemove,
			onManualPriceChange: handleManualPriceChange,
			onOpenNote: () => setNoteModalOpen(true),
			onConfirm: handleConfirm
		})));
	};
	if (!productData) return null;
	const rightContent = () => {
		return /* @__PURE__ */ React.createElement("div", { className: "sku-detail-right-content" }, !isMobile && currentStep === 0 && /* @__PURE__ */ React.createElement("div", { className: "sku-detail-right-content-detail" }, /* @__PURE__ */ React.createElement("div", { className: "sku-detail-right-content-detail-description" }, (productData === null || productData === void 0 ? void 0 : productData.subtitle) ? /* @__PURE__ */ React.createElement("div", { className: "sku-detail-right-content-detail-subtitle" }, productData.subtitle) : null, productDescription ? /* @__PURE__ */ React.createElement("div", {
			className: "sku-detail-right-content-detail-description-html",
			dangerouslySetInnerHTML: { __html: productDescription }
		}) : null, productDescription === "" && !hasSkuOptions && /* @__PURE__ */ React.createElement("div", { className: "sku-detail-right-content-detail-placeholder" }, /* @__PURE__ */ React.createElement("img", {
			width: 300,
			height: 300,
			src: "https://static.pisellcdn.com/sku_empty.png",
			alt: "placeholder"
		}), /* @__PURE__ */ React.createElement("p", null, locales.getText("pisell2.text.sku.detail.modal.no.additional.options"))))), (isMobile || currentStep === 1) && hasSkuOptions && /* @__PURE__ */ React.createElement(SKUOptionsSelection, {
			ref: skuOptionsSelectionRef,
			dataSource: productData,
			value: skuDefaultValue,
			skuCardConfig: {
				title: { lineClamp: 1 },
				subTitle: { lineClamp: 1 }
			},
			customConfig: {
				modalWidth: isMobile ? "100%" : "680px",
				selectorLayout: {
					type: "antdGrid",
					columns: isMobile ? 1 : 2,
					gutter: isMobile ? [12, 12] : [16, 16]
				}
			},
			config: { overSold: stockValidation === 0 || allowAddToCartWhenOutStock === 1 ? 1 : 0 },
			onChange: (v) => {
				console.log("SKUOptionsSelectionOnChange", v);
				setSkuValue(v);
			},
			customScrollParent: skuScrollParentSelector
		}));
	};
	const leftHeaderClose = () => {
		return /* @__PURE__ */ React.createElement("div", {
			className: "sku-detail-left-close",
			onClick: handleCancel
		}, /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-x-close" }), locales.getText("pisell2.text.sku.detail.modal.btn.close"));
	};
	/**
	* @description Procedure Header：返回按钮（仅在非第一步展示）
	* - 第一页不展示，但必须渲染一个空 div 占位，避免 header 布局抖动
	*/
	const leftHeaderBack = () => {
		if (currentStep === 0) return /* @__PURE__ */ React.createElement("div", { className: "sku-detail-left-back-placeholder" });
		return /* @__PURE__ */ React.createElement("div", {
			className: "sku-detail-left-back",
			onClick: () => {
				var _procedureRef$current3, _procedureRef$current4;
				(_procedureRef$current3 = procedureRef.current) === null || _procedureRef$current3 === void 0 || (_procedureRef$current4 = _procedureRef$current3.goToStep) === null || _procedureRef$current4 === void 0 || _procedureRef$current4.call(_procedureRef$current3, 0);
				setCurrentStep(0);
			}
		}, /* @__PURE__ */ React.createElement(Iconfont, { type: "pisell2-arrow-left" }), locales.getText("pisell2.text.sku.detail.modal.btn.back"));
	};
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CompensatedPisellContainer, {
		platform: "pc",
		renderType: variant === "phone" ? "drawer" : "modal",
		props: {
			open,
			onCancel: handleCancel,
			header: null,
			headerDivider: false,
			footer: null,
			closable: false,
			destroyOnClose: true,
			style: { maxHeight: variant === "phone" ? "95dvh" : void 0 },
			height: variant === "phone" && hasSkuOptions ? "95%" : void 0,
			width: variant === "phone" ? "100%" : "80%",
			className: classNames({
				"pisell-sku-detail-modal": variant !== "phone",
				"pisell-sku-detail-modal--smallTablet": variant !== "phone" && variant === "smallTablet",
				"pisell-sku-detail-modal--tablet": variant !== "phone" && variant === "tablet",
				"pisell-sku-detail-drawer": variant === "phone",
				"aside-full": isWeighingProduct$1 && !hasSkuOptions
			}),
			placement: variant === "phone" ? "bottom" : void 0
		}
	}, /* @__PURE__ */ React.createElement(PisellProcedureComponent, {
		ref: procedureRef,
		className: "pisell-sku-procedure",
		mode: "modal",
		defaultCurrent: currentStep,
		layoutMode: "ratio",
		onStepsChange: (result) => {
			setCurrentStep(Math.min(Number(result.currentStep || 0), maxStepIndex));
		},
		headerProps: {
			showBackOnFirstStep: true,
			showSteps: procedureSteps.length > 1,
			left: leftHeaderBack(),
			right: leftHeaderClose(),
			stepsProps: { items: procedureSteps }
		},
		onFirstStepBack: () => {
			handleCancel();
		},
		showSideBar: true,
		showFooter: false,
		bodyProps: {
			direction: variant === "phone" ? "vertical" : "horizontal",
			contentOrder: "content-first",
			contentSlot: rightContent(),
			sidebarSlot: leftContent(),
			sidebarContainerSelector: _containerClass
		}
	}), noteModalOpen && /* @__PURE__ */ React.createElement(noteModal_default, {
		open: noteModalOpen,
		value: note,
		onCancel: onNoteCancel,
		onConfirm: onNoteConfirm,
		onDelete: onNoteDelete
	}), /* @__PURE__ */ React.createElement(DiscountKeyboard, {
		containerProps: {
			renderType: "modal",
			open: showPriceAdjustModal,
			onCancel: () => setShowPriceAdjustModal(false)
		},
		enableExceedMaxAmount: true,
		originalValue: subtotal.toNumber() || 0,
		defaultValue: displayUnitPrice || 0,
		onEnter: (discountAmount) => {
			handlePriceAdjustConfirm(subtotal.minus(Number(discountAmount) || 0).toNumber());
		},
		selectType: "dark"
	})), /* @__PURE__ */ React.createElement(PisellModal, {
		platform: "pc",
		open: stockAlertOpen,
		title: locales.getText("pisell2.text.sku.detail.modal.stock.alert.title"),
		headerDivider: false,
		footer: /* @__PURE__ */ React.createElement("div", { style: {
			width: "100%",
			display: "flex",
			justifyContent: "flex-end",
			gap: 12
		} }, /* @__PURE__ */ React.createElement(Button, {
			size: "large",
			onClick: handleStockAlertCancel
		}, locales.getText("pisell2.text.sku.detail.modal.stock.alert.btn.cancel")), /* @__PURE__ */ React.createElement(Button, {
			type: "primary",
			size: "large",
			onClick: handleStockAlertContinue
		}, locales.getText("pisell2.text.sku.detail.modal.stock.alert.btn.continue"))),
		width: 520,
		centered: true,
		destroyOnClose: true,
		maskClosable: false,
		zIndex: 2e3,
		onCancel: handleStockAlertCancel
	}, /* @__PURE__ */ React.createElement("div", { style: { padding: "40px 0 0 0" } }, /* @__PURE__ */ React.createElement("div", { style: {
		color: "#344054",
		fontSize: 14,
		lineHeight: "22px"
	} }, locales.getText("pisell2.text.sku.detail.modal.stock.alert.desc")), Number((_bookingState$booking12 = bookingState === null || bookingState === void 0 || (_bookingState$booking13 = bookingState.bookingConfig) === null || _bookingState$booking13 === void 0 || (_bookingState$booking13 = _bookingState$booking13.config) === null || _bookingState$booking13 === void 0 || (_bookingState$booking13 = _bookingState$booking13.stock_setting) === null || _bookingState$booking13 === void 0 ? void 0 : _bookingState$booking13.do_not_show_again_today) !== null && _bookingState$booking12 !== void 0 ? _bookingState$booking12 : 0) === 1 && /* @__PURE__ */ React.createElement("div", { style: { marginTop: 16 } }, /* @__PURE__ */ React.createElement(Checkbox, {
		checked: stockAlertDontShowAgainChecked,
		onChange: (e) => {
			var _e$target;
			setStockAlertDontShowAgainChecked(!!(e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.checked));
		}
	}, locales.getText("pisell2.text.sku.detail.modal.stock.alert.checkbox"))))));
};
const ForwardedSkuDetailModal = forwardRef(SkuDetailModal);
ForwardedSkuDetailModal.displayName = `SkuDetailModal`;
var skuDetailModal_default = withResponsive(ForwardedSkuDetailModal);
/**
* @description
* v2 主商品 source 单价（不含套餐子商品、不含单规格加价），供 _extend.price / transform 使用。
*/
function getSourceUnitPrice(params) {
	var _ref6, _ref7, _productData$base_pri, _productData$_extend3;
	const { productData, skuValue } = params;
	if (!productData) return 0;
	let price = new Decimal((_ref6 = (_ref7 = (_productData$base_pri = productData === null || productData === void 0 ? void 0 : productData.base_price) !== null && _productData$base_pri !== void 0 ? _productData$base_pri : productData === null || productData === void 0 ? void 0 : productData.price) !== null && _ref7 !== void 0 ? _ref7 : productData === null || productData === void 0 || (_productData$_extend3 = productData._extend) === null || _productData$_extend3 === void 0 ? void 0 : _productData$_extend3.price) !== null && _ref6 !== void 0 ? _ref6 : 0);
	if (skuValue === null || skuValue === void 0 ? void 0 : skuValue.product_variant_id) {
		var _variant2;
		const variantItem = productData === null || productData === void 0 || (_variant2 = productData.variant) === null || _variant2 === void 0 ? void 0 : _variant2.find((item) => Number(item === null || item === void 0 ? void 0 : item.id) === Number(skuValue.product_variant_id));
		if (variantItem) {
			var _ref8, _ref9, _variantItem$price;
			price = new Decimal((_ref8 = (_ref9 = (_variantItem$price = variantItem === null || variantItem === void 0 ? void 0 : variantItem.price) !== null && _variantItem$price !== void 0 ? _variantItem$price : variantItem === null || variantItem === void 0 ? void 0 : variantItem.base_price) !== null && _ref9 !== void 0 ? _ref9 : variantItem === null || variantItem === void 0 ? void 0 : variantItem.original_price) !== null && _ref8 !== void 0 ? _ref8 : 0);
		}
	}
	return price.toNumber();
}
/**
* @description
* 根据当前 skuValue（组合规格/单规格/套餐）计算“商品单价”
* 计算规则与 booking/utils.ts 的 getProductTotalPrice 保持一致。
*/
function getSelectedUnitPrice(params) {
	var _ref10, _productData$base_pri2, _productData$_extend4;
	const { productData, skuValue } = params;
	if (!productData) return 0;
	let price = new Decimal((_ref10 = (_productData$base_pri2 = productData === null || productData === void 0 ? void 0 : productData.base_price) !== null && _productData$base_pri2 !== void 0 ? _productData$base_pri2 : productData === null || productData === void 0 || (_productData$_extend4 = productData._extend) === null || _productData$_extend4 === void 0 ? void 0 : _productData$_extend4.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
	if (skuValue === null || skuValue === void 0 ? void 0 : skuValue.product_variant_id) {
		var _variant3;
		const variantItem = productData === null || productData === void 0 || (_variant3 = productData.variant) === null || _variant3 === void 0 ? void 0 : _variant3.find((item) => Number(item === null || item === void 0 ? void 0 : item.id) === Number(skuValue.product_variant_id));
		if (variantItem) {
			var _ref11, _variantItem$base_pri;
			price = new Decimal((_ref11 = (_variantItem$base_pri = variantItem === null || variantItem === void 0 ? void 0 : variantItem.base_price) !== null && _variantItem$base_pri !== void 0 ? _variantItem$base_pri : variantItem === null || variantItem === void 0 ? void 0 : variantItem.original_price) !== null && _ref11 !== void 0 ? _ref11 : 0);
		}
	}
	if (Array.isArray(skuValue === null || skuValue === void 0 ? void 0 : skuValue.bundle) && skuValue.bundle.length > 0) price = skuValue.bundle.reduce((accumulator, currentValue) => {
		var _ref12, _currentValue$origina;
		const currentPrice = new Decimal((_ref12 = (_currentValue$origina = currentValue === null || currentValue === void 0 ? void 0 : currentValue.original_price) !== null && _currentValue$origina !== void 0 ? _currentValue$origina : currentValue === null || currentValue === void 0 ? void 0 : currentValue.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
		const currentNum = new Decimal((currentValue === null || currentValue === void 0 ? void 0 : currentValue.num) || 0);
		return accumulator.add(currentPrice.mul(currentNum));
	}, price);
	if (Array.isArray(skuValue === null || skuValue === void 0 ? void 0 : skuValue.option) && skuValue.option.length > 0) price = skuValue.option.reduce((accumulator, currentValue) => {
		var _ref13, _currentValue$origina2;
		const currentPrice = new Decimal((_ref13 = (_currentValue$origina2 = currentValue === null || currentValue === void 0 ? void 0 : currentValue.original_price) !== null && _currentValue$origina2 !== void 0 ? _currentValue$origina2 : currentValue === null || currentValue === void 0 ? void 0 : currentValue.price) !== null && _ref13 !== void 0 ? _ref13 : 0);
		const currentNum = new Decimal((currentValue === null || currentValue === void 0 ? void 0 : currentValue.num) || 0);
		return accumulator.add(currentPrice.mul(currentNum));
	}, price);
	return price.toNumber();
}
/**
* @description
* 生成给 booking 侧使用的 other 字段（用于 getProductTotalPrice 按同规则算价）
*/
function getOtherFromSkuValue(params) {
	const { productData, skuValue } = params;
	const other = _objectSpread2(_objectSpread2({}, skuValue || {}), {}, {
		product_variant_id: (skuValue === null || skuValue === void 0 ? void 0 : skuValue.product_variant_id) || 0,
		bundle: (skuValue === null || skuValue === void 0 ? void 0 : skuValue.bundle) || [],
		option: (skuValue === null || skuValue === void 0 ? void 0 : skuValue.option) || []
	});
	if (other.product_variant_id && productData) {
		var _variant4;
		const variantItem = productData === null || productData === void 0 || (_variant4 = productData.variant) === null || _variant4 === void 0 ? void 0 : _variant4.find((item) => Number(item === null || item === void 0 ? void 0 : item.id) === Number(other.product_variant_id));
		if (variantItem) {
			var _ref14, _variantItem$price2;
			other.price = Number((_ref14 = (_variantItem$price2 = variantItem === null || variantItem === void 0 ? void 0 : variantItem.price) !== null && _variantItem$price2 !== void 0 ? _variantItem$price2 : variantItem === null || variantItem === void 0 ? void 0 : variantItem.base_price) !== null && _ref14 !== void 0 ? _ref14 : 0);
		}
	}
	return other;
}
//#endregion
export { skuDetailModal_default as default };
