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/shoppingCart/components/Cart/Product.tsx
var Product_exports = {};
__export(Product_exports, {
  default: () => Product_default
});
module.exports = __toCommonJS(Product_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_useClearCart = __toESM(require("../../hooks/useClearCart"));
var import_useContext = require("../../hooks/useContext");
var import_useAddService = __toESM(require("../../hooks/useAddService"));
var import_ahooks = require("ahooks");
var import_utils = require("../../../booking/info/service2/utils");
var import_pisellNumberSelector = __toESM(require("../../../../pro/pisellNumberSelector"));
var Product = (props) => {
  const { id, lists, isAdd = true } = props;
  const { state, onAction, onChange } = (0, import_useContext.useContext)();
  const {
    disabledEdit,
    isShowPackageNote,
    isShowNote,
    hideAddBtn,
    platform,
    isShowChangeResource,
    isShowDelete,
    isShowChangeHolder,
    isShowHolder,
    isShowAddHolderButton,
    isShowEditProduct,
    productCardStyleConfig = {}
  } = state;
  const clearCart = (0, import_useClearCart.default)(id);
  const handleChange = (0, import_ahooks.useMemoizedFn)(
    (item, type, other) => {
      if (disabledEdit && !(other == null ? void 0 : other.disabled)) return;
      onChange(item, type, other);
    }
  );
  const productParams = (0, import_react.useMemo)(() => {
    return {
      isShowNote,
      isShowPackageNote,
      disabledEdit,
      isShowChangeResource,
      isShowChangeHolder,
      isShowDelete,
      isShowHolder,
      isShowAddHolderButton,
      isShowEditProduct
    };
  }, [
    isShowNote,
    isShowPackageNote,
    disabledEdit,
    isShowChangeResource,
    isShowDelete,
    isShowHolder,
    isShowAddHolderButton,
    isShowChangeHolder,
    isShowEditProduct
  ]);
  const getProductCardStyleProps = (0, import_ahooks.useMemoizedFn)(
    (type) => {
      const conf = productCardStyleConfig[`${type}_product_card_style`];
      if (state.scenario !== "booking2") return {};
      return {
        isShowImage: conf == null ? void 0 : conf.show_product_image,
        isShowDelete: conf == null ? void 0 : conf.show_remove_button,
        disabledEdit: true
      };
    }
  );
  return (0, import_react.useMemo)(() => {
    console.log("render cart");
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__shopping-cart-content" }, clearCart, lists == null ? void 0 : lists.map((item) => {
      let Comp = import_materials.ProductCard;
      let isRetail;
      if (state.scenario === "booking2") {
        isRetail = (0, import_utils.isNormalProductByDurationSchedule)(item == null ? void 0 : item._origin);
        Comp = import_materials.ProductCard.V2;
      }
      return /* @__PURE__ */ import_react.default.createElement(
        Comp,
        {
          type: isRetail ? "a2" : "a5",
          rightActions: [
            {
              key: "update_number",
              text: /* @__PURE__ */ import_react.default.createElement(
                import_pisellNumberSelector.default,
                {
                  enablePriceAdjust: true,
                  min: 1,
                  className: "pisell-sku-card__pisell-number-setter",
                  value: item == null ? void 0 : item.num,
                  onChange: (value) => {
                    if (value < 1) {
                      handleChange(item, "num", { num: 1 });
                    } else {
                      handleChange(item, "num", { num: value });
                    }
                  }
                }
              ),
              color: "#667085"
            }
          ],
          escapeDom: ".pisell-number-selector-popover",
          key: item._id,
          dataSource: item,
          onAction: (e) => onAction == null ? void 0 : onAction(e),
          onDelete: (e) => handleChange(e, "delete", item),
          onNote: (e) => handleChange(e, "note", { note: e.note }),
          onLike: (e) => handleChange(e, "like", { like_status: e.like_status }),
          onEditProduct: (e) => handleChange == null ? void 0 : handleChange(e, "edit_product"),
          onCard: (e) => handleChange == null ? void 0 : handleChange(e, "view"),
          onChangeResource: (e) => handleChange(item, "change_resource", e),
          onChangeHolder: (e) => handleChange(item, "change_holder", e),
          onAddHolder: (e) => handleChange(item, "add_holder", e),
          ...productParams,
          ...getProductCardStyleProps(isRetail ? "retail" : "appointment"),
          scenario: state.scenario
        }
      );
    }), !hideAddBtn && platform !== "h5" && isAdd ? (0, import_useAddService.default)(id, "more") : null);
  }, [clearCart, lists, productParams, hideAddBtn, isAdd, platform]);
};
var Product_default = Product;
