var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/productSelect/ProductCard/index.tsx
var ProductCard_exports = {};
__export(ProductCard_exports, {
  DefaultItemContent: () => DefaultItemContent,
  ProductCard: () => ProductCard,
  ProductCardSkeleton: () => import_ProductCardSkeleton.default,
  default: () => ProductCard_default
});
module.exports = __toCommonJS(ProductCard_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_decimal = __toESM(require("decimal.js"));
var import_IntersectionObserver = require("../components/IntersectionObserver");
var import_pisellPriceText = __toESM(require("../components/pisellPriceText"));
var import_ProductCardSkeleton = __toESM(require("./ProductCardSkeleton"));
var import_index = require("./index.less");
var import__ = require("../index");
var 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
};
var ProductCard = (0, import_react.memo)(
  ({
    item,
    index,
    context,
    onSelect,
    isSelected,
    className,
    decorateConfig = {}
  }) => {
    const finalConfig = { ...defaultConfig, ...decorateConfig };
    const {
      imgHeight,
      imgWidth,
      isOriginPrice,
      isPrice,
      isProductCover,
      isStock,
      isSubtitle,
      isTitle,
      radius,
      showZeroPrice
    } = finalConfig;
    const { __typename } = item;
    if (__typename === "category") {
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)(`${import__.PREFIX}__product-category`, className),
          "data-index": index,
          "data-item-index": index
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "category-title" }, item.name)
      );
    }
    const getStockText = (item2) => {
      if (item2.is_track === 0) {
        return false;
      }
      return `${import_utils.locales.getText("pisell2.product-select.stock")}：${item2.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 = (item2) => {
      const {
        price: _price,
        original_price: _original_price,
        is_bundle,
        minimum_markup_price
      } = item2;
      let price = _price;
      let original_price = _original_price;
      if (is_bundle) {
        price = new import_decimal.default(price).plus(new import_decimal.default(minimum_markup_price)).toFixed(2);
        original_price = new import_decimal.default(original_price).plus(new import_decimal.default(minimum_markup_price)).toFixed(2);
      }
      if (!showZeroPrice && !parseFloat(price)) return null;
      return !!isPrice || !!isOriginPrice ? /* @__PURE__ */ import_react.default.createElement("div", { className: "price-info" }, isPrice ? /* @__PURE__ */ import_react.default.createElement("div", { className: "price" }, /* @__PURE__ */ import_react.default.createElement(import_pisellPriceText.default, { value: price, isMini: is_bundle })) : null, !!isOriginPrice && parseFloat(original_price) ? /* @__PURE__ */ import_react.default.createElement("div", { className: "original-price" }, /* @__PURE__ */ import_react.default.createElement(import_pisellPriceText.default, { value: original_price, isMini: is_bundle })) : null) : null;
    };
    const cardContent = /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(`${import__.PREFIX}__product-card`, className, {
          selected: isSelected
        }),
        onClick: () => {
          onSelect == null ? void 0 : onSelect(item);
        },
        "data-index": index,
        "data-item-index": index
      },
      isProductCover ? /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "card-left",
          style: {
            width: imgWidth || "auto",
            height: imgHeight || "auto"
          }
        },
        item.cover ? /* @__PURE__ */ import_react.default.createElement(
          "img",
          {
            loading: "lazy",
            src: import_utils.image.ali(item.cover, 360),
            alt: item.title,
            style: { borderRadius: radius }
          }
        ) : /* @__PURE__ */ import_react.default.createElement("div", { className: "text-cover", style: { borderRadius: radius } }, getTextCover(item.title))
      ) : null,
      /* @__PURE__ */ import_react.default.createElement("div", { className: "card-right" }, !!isTitle ? /* @__PURE__ */ import_react.default.createElement("div", { className: "title" }, item.title) : null, !!isSubtitle && item.subtitle ? /* @__PURE__ */ import_react.default.createElement("div", { className: "subtitle" }, item.subtitle) : null, !!isStock && !!item.is_track ? /* @__PURE__ */ import_react.default.createElement("div", { className: "stock" }, getStockText(item)) : null, renderPrice(item))
    );
    if (context) {
      return /* @__PURE__ */ import_react.default.createElement(
        import_IntersectionObserver.IntersectionTrigger,
        {
          onShow: () => context.onItemIntersectionIn(item)
        },
        cardContent
      );
    }
    return cardContent;
  }
);
ProductCard.displayName = "ProductCard";
var DefaultItemContent = (0, import_react.memo)(
  (props) => {
    return /* @__PURE__ */ import_react.default.createElement(ProductCard, { ...props });
  }
);
DefaultItemContent.displayName = "DefaultItemContent";
var ProductCard_default = ProductCard;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DefaultItemContent,
  ProductCard,
  ProductCardSkeleton
});
