import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { IntersectionTrigger } from "../components/IntersectionObserver.js";
import index from "../components/pisellPriceText/index.js";
import "./ProductCardSkeleton.js";
import { PREFIX } from "../index.js";
import React, { memo } from "react";
import { image, locales } from "@pisell/utils";
import Decimal from "decimal.js";
import classNames from "classnames";
import "./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 = memo(({ item, index: index$1, context, onSelect, onSelectCover, onSelectInfo, isSelected, className, decorateConfig = {} }) => {
	const { imgHeight, imgWidth, isOriginPrice, isPrice, isProductCover, isStock, isSubtitle, isTitle, radius, showZeroPrice } = _objectSpread2(_objectSpread2({}, defaultConfig), decorateConfig);
	const { __typename } = item;
	if (__typename === "category") return /* @__PURE__ */ React.createElement("div", {
		className: classNames(`${PREFIX}__product-category`, className),
		"data-index": index$1,
		"data-item-index": index$1
	}, /* @__PURE__ */ React.createElement("div", { className: "category-title" }, item.name));
	const getStockText = (item) => {
		if (item.is_track === 0) return false;
		return `${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(price).plus(new Decimal(minimum_markup_price)).toFixed(2);
			original_price = new Decimal(original_price).plus(new Decimal(minimum_markup_price)).toFixed(2);
		}
		if (!showZeroPrice && !parseFloat(price)) return null;
		return !!isPrice || !!isOriginPrice ? /* @__PURE__ */ React.createElement("div", { className: "price-info" }, isPrice ? /* @__PURE__ */ React.createElement("div", { className: "price" }, /* @__PURE__ */ React.createElement(index, {
			value: price,
			isMini: is_bundle
		})) : null, !!isOriginPrice && parseFloat(original_price) ? /* @__PURE__ */ React.createElement("div", { className: "original-price" }, /* @__PURE__ */ React.createElement(index, {
			value: original_price,
			isMini: is_bundle
		})) : null) : null;
	};
	const cardContent = /* @__PURE__ */ React.createElement("div", {
		className: classNames(`${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.createElement("div", {
		className: "card-left",
		style: {
			width: imgWidth || "auto",
			height: imgHeight || "auto"
		},
		onClick: () => {
			onSelectCover === null || onSelectCover === void 0 || onSelectCover(item);
		}
	}, item.cover ? /* @__PURE__ */ React.createElement("img", {
		loading: "lazy",
		src: image.ali(item.cover, 360),
		alt: item.title,
		style: { borderRadius: radius }
	}) : /* @__PURE__ */ React.createElement("div", {
		className: "text-cover",
		style: { borderRadius: radius }
	}, getTextCover(item.title))) : null, /* @__PURE__ */ React.createElement("div", {
		className: "card-right",
		onClick: () => {
			onSelectInfo === null || onSelectInfo === void 0 || onSelectInfo(item);
		}
	}, !!isTitle ? /* @__PURE__ */ React.createElement("div", { className: "title" }, item.title) : null, !!isSubtitle && item.subtitle ? /* @__PURE__ */ React.createElement("div", { className: "subtitle" }, item.subtitle) : null, !!isStock && !!item.is_track ? /* @__PURE__ */ React.createElement("div", { className: "stock" }, getStockText(item)) : null, renderPrice(item)));
	if (context) return /* @__PURE__ */ React.createElement(IntersectionTrigger, { onShow: () => context.onItemIntersectionIn(item) }, cardContent);
	return cardContent;
});
ProductCard.displayName = "ProductCard";
const DefaultItemContent = memo((props) => {
	return /* @__PURE__ */ React.createElement(ProductCard, props);
});
DefaultItemContent.displayName = "DefaultItemContent";
//#endregion
export { ProductCard as default };
