import { _objectSpread2 } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { PREFIX } from "../../status.js";
import React, { useCallback, useMemo } from "react";
import { PisellTags } from "@pisell/materials";
import "./index.less";
//#region src/plus/productSelect/ProductCard/SkuCard/components/Promotions/index.tsx
const Promotions = ({ props }) => {
	const { dataSource, skuTextConfig } = props;
	const { isOpen, marginX, isShowAll, maxCount, lists } = (skuTextConfig === null || skuTextConfig === void 0 ? void 0 : skuTextConfig.skuPromotionsConfig) || {};
	if (!isOpen) return null;
	const listsData = useMemo(() => {
		var _dataSource$promotion;
		return ((dataSource === null || dataSource === void 0 || (_dataSource$promotion = dataSource.promotions) === null || _dataSource$promotion === void 0 ? void 0 : _dataSource$promotion.length) ? dataSource === null || dataSource === void 0 ? void 0 : dataSource.promotions : lists) || [];
	}, [dataSource === null || dataSource === void 0 ? void 0 : dataSource.promotions, lists]);
	/**
	* @title: 文本样式
	* @description:
	* @param {*} useCallback
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-10 11:27
	*/
	const textStyle = useCallback((tag) => {
		return {
			fontSize: tag.fontSize,
			fontWeight: tag.fontWeight,
			color: tag.color
		};
	}, []);
	/**
	* @title: 促销信息样式
	* @description:
	* @param {*} useCallback
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-10 11:27
	*/
	const tagStyle = useCallback((tag) => {
		return {
			background: tag.background,
			padding: `${tag.paddingY}px ${tag.paddingX}px`,
			borderRadius: tag.radius,
			border: tag.isBorder ? `${tag.borderWidth}px solid ${tag.borderColor}` : "none",
			margin: 0,
			lineHeight: "18px"
		};
	}, [marginX]);
	/**
	* @title: 处理促销信息数据
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-11 10:59
	*/
	const listsResult = useMemo(() => {
		if (isShowAll) return listsData;
		return listsData.slice(0, maxCount);
	}, [
		listsData,
		isShowAll,
		maxCount
	]);
	if (listsData.length === 0) return null;
	return /* @__PURE__ */ React.createElement("div", {
		className: `${PREFIX}__card-promotions`,
		style: { gap: `${marginX}px` }
	}, listsResult.map((tag, tagIndex) => /* @__PURE__ */ React.createElement(PisellTags, _objectSpread2({
		key: tagIndex,
		style: _objectSpread2({}, tagStyle(tag))
	}, tag.props), /* @__PURE__ */ React.createElement("span", { style: textStyle(tag) }, tag === null || tag === void 0 ? void 0 : tag.title))), (listsData === null || listsData === void 0 ? void 0 : listsData.length) > listsResult.length && /* @__PURE__ */ React.createElement("div", { className: `pisell-product-sku__card-tags-remaining` }, "+", (listsData === null || listsData === void 0 ? void 0 : listsData.length) - listsResult.length));
};
//#endregion
export { Promotions as default };
