import { PREFIX } from "../../status.js";
import Favorite from "../Favorite/index.js";
import React, { useMemo } from "react";
import { image } from "@pisell/utils";
import "./index.less";
//#region src/plus/productSelect/ProductCard/SkuCard/components/Cover/index.tsx
const Cover = ({ props }) => {
	const { dataSource, skuImageConfig } = props;
	const { isCover, width, height, radius, isTextFallback, background } = skuImageConfig || {};
	if (!isCover) return null;
	if (!(dataSource === null || dataSource === void 0 ? void 0 : dataSource.cover) && !isTextFallback) return null;
	const getTextCover = (title) => {
		if (!(dataSource === null || dataSource === void 0 ? void 0 : dataSource.title)) return "";
		const cleanTitle = title.trim();
		if (cleanTitle.length === 0) return "";
		return cleanTitle.substring(0, 2).toUpperCase();
	};
	const finalStyle = useMemo(() => {
		return {
			borderRadius: radius,
			background
		};
	}, [radius, background]);
	return /* @__PURE__ */ React.createElement("div", { className: `${PREFIX}__card-cover` }, /* @__PURE__ */ React.createElement("div", {
		className: `${PREFIX}__card-cover-image`,
		style: {
			width: `${width}` || "auto",
			height: `${height}` || "auto"
		}
	}, (dataSource === null || dataSource === void 0 ? void 0 : dataSource.cover) ? /* @__PURE__ */ React.createElement("img", {
		loading: "lazy",
		src: image.ali(dataSource === null || dataSource === void 0 ? void 0 : dataSource.cover, 360),
		alt: dataSource === null || dataSource === void 0 ? void 0 : dataSource.title,
		style: finalStyle
	}) : /* @__PURE__ */ React.createElement("div", {
		className: `${PREFIX}__card-cover-text`,
		style: finalStyle
	}, getTextCover((dataSource === null || dataSource === void 0 ? void 0 : dataSource.title) || "")), /* @__PURE__ */ React.createElement(Favorite, { props })));
};
//#endregion
export { Cover as default };
