const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_useStore = require("../../hooks/useStore.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let decimal_js = require("decimal.js");
decimal_js = require_runtime.__toESM(decimal_js);
require("./index.less");
//#region src/plus/skuOptionsSelection/components/TitleExtra/index.tsx
const TitleExtra = (props) => {
	const { values } = props || {};
	const symbol = require_useStore.default((s) => s.symbol);
	const transformText = (textKey, tag, value) => {
		return _pisell_utils.locales.getText(textKey).replace(`{{${tag}}}`, value);
	};
	const numText = (0, react.useMemo)(() => {
		let quantity = 0;
		if (Array.isArray(values)) quantity = values.reduce((sum, i) => sum + ((i === null || i === void 0 ? void 0 : i.quantity) || 0), 0) || 0;
		else quantity = (values === null || values === void 0 ? void 0 : values.quantity) || 0;
		return transformText("pisell2.skuOptionsSelection.titleExtra.alreadySelected", "num", quantity);
	}, [props === null || props === void 0 ? void 0 : props.values]);
	const priceText = (0, react.useMemo)(() => {
		let price = 0;
		if (Array.isArray(values)) price = values === null || values === void 0 ? void 0 : values.reduce((sum, i) => sum.plus((i === null || i === void 0 ? void 0 : i.totalPrice) || 0), new decimal_js.default(0)).toNumber();
		else price = Number((values === null || values === void 0 ? void 0 : values.totalPrice) || 0);
		return transformText("pisell2.skuOptionsSelection.titleExtra.totalPrice", "price", `${price >= 0 ? "" : "-"}${symbol}${Math.abs(price)}`);
	}, [values, symbol]);
	return /* @__PURE__ */ react.default.createElement("div", { className: "sku-options-selection-title-extra" }, /* @__PURE__ */ react.default.createElement("span", { className: "sku-options-selection-title-extra-price" }, priceText), /* @__PURE__ */ react.default.createElement("span", { className: "sku-options-selection-title-extra-num" }, numText));
};
//#endregion
exports.default = TitleExtra;
