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/components/productSelect/components/productGroup/index.tsx
var productGroup_exports = {};
__export(productGroup_exports, {
  ProductGroupSkeleton: () => ProductGroupSkeleton,
  default: () => productGroup_default
});
module.exports = __toCommonJS(productGroup_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_gridLayout = __toESM(require("../gridLayout"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_decimal = __toESM(require("decimal.js"));
var import_index = require("./index.less");
var import_pisellPriceText = __toESM(require("../pisellPriceText"));
var ProductGroup = ({
  data,
  layout = { grid: false },
  onSelectProduct,
  currentProductId,
  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 _products = (0, import_react.useMemo)(() => {
    const { products } = data;
    return products;
  }, [data]);
  const getStockText = (item) => {
    if (item.is_track === 0) {
      return false;
    }
    return `${import_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 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 renderItem = (item) => /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("product-card", {
        selected: currentProductId && item.id === currentProductId
      }),
      onClick: () => {
        console.log("进入 renderItem onClick");
        onSelectProduct == null ? void 0 : onSelectProduct(item);
      }
    },
    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),
          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))
  );
  return /* @__PURE__ */ import_react.default.createElement("div", { "data-section": data.id, className: "pisell-product-select-group" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "group-title" }, data.name), /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "16px 0" } }, (layout == null ? void 0 : layout.grid) && layout.config ? /* @__PURE__ */ import_react.default.createElement(
    import_gridLayout.default,
    {
      gridConfig: layout.config,
      items: _products,
      renderItem
    }
  ) : /* @__PURE__ */ import_react.default.createElement("div", { className: "group-row" }, _products.map((item) => renderItem(item)))));
};
var ProductGroupSkeleton = ({ layout }) => {
  const renderItem = () => /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("product-card") }, /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton.Image, { active: true, style: { width: 180, height: 126 } }), /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { active: true, paragraph: { rows: 2 } }));
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-product-select-group" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton.Input, { active: true, size: "small", block: false }), /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "16px 0" } }, (layout == null ? void 0 : layout.grid) && layout.config ? /* @__PURE__ */ import_react.default.createElement(
    import_gridLayout.default,
    {
      gridConfig: layout.config,
      items: [1, 2],
      renderItem
    }
  ) : /* @__PURE__ */ import_react.default.createElement("div", { className: "group-row" }, [1, 2, 3].map((item) => renderItem()))));
};
var productGroup_default = ProductGroup;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ProductGroupSkeleton
});
