import useStore_default from "../../hooks/useStore.js";
import React, { useMemo } from "react";
import { locales } from "@pisell/utils";
import Decimal from "decimal.js";
import "./index.less";
//#region src/plus/skuOptionsSelection/components/TitleExtra/index.tsx
const TitleExtra = (props) => {
	const { values } = props || {};
	const symbol = useStore_default((s) => s.symbol);
	const transformText = (textKey, tag, value) => {
		return locales.getText(textKey).replace(`{{${tag}}}`, value);
	};
	const numText = 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 = 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(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.createElement("div", { className: "sku-options-selection-title-extra" }, /* @__PURE__ */ React.createElement("span", { className: "sku-options-selection-title-extra-price" }, priceText), /* @__PURE__ */ React.createElement("span", { className: "sku-options-selection-title-extra-num" }, numText));
};
//#endregion
export { TitleExtra as default };
