const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../../keyboards/numberKeyboard/index.js");
const require_utils = require("./utils.js");
const require_TareManagementPanel = require("./TareManagementPanel.js");
const require_locales = require("./locales.js");
const require_grid = require("./grid.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/pro/skuDetailModal/components/weighing/index.tsx
const MAX_RETAIL_SCALE_WEIGHT_KG = 1e3;
const WEIGHT_PRECISION = 3;
const DEFAULT_OUTPUT_WEIGHT_PRECISION = 3;
const DEFAULT_OUTPUT_UNIT_PRICE_PRECISION = 2;
const formatOutputWeight = (value) => Number(value || 0).toFixed(DEFAULT_OUTPUT_WEIGHT_PRECISION);
const formatOutputUnitPrice = (value) => Number(value || 0).toFixed(DEFAULT_OUTPUT_UNIT_PRICE_PRECISION);
const Weighing = (props) => {
	var _context$engine, _context$appHelper, _context$appHelper$ge, _context$appHelper$ge2, _initialValue$mode, _initialTare$value, _initialValue$weight;
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_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");
	const getText = (key, fallback) => _pisell_utils.locales.getText(key) || fallback;
	const noTareLabel = getText("pisell2.text.sku.detail.modal.weighing.none.tare", "No Tare");
	const { tareOptions: tareOptionsProp = [], initialValue, unit: scaleUnit = "KILOGRAMS", currencySymbol = "$", scalePriceProduct, onChange } = props;
	/**
	* 从宿主注入的 plugins 中取出 nativeScaleTools（硬件监听 + 单位换算 + 称重计价）。
	* 开发阶段不做兼容：若未注入则直接抛错，由宿主侧保证插件存在。
	*/
	const nativeScaleTools = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.call(_context$appHelper)) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.plugins) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge2 = _context$appHelper$ge.get) === null || _context$appHelper$ge2 === void 0 ? void 0 : _context$appHelper$ge2.call(_context$appHelper$ge, "nativeScaleTools");
	if (!nativeScaleTools) throw new Error("[Weighing] nativeScaleTools plugin is required. Please register it via app.plugins.");
	const { useNativeScale, calculateScaleItemTotal, convertWeight } = nativeScaleTools;
	/** 秤单位对应的展示缩写，用于所有 UI 文本。 */
	const unitLabel = require_utils.UNIT_LABEL[scaleUnit];
	const initialMode = (_initialValue$mode = initialValue === null || initialValue === void 0 ? void 0 : initialValue.mode) !== null && _initialValue$mode !== void 0 ? _initialValue$mode : "auto";
	/**
	* 手动输入初始值：initialValue.grossWeight 已经是 scaleUnit，直接格式化。
	* 若未传 initialValue 则初始为 '0.000'。
	*/
	const initialManualWeight = initialValue != null ? require_utils.formatWeight(Number(initialValue.weight)) : "0.000";
	const initialTare = initialValue === null || initialValue === void 0 ? void 0 : initialValue.tare;
	const initialTareValue = Number((_initialTare$value = initialTare === null || initialTare === void 0 ? void 0 : initialTare.value) !== null && _initialTare$value !== void 0 ? _initialTare$value : 0);
	const rootRef = (0, react.useRef)(null);
	const [tarePopoverOpen, setTarePopoverOpen] = (0, react.useState)(false);
	const [componentWidth, setComponentWidth] = (0, react.useState)(0);
	const [keyboardOpen, setKeyboardOpen] = (0, react.useState)(false);
	/**
	* 初始化 customTareOptions：若 initialValue.tare 在 tareOptionsProp 和 localStorage
	* 里均无匹配，则在列表首位插入一条还原项（不写入 localStorage）。
	*/
	const [customTareOptions, setCustomTareOptions] = (0, react.useState)(() => {
		const stored = require_utils.readCustomTares();
		if (!initialTare || initialTareValue === 0) return stored;
		const allOpts = [...tareOptionsProp.length ? tareOptionsProp : [{
			id: "none",
			label: noTareLabel,
			value: 0
		}], ...stored];
		const hasIdMatch = Boolean(initialTare.id) && allOpts.some((t) => t.id === initialTare.id);
		const hasMatch = allOpts.some((t) => t.label === initialTare.label && Math.abs(t.value - initialTareValue) < .001);
		if (hasIdMatch || hasMatch) return stored;
		return [{
			id: initialTare.id || require_utils.getRestoredTareId({
				label: initialTare.label,
				value: initialTareValue
			}),
			label: initialTare.label,
			value: initialTareValue,
			unit: initialTare.unit
		}, ...stored];
	});
	const [weightRefreshing, setWeightRefreshing] = (0, react.useState)(false);
	const [selectedMode, setSelectedMode] = (0, react.useState)(initialMode);
	/**
	* 编辑态（有 initialValue）挂载时不自动读秤：
	* - 先展示上次保存的 weight 快照
	* - 用户点击 re-read 后再启动监听，切换到实时读数
	* 新建态保持原行为：挂载即自动读秤。
	*/
	const isEditMode = initialValue != null;
	const [autoReadingStarted, setAutoReadingStarted] = (0, react.useState)(!isEditMode);
	const frozenWeight = Number((_initialValue$weight = initialValue === null || initialValue === void 0 ? void 0 : initialValue.weight) !== null && _initialValue$weight !== void 0 ? _initialValue$weight : 0);
	/** 当前商品+规格的皮重偏好 key，无 scalePriceProduct 时为 undefined。 */
	const productTareKey = (scalePriceProduct === null || scalePriceProduct === void 0 ? void 0 : scalePriceProduct.id) ? require_utils.getProductTareKey(scalePriceProduct.id, scalePriceProduct.variant_id) : void 0;
	/** 用于检测 productTareKey 变化（variant 切换），跳过首次挂载。 */
	const productTareKeyRef = (0, react.useRef)(void 0);
	/**
	* 初始化选中的 tare ID：
	* - 无 initialTare（未传 initialValue 或其 tare 为空）→ undefined，由后续同步 effect 选中第一个选项
	* - value 为 0 → 'none'
	* - 在 baseOpts 中按 label + value 匹配 → 使用该选项的 id
	* - 无匹配 → 使用确定性还原 ID（与 customTareOptions 插入的 ID 一致）
	*/
	const [selectedTare, setSelectedTare] = (0, react.useState)(() => {
		if (!initialTare) {
			if (scalePriceProduct === null || scalePriceProduct === void 0 ? void 0 : scalePriceProduct.id) {
				const key = require_utils.getProductTareKey(scalePriceProduct.id, scalePriceProduct.variant_id);
				const map = require_utils.readProductTareMap();
				if (map[key]) return map[key];
			}
			return require_utils.readDefaultTareId();
		}
		if (initialTareValue === 0) return "none";
		const baseOpts = tareOptionsProp.length ? tareOptionsProp : [{
			id: "none",
			label: noTareLabel,
			value: 0
		}];
		const stored = require_utils.readCustomTares();
		const allOpts = [...baseOpts, ...stored];
		const matchById = initialTare.id ? allOpts.find((t) => t.id === initialTare.id) : void 0;
		if (matchById) return matchById.id;
		const matchByLabelValue = allOpts.find((t) => t.label === initialTare.label && Math.abs(t.value - initialTareValue) < .001);
		return matchByLabelValue ? matchByLabelValue.id : initialTare.id || require_utils.getRestoredTareId({
			label: initialTare.label,
			value: initialTareValue
		});
	});
	const [manualWeight, setManualWeight] = (0, react.useState)(initialManualWeight);
	const tareOptions = (0, react.useMemo)(() => {
		const noneOption = {
			id: "none",
			label: noTareLabel,
			value: 0
		};
		const optionMap = /* @__PURE__ */ new Map();
		[
			noneOption,
			...tareOptionsProp,
			...customTareOptions
		].forEach((item) => {
			if (!optionMap.has(item.id)) optionMap.set(item.id, item);
		});
		return Array.from(optionMap.values());
	}, [
		customTareOptions,
		noTareLabel,
		tareOptionsProp
	]);
	const customTareIdSet = (0, react.useMemo)(() => new Set(customTareOptions.map((item) => item.id)), [customTareOptions]);
	/**
	* 将 TareOption 换算到系统称重单位（scaleUnit）。
	* 选项单位可能和 scaleUnit 不同（历史数据 / 跨单位迁移），统一走外部 convertWeight。
	*/
	const convertTareValue = (0, react.useCallback)((option) => {
		var _option$unit;
		const fromUnit = (_option$unit = option.unit) !== null && _option$unit !== void 0 ? _option$unit : scaleUnit;
		if (!option.value) return 0;
		const result = convertWeight(option.value, fromUnit, scaleUnit);
		return result.valid ? result.value : 0;
	}, [convertWeight, scaleUnit]);
	const selectedTareOption = tareOptions.find((item) => item.id === selectedTare);
	const tareWeight = selectedTareOption ? convertTareValue(selectedTareOption) : 0;
	/**
	* 调用外部 hook 拿到硬件读数。
	* 单位换算由 useNativeScale 内部处理：
	* - 传入的 unit / tareWeight 为系统称重单位（scaleUnit）
	* - 返回的 grossWeight / netWeight 也是 scaleUnit，直接用
	* autoStart 为 true：组件挂载后立刻开始监听；卸载由 hook 自行清理。
	*/
	const scale = useNativeScale({
		unit: scaleUnit,
		precision: WEIGHT_PRECISION,
		tareWeight,
		autoStart: autoReadingStarted
	});
	/**
	* hook 的 tareWeight / unit 只在 useState initializer 里读一次，
	* 运行时只能通过 updateParams 同步。否则皮重、单位切换后 scale.netWeight 会用旧值。
	*/
	(0, react.useEffect)(() => {
		scale.updateParams({
			tareWeight,
			unit: scaleUnit
		});
	}, [
		scale.updateParams,
		scaleUnit,
		tareWeight
	]);
	/**
	* 只有 hook 真正收到过一帧数据后，才认为实时读数可用；否则继续沿用冻结值。
	* 这样可以避免「点 re-read 瞬间 scale.grossWeight 还是 0」导致 onChange 吐出 weight=0
	* 把父组件已保存的快照覆盖掉。
	*/
	const hasLiveData = scale.rawData != null;
	/**
	* auto 模式下的源重量：
	* - 已启动读数且收到首帧 → 取 hook 毛重（实时、按精度规整）
	* - 其余（未启动 / 启动但首帧未到） → 用 initialValue.weight 冻结展示
	* manual 模式：始终由手动输入决定，硬件值忽略。
	*/
	const sourceWeight = selectedMode === "manual" ? Number(manualWeight || 0) : autoReadingStarted && hasLiveData ? scale.grossWeight : frozenWeight;
	const netWeight = selectedMode === "manual" ? Math.max(Number(manualWeight || 0) - tareWeight, 0) : autoReadingStarted && hasLiveData ? scale.netWeight : Math.max(frozenWeight - tareWeight, 0);
	/**
	* 称重计价：
	* - product 形状直接对齐 nativeScaleTools.calculateScaleItemTotal 的入参
	* - finalPrice 基于当前 netWeight 计算
	* - displayUnitPrice 复用同一工具计算「1 个 scaleUnit 的价格」，避免手写换算
	*/
	const product = (0, react.useMemo)(() => {
		var _scalePriceProduct$un, _scalePriceProduct$un2, _scalePriceProduct$pr;
		return {
			unit: (_scalePriceProduct$un = scalePriceProduct === null || scalePriceProduct === void 0 ? void 0 : scalePriceProduct.unit) !== null && _scalePriceProduct$un !== void 0 ? _scalePriceProduct$un : scaleUnit,
			unit_value: (_scalePriceProduct$un2 = scalePriceProduct === null || scalePriceProduct === void 0 ? void 0 : scalePriceProduct.unit_value) !== null && _scalePriceProduct$un2 !== void 0 ? _scalePriceProduct$un2 : 1,
			price: (_scalePriceProduct$pr = scalePriceProduct === null || scalePriceProduct === void 0 ? void 0 : scalePriceProduct.price) !== null && _scalePriceProduct$pr !== void 0 ? _scalePriceProduct$pr : 0
		};
	}, [scalePriceProduct, scaleUnit]);
	/**
	* 统一的总价计算入口：给定 scaleUnit 下的重量，得到 calculateScaleItemTotal 计算后的金额。
	* 无效结果统一回落 0，避免散落 `.valid ? .totalPrice : 0` 判断。
	*/
	const computeTotalPrice = (0, react.useCallback)((weightInScaleUnit) => {
		const result = calculateScaleItemTotal({
			netWeight: weightInScaleUnit,
			unit: scaleUnit,
			precision: WEIGHT_PRECISION
		}, product);
		return result.valid ? result.totalPrice : 0;
	}, [
		calculateScaleItemTotal,
		product,
		scaleUnit
	]);
	const finalPrice = (0, react.useMemo)(() => computeTotalPrice(netWeight), [computeTotalPrice, netWeight]);
	const displayUnitPrice = (0, react.useMemo)(() => computeTotalPrice(1), [computeTotalPrice]);
	const manualWeightMax = (0, react.useMemo)(() => {
		const result = convertWeight(MAX_RETAIL_SCALE_WEIGHT_KG, "KILOGRAMS", scaleUnit);
		return result.valid ? result.value : MAX_RETAIL_SCALE_WEIGHT_KG;
	}, [convertWeight, scaleUnit]);
	const scaleFactor = Math.max(.5, Math.min((componentWidth || 360) / 420, 1));
	const compactPadding = Math.max(4, Math.round(12 * scaleFactor));
	const compactRadius = Math.max(4, Math.round(18 * scaleFactor));
	const compactGap = Math.max(4, Math.round(12 * scaleFactor));
	const compactInputRadius = Math.max(4, Math.round(12 * scaleFactor));
	const connectionDotClass = scale.isListening && !scale.error ? "pisell-sku-detail-weighing__connection-dot--connected" : "pisell-sku-detail-weighing__connection-dot--error";
	/**
	* 秤异常 / 超载只在 auto 模式下提示：
	* - manual 模式用户手动录入，秤状态与结果无关，提示反而会误导；
	* - error 优先级高于 overload（error 说明连 read 都失败了，更严重）。
	*/
	const scaleHasError = Boolean(scale.error);
	const scaleOverloaded = scale.status === "overload";
	const showScaleAlert = selectedMode === "auto" && (scaleHasError || scaleOverloaded);
	const modeDescription = (() => {
		if (selectedMode === "manual") return getText("pisell2.text.sku.detail.modal.weighing.mode.desc.manual", "Manual entry");
		if (scaleHasError) return getText("pisell2.text.sku.detail.modal.weighing.mode.desc.error", "Scale error");
		if (scaleOverloaded) return getText("pisell2.text.sku.detail.modal.weighing.mode.desc.overload", "Scale overload");
		/**
		* auto 模式下未在监听（编辑态首屏、点了停止、或启动失败）时提示「已暂停」，
		* 搭配 Weight 卡片的 re-read 提示一起，告诉用户此刻屏幕上的是冻结值而不是实时读数。
		*/
		if (!scale.isListening) return getText("pisell2.text.sku.detail.modal.weighing.mode.desc.paused", "Paused");
		return getText("pisell2.text.sku.detail.modal.weighing.mode.desc.auto", "Scale reading");
	})();
	const componentStyle = {
		"--weighing-scale": String(scaleFactor),
		"--weighing-padding": `${compactPadding}px`,
		"--weighing-radius": `${compactRadius}px`,
		"--weighing-gap": `${compactGap}px`,
		"--weighing-input-radius": `${compactInputRadius}px`
	};
	const metricsGridParams = (0, react.useMemo)(() => ({
		containerWidth: Math.max(componentWidth - compactPadding * 2, 0),
		gap: compactGap
	}), [
		compactGap,
		compactPadding,
		componentWidth
	]);
	const metricsColumns = (0, react.useMemo)(() => require_grid.getWeighingMetricGridColumns(metricsGridParams), [metricsGridParams]);
	const metricsGridStyle = (0, react.useMemo)(() => require_grid.getWeighingMetricGridStyle(metricsGridParams), [metricsGridParams]);
	/** metrics 未能展开为单行（4 列）时，chip 隐藏重量值以节省空间。 */
	const isTareBarCompact = metricsColumns < 4;
	(0, react.useEffect)(() => {
		const element = rootRef.current;
		if (!element) return;
		const updateWidth = () => {
			setComponentWidth(element.getBoundingClientRect().width);
		};
		updateWidth();
		const observer = new ResizeObserver(updateWidth);
		observer.observe(element);
		return () => {
			observer.disconnect();
		};
	}, []);
	(0, react.useEffect)(() => {
		if (typeof window === "undefined") return;
		window.localStorage.setItem(require_utils.CUSTOM_TARE_STORAGE_KEY, JSON.stringify(customTareOptions));
	}, [customTareOptions]);
	(0, react.useEffect)(() => {
		if (typeof window === "undefined" || !selectedTare) return;
		window.localStorage.setItem(require_utils.DEFAULT_TARE_STORAGE_KEY, selectedTare);
	}, [selectedTare]);
	(0, react.useEffect)(() => {
		if (!tareOptions.some((item) => item.id === selectedTare)) {
			var _tareOptions$;
			setSelectedTare(((_tareOptions$ = tareOptions[0]) === null || _tareOptions$ === void 0 ? void 0 : _tareOptions$.id) || "none");
		}
	}, [selectedTare, tareOptions]);
	(0, react.useEffect)(() => {
		const prevKey = productTareKeyRef.current;
		productTareKeyRef.current = productTareKey;
		if (prevKey === void 0 || prevKey === productTareKey || isEditMode || !productTareKey) return;
		const savedTareId = require_utils.readProductTareMap()[productTareKey];
		if (savedTareId) setSelectedTare(savedTareId);
	}, [productTareKey, isEditMode]);
	(0, react.useEffect)(() => {
		if (!selectedTare || !productTareKey) return;
		require_utils.saveProductTarePref(productTareKey, selectedTare);
	}, [selectedTare, productTareKey]);
	(0, react.useEffect)(() => {
		var _selectedTareOption$l;
		const _value = {
			mode: selectedMode,
			weight: formatOutputWeight(sourceWeight),
			tare: {
				id: selectedTareOption === null || selectedTareOption === void 0 ? void 0 : selectedTareOption.id,
				label: (_selectedTareOption$l = selectedTareOption === null || selectedTareOption === void 0 ? void 0 : selectedTareOption.label) !== null && _selectedTareOption$l !== void 0 ? _selectedTareOption$l : getText("pisell2.text.sku.detail.modal.weighing.none.tare", "No Tare"),
				value: formatOutputWeight(tareWeight),
				unit: scaleUnit
			},
			net_weight: formatOutputWeight(netWeight),
			total_amount: finalPrice,
			unit: scaleUnit,
			unit_weight: formatOutputWeight(1),
			unit_price: formatOutputUnitPrice(displayUnitPrice),
			scalePriceProduct
		};
		onChange === null || onChange === void 0 || onChange(_value);
	}, [
		displayUnitPrice,
		finalPrice,
		netWeight,
		onChange,
		selectedMode,
		selectedTareOption,
		sourceWeight,
		tareWeight,
		scalePriceProduct,
		scaleUnit
	]);
	const handleTareSelect = (tareId) => {
		setSelectedTare(tareId);
		setTarePopoverOpen(false);
	};
	const handleAddCustomTare = (params) => {
		const trimmedLabel = params.label.trim();
		const normalizedLabel = trimmedLabel.toLocaleLowerCase();
		const inputValue = Number(params.value);
		if (!trimmedLabel || tareOptions.some((item) => item.label.trim().toLocaleLowerCase() === normalizedLabel) || !Number.isFinite(inputValue) || inputValue < 0 || inputValue > manualWeightMax) return false;
		const nextOption = {
			id: `custom-${Date.now()}`,
			label: trimmedLabel,
			value: inputValue,
			unit: scaleUnit
		};
		setCustomTareOptions((prev) => [...prev, nextOption]);
		setSelectedTare(nextOption.id);
		setTarePopoverOpen(false);
		return true;
	};
	const handleReRead = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			if (weightRefreshing) return;
			setWeightRefreshing(true);
			try {
				if (!autoReadingStarted) {
					setAutoReadingStarted(true);
					return;
				}
				yield scale.stopListening();
				yield scale.startListening();
			} catch (_unused) {}
		});
		return function handleReRead() {
			return _ref.apply(this, arguments);
		};
	}();
	const handleDeleteCustomTare = (tareId) => {
		setCustomTareOptions((prev) => prev.filter((item) => item.id !== tareId));
	};
	(0, react.useEffect)(() => {
		if (!weightRefreshing) return;
		const timer = window.setTimeout(() => {
			setWeightRefreshing(false);
		}, 300);
		return () => {
			window.clearTimeout(timer);
		};
	}, [weightRefreshing]);
	const handleManualKeyboardConfirm = (value) => {
		setManualWeight(require_utils.sanitizeManualWeight(value));
		setKeyboardOpen(false);
	};
	const tareManagementContent = /* @__PURE__ */ react.default.createElement(require_TareManagementPanel.TareManagementPanel, {
		componentStyle,
		tareOptions,
		selectedTare,
		customTareIdSet,
		unitLabel,
		maxTareValue: manualWeightMax,
		convertTareValue,
		getText,
		onSelectTare: handleTareSelect,
		onDeleteCustomTare: handleDeleteCustomTare,
		onAddCustomTare: handleAddCustomTare
	});
	const modeSwitcher = /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__mode-switcher" }, /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		onClick: () => setSelectedMode("auto"),
		className: `pisell-sku-detail-weighing__mode-tab${selectedMode === "auto" ? " pisell-sku-detail-weighing__mode-tab--active" : ""}`,
		"aria-pressed": selectedMode === "auto"
	}, getText("pisell2.text.sku.detail.modal.weighing.mode.auto", "Auto")), /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		onClick: () => setSelectedMode("manual"),
		className: `pisell-sku-detail-weighing__mode-tab${selectedMode === "manual" ? " pisell-sku-detail-weighing__mode-tab--active" : ""}`,
		"aria-pressed": selectedMode === "manual"
	}, getText("pisell2.text.sku.detail.modal.weighing.mode.manual", "Manual")));
	const weightIcon = selectedMode === "auto" ? /* @__PURE__ */ react.default.createElement("span", { className: weightRefreshing ? "pisell-sku-detail-weighing__icon--spinning" : void 0 }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
		type: "pisell2-refresh-cw-05",
		size: 18
	})) : null;
	const tareIcon = /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
		type: "pisell2-switch-horizontal-01",
		size: 18
	});
	const manualWeightMetricCard = /* @__PURE__ */ react.default.createElement(MetricCard, {
		label: getText("pisell2.text.sku.detail.modal.weighing.metric.weight", "Weight"),
		value: require_utils.formatWeight(sourceWeight),
		unit: unitLabel,
		description: selectedMode === "auto" ? getText("pisell2.text.sku.detail.modal.weighing.metric.weight.desc.auto", "click to re-read") : void 0,
		highlight: true,
		editable: selectedMode === "manual",
		icon: weightIcon,
		onCardClick: selectedMode === "auto" ? handleReRead : void 0
	});
	return /* @__PURE__ */ react.default.createElement("div", {
		ref: rootRef,
		style: componentStyle,
		className: `pisell-sku-detail-weighing pisell-sku-detail-weighing--${selectedMode}`
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__header" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__header-main" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__title-row" }, /* @__PURE__ */ react.default.createElement("span", { className: `pisell-sku-detail-weighing__connection-dot ${connectionDotClass}` }), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__title" }, getText("pisell2.text.sku.detail.modal.weighing.title", "Weighing"))), /* @__PURE__ */ react.default.createElement("div", { className: `pisell-sku-detail-weighing__subtitle${showScaleAlert ? " pisell-sku-detail-weighing__subtitle--error" : ""}` }, modeDescription)), modeSwitcher), /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-sku-detail-weighing__metrics",
		style: metricsGridStyle
	}, /* @__PURE__ */ react.default.createElement(MetricCard, {
		label: getText("pisell2.text.sku.detail.modal.weighing.metric.unit.price", "Unit Price"),
		value: require_utils.formatMoney(displayUnitPrice, currencySymbol),
		unit: `/${unitLabel}`
	}), selectedMode === "manual" ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		originalValue: manualWeight,
		defaultValue: manualWeight,
		mode: "decimal",
		min: 0,
		max: manualWeightMax,
		precision: 3,
		onEnter: handleManualKeyboardConfirm,
		containerProps: {
			className: "pisell-sku-detail-weighing__keyboard-popover",
			renderType: "popover",
			placement: "right",
			open: keyboardOpen,
			onOpenChange: setKeyboardOpen
		}
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__popover-trigger" }, manualWeightMetricCard)) : manualWeightMetricCard, /* @__PURE__ */ react.default.createElement(antd.Popover, {
		trigger: "click",
		placement: "bottomRight",
		open: tarePopoverOpen,
		content: tareManagementContent,
		overlayClassName: "pisell-sku-detail-weighing__popover",
		onOpenChange: setTarePopoverOpen
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__popover-trigger" }, /* @__PURE__ */ react.default.createElement(MetricCard, {
		label: getText("pisell2.text.sku.detail.modal.weighing.metric.tare", "Tare"),
		value: require_utils.formatWeight(tareWeight),
		unit: unitLabel,
		description: selectedTareOption && selectedTareOption.id !== "none" ? selectedTareOption.label : getText("pisell2.text.sku.detail.modal.weighing.metric.tare.desc", "click to change"),
		icon: tareIcon
	}))), /* @__PURE__ */ react.default.createElement(MetricCard, {
		label: getText("pisell2.text.sku.detail.modal.weighing.metric.net.weight", "Net Weight"),
		value: require_utils.formatWeight(netWeight),
		unit: unitLabel
	})), /* @__PURE__ */ react.default.createElement(require_TareManagementPanel.TareQuickBar, {
		options: tareOptions,
		selected: selectedTare,
		compact: isTareBarCompact,
		unitLabel,
		convertTareValue,
		onSelect: handleTareSelect
	}));
};
function MetricCard(props) {
	const { label, value, unit, description, highlight = false, editable = false, icon, onCardClick } = props;
	const interactive = Boolean(onCardClick);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `pisell-sku-detail-weighing__metric-card${highlight ? " pisell-sku-detail-weighing__metric-card--highlight" : ""}${interactive ? " pisell-sku-detail-weighing__metric-card--interactive" : ""}`,
		onClick: onCardClick,
		onKeyDown: (event) => {
			if (!interactive) return;
			if (event.key === "Enter" || event.key === " ") {
				event.preventDefault();
				onCardClick === null || onCardClick === void 0 || onCardClick();
			}
		},
		role: interactive ? "button" : void 0,
		tabIndex: interactive ? 0 : void 0
	}, icon ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-sku-detail-weighing__metric-icon",
		"aria-hidden": "true"
	}, icon) : null, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__metric-top" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__metric-label" }, label), description ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sku-detail-weighing__metric-description" }, description) : null), /* @__PURE__ */ react.default.createElement("div", { className: `pisell-sku-detail-weighing__metric-value-row${editable ? " pisell-sku-detail-weighing__metric-value-row--editable" : ""}` }, /* @__PURE__ */ react.default.createElement("span", { className: `pisell-sku-detail-weighing__metric-value${editable ? " pisell-sku-detail-weighing__metric-value--editable" : ""}` }, /* @__PURE__ */ react.default.createElement(_pisell_materials.AutoResizeText, null, value)), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-sku-detail-weighing__metric-unit" }, unit)));
}
//#endregion
exports.default = Weighing;
