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/skuOptionsSelection/components/NormalCard/index.tsx
var NormalCard_exports = {};
__export(NormalCard_exports, {
  default: () => NormalCard_default
});
module.exports = __toCommonJS(NormalCard_exports);
var import_react = __toESM(require("react"));
var import_decimal = __toESM(require("decimal.js"));
var import_hooks = require("../../hooks");
var import_Cards = require("../../../../pro/Cards");
var NormalCard = (props) => {
  var _a, _b;
  const {
    _key: uniqueKey,
    ruleConfig,
    _original,
    disabled,
    selected
  } = (props == null ? void 0 : props.dataSource) || {};
  const { cover, title, name, product_subtitle, price, price_type, add_price } = _original || {};
  const symbol = (0, import_hooks.useStore)((s) => s.symbol);
  const skuCardConfig = (0, import_hooks.useStore)((s) => s.skuCardConfig);
  const renderIndicator = () => {
    if (!(props == null ? void 0 : props.indicator) || typeof (props == null ? void 0 : props.indicator) !== "object") return null;
    return import_react.default.cloneElement(props == null ? void 0 : props.indicator, {
      onChange: handleChange
    });
  };
  const renderNumberSelector = () => {
    if (!(props == null ? void 0 : props.numberSelector) || typeof (props == null ? void 0 : props.numberSelector) !== "object")
      return null;
    return import_react.default.cloneElement(props == null ? void 0 : props.numberSelector, {
      onChange: (v) => {
        var _a2;
        const _price = add_price !== void 0 && add_price !== null ? add_price : price;
        const priceType = price_type === "markdown" ? -1 : 1;
        const totalPrice = new import_decimal.default(_price).times(new import_decimal.default(v)).times(priceType).toNumber();
        const newOriginal = {
          ..._original,
          quantity: v,
          num: v,
          price: _price,
          original_price: _price,
          original_total: _price
        };
        (_a2 = props == null ? void 0 : props.actions) == null ? void 0 : _a2.update(uniqueKey, {
          quantity: v,
          data: newOriginal,
          totalPrice
        });
      }
    });
  };
  const isNumberSelector = (0, import_react.useMemo)(() => {
    return !!(props == null ? void 0 : props.numberSelector) && import_react.default.isValidElement(props == null ? void 0 : props.numberSelector);
  }, [props == null ? void 0 : props.numberSelector]);
  const priceText = (0, import_react.useMemo)(() => {
    if (add_price !== void 0 && add_price !== null) {
      return `${Number(add_price) > 0 ? "+" : ""}${symbol}${Math.abs(
        Number(add_price || 0)
      )}`;
    }
    return `${price_type === "markdown" ? "-" : ""}${symbol}${price || 0}`;
  }, [price, price_type, symbol, add_price]);
  const handleChange = () => {
    var _a2, _b2;
    if (disabled || isNumberSelector) return;
    if (selected) {
      (_a2 = props == null ? void 0 : props.actions) == null ? void 0 : _a2.update(uniqueKey, { quantity: 0 });
    } else {
      const _price = add_price !== void 0 && add_price !== null ? add_price : price;
      const priceType = price_type === "markdown" ? -1 : 1;
      const newOriginal = {
        ..._original,
        quantity: 1,
        num: 1,
        price: _price,
        original_price: _price,
        original_total: _price
      };
      (_b2 = props == null ? void 0 : props.actions) == null ? void 0 : _b2.update(uniqueKey, {
        quantity: 1,
        data: newOriginal,
        totalPrice: new import_decimal.default(_price).times(priceType).toNumber()
      });
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_Cards.SKUCard,
    {
      cover,
      title: title || name || "",
      subtitle: product_subtitle,
      price: priceText,
      selected,
      disabled,
      renderRight: isNumberSelector ? /* @__PURE__ */ import_react.default.createElement("div", { style: { position: "relative", height: "100%" } }, renderNumberSelector()) : /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          style: { position: "relative", height: "100%", padding: "0 8px" }
        },
        /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, renderIndicator(), /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            style: {
              position: "absolute",
              top: 0,
              left: 0,
              width: "100%",
              height: "100%"
            }
          }
        ))
      ),
      onClick: handleChange,
      skuCardConfig,
      skuDisabled: ((_b = (_a = props == null ? void 0 : props.dataSource) == null ? void 0 : _a._extra) == null ? void 0 : _b.disabled) === true
    }
  );
};
var NormalCard_default = NormalCard;
