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/ProductCardV2.tsx
var ProductCardV2_exports = {};
__export(ProductCardV2_exports, {
  default: () => ProductCardV2_default
});
module.exports = __toCommonJS(ProductCardV2_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_IntersectionObserver = require("../components/IntersectionObserver");
var import__ = require("../index");
var import_pisellSalesProductCard = __toESM(require("../../pisellSalesProductCard"));
var ProductCardV2 = (0, import_react.memo)(
  ({
    item,
    index,
    context,
    className,
    value,
    onChange,
    decorateConfig = {},
    cartElementId
  }) => {
    var _a, _b, _c, _d, _e;
    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 itemValue = (() => {
      const targetProductId = (item == null ? void 0 : item.product_id) ?? (item == null ? void 0 : item.id);
      const products = Array.isArray(value) ? value : [];
      return products.find((v) => {
        return String((v == null ? void 0 : v.product_id) ?? "") === String(targetProductId ?? "");
      });
    })();
    const cardContent = /* @__PURE__ */ import_react.default.createElement("div", { "data-product-id": String((item == null ? void 0 : item.product_id) ?? (item == null ? void 0 : item.id) ?? "") }, /* @__PURE__ */ import_react.default.createElement(
      import_pisellSalesProductCard.default,
      {
        product: item,
        stepperProps: {
          min: (_a = item == null ? void 0 : item.item_rule_limit) == null ? void 0 : _a.min,
          max: (_b = item == null ? void 0 : item.item_rule_limit) == null ? void 0 : _b.remainingMax,
          limitMessage: {
            max: ((_c = item == null ? void 0 : item.item_rule_limit) == null ? void 0 : _c.maxValidationMessage) ?? ((_d = item == null ? void 0 : item.item_rule_limit) == null ? void 0 : _d.validationMessage),
            min: (_e = item == null ? void 0 : item.item_rule_limit) == null ? void 0 : _e.minValidationMessage
          }
        },
        value: itemValue,
        skuCardConfig: {
          image: {
            width: decorateConfig == null ? void 0 : decorateConfig.imgWidth,
            height: decorateConfig == null ? void 0 : decorateConfig.imgHeight
          }
        },
        cartElementId,
        onClick: (nextValue, meta) => {
          onChange == null ? void 0 : onChange(nextValue, meta.intent, meta);
        },
        onChange: (nextValue, meta) => {
          onChange == null ? void 0 : onChange(nextValue, meta.intent, meta);
        }
      }
    ));
    if (context) {
      return /* @__PURE__ */ import_react.default.createElement(import_IntersectionObserver.IntersectionTrigger, { onShow: () => context.onItemIntersectionIn(item) }, cardContent);
    }
    return cardContent;
  }
);
ProductCardV2.displayName = "ProductCardV2";
var ProductCardV2_default = ProductCardV2;
