const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_IntersectionObserver = require("../components/IntersectionObserver.js");
const require_index = require("../components/pisellPriceText/index.js");
require("./ProductCardSkeleton.js");
const require_index$1 = require("../index.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);
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/plus/productSelect/ProductCard/index.tsx
const defaultConfig = {
	isProductCover: 1,
	imgWidth: "180px",
	imgHeight: "126px",
	radius: 8,
	isTitle: 1,
	isSubtitle: 0,
	showSpec: true,
	isTag: 0,
	isPrice: 0,
	isOriginPrice: 0,
	showZeroPrice: false,
	showMarketingTag: true,
	showRemark: true,
	isStock: 0
};
const ProductCard = (0, react.memo)(({ item, index: index$1, context, onSelect, onSelectCover, onSelectInfo, isSelected, className, decorateConfig = {} }) => {
	const { imgHeight, imgWidth, isOriginPrice, isPrice, isProductCover, isStock, isSubtitle, isTitle, radius, showZeroPrice } = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, defaultConfig), decorateConfig);
	const { __typename } = item;
	if (__typename === "category") return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)(`${require_index$1.PREFIX}__product-category`, className),
		"data-index": index$1,
		"data-item-index": index$1
	}, /* @__PURE__ */ react.default.createElement("div", { className: "category-title" }, item.name));
	const getStockText = (item) => {
		if (item.is_track === 0) return false;
		return `${_pisell_utils.locales.getText("pisell2.product-select.stock")}：${item.stock_quantity}`;
	};
	const getTextCover = (title) => {
		if (!title) return "";
		const cleanTitle = title.trim();
		if (cleanTitle.length === 0) return "";
		return cleanTitle.substring(0, 2).toUpperCase();
	};
	const renderPrice = (item) => {
		const { price: _price, original_price: _original_price, is_bundle, minimum_markup_price } = item;
		let price = _price;
		let original_price = _original_price;
		if (is_bundle) {
			price = new decimal_js.default(price).plus(new decimal_js.default(minimum_markup_price)).toFixed(2);
			original_price = new decimal_js.default(original_price).plus(new decimal_js.default(minimum_markup_price)).toFixed(2);
		}
		if (!showZeroPrice && !parseFloat(price)) return null;
		return !!isPrice || !!isOriginPrice ? /* @__PURE__ */ react.default.createElement("div", { className: "price-info" }, isPrice ? /* @__PURE__ */ react.default.createElement("div", { className: "price" }, /* @__PURE__ */ react.default.createElement(require_index.default, {
			value: price,
			isMini: is_bundle
		})) : null, !!isOriginPrice && parseFloat(original_price) ? /* @__PURE__ */ react.default.createElement("div", { className: "original-price" }, /* @__PURE__ */ react.default.createElement(require_index.default, {
			value: original_price,
			isMini: is_bundle
		})) : null) : null;
	};
	const cardContent = /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)(`${require_index$1.PREFIX}__product-card`, className, { selected: isSelected }),
		onPointerUp: () => {
			onSelect === null || onSelect === void 0 || onSelect(item);
		},
		"data-index": index$1,
		"data-item-index": index$1
	}, isProductCover ? /* @__PURE__ */ react.default.createElement("div", {
		className: "card-left",
		style: {
			width: imgWidth || "auto",
			height: imgHeight || "auto"
		},
		onClick: () => {
			onSelectCover === null || onSelectCover === void 0 || onSelectCover(item);
		}
	}, item.cover ? /* @__PURE__ */ react.default.createElement("img", {
		loading: "lazy",
		src: _pisell_utils.image.ali(item.cover, 360),
		alt: item.title,
		style: { borderRadius: radius }
	}) : /* @__PURE__ */ react.default.createElement("div", {
		className: "text-cover",
		style: { borderRadius: radius }
	}, getTextCover(item.title))) : null, /* @__PURE__ */ react.default.createElement("div", {
		className: "card-right",
		onClick: () => {
			onSelectInfo === null || onSelectInfo === void 0 || onSelectInfo(item);
		}
	}, !!isTitle ? /* @__PURE__ */ react.default.createElement("div", { className: "title" }, item.title) : null, !!isSubtitle && item.subtitle ? /* @__PURE__ */ react.default.createElement("div", { className: "subtitle" }, item.subtitle) : null, !!isStock && !!item.is_track ? /* @__PURE__ */ react.default.createElement("div", { className: "stock" }, getStockText(item)) : null, renderPrice(item)));
	if (context) return /* @__PURE__ */ react.default.createElement(require_IntersectionObserver.IntersectionTrigger, { onShow: () => context.onItemIntersectionIn(item) }, cardContent);
	return cardContent;
});
ProductCard.displayName = "ProductCard";
const DefaultItemContent = (0, react.memo)((props) => {
	return /* @__PURE__ */ react.default.createElement(ProductCard, props);
});
DefaultItemContent.displayName = "DefaultItemContent";
//#endregion
exports.default = ProductCard;
