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/VariantCard/index.tsx
var VariantCard_exports = {};
__export(VariantCard_exports, {
  default: () => VariantCard_default
});
module.exports = __toCommonJS(VariantCard_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_Selector = __toESM(require("../../../../pro/Selector"));
var import_useStore = __toESM(require("../../hooks/useStore"));
var import_index = require("./index.less");
var VariantCard = (props) => {
  var _a, _b, _c;
  const { dataSource, actions } = props || {};
  const symbol = (0, import_useStore.default)((s) => s.symbol);
  const skuCardConfig = (0, import_useStore.default)((s) => s.skuCardConfig);
  const isVariantPriceVisible = (skuCardConfig == null ? void 0 : skuCardConfig.variantPriceVisible) === true;
  const priceConfig = skuCardConfig == null ? void 0 : skuCardConfig.price;
  const priceText = formatPriceText({
    symbol,
    price: dataSource == null ? void 0 : dataSource.price
  });
  const handleClick = (e) => {
    e.stopPropagation();
    if (dataSource == null ? void 0 : dataSource.disabled) return;
    if (dataSource == null ? void 0 : dataSource.selected) {
      actions.update(dataSource._key, { quantity: 0 });
    } else {
      actions.update(dataSource._key, {
        quantity: 1,
        data: dataSource._original
      });
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(import_Selector.default.Item, { ...props || {} }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-sku-options-selection-variant-card",
      onClick: handleClick
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sku-options-selection-variant-card__title" }, ((_a = props.dataSource) == null ? void 0 : _a.title) || "", ((_c = (_b = props.dataSource) == null ? void 0 : _b._extra) == null ? void 0 : _c.hasStock) === false ? ` (${import_utils.locales.getText(
      "pisell2.skuOptionsSelection.variantItemCard.soldOut"
    )})` : null),
    isVariantPriceVisible && (priceConfig == null ? void 0 : priceConfig.visible) !== false && !!priceText ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-sku-options-selection-variant-card__price",
        style: {
          fontSize: priceConfig == null ? void 0 : priceConfig.fontSize,
          fontWeight: priceConfig == null ? void 0 : priceConfig.fontWeight,
          color: priceConfig == null ? void 0 : priceConfig.color
        }
      },
      import_utils.locales.getText("pisell2.skuOptionsSelection.variantItemCard.price"),
      ":",
      priceText
    ) : null
  ));
};
function formatPriceText(params) {
  const symbol = params.symbol || "$";
  const price = Number(params.price);
  if (!params.price && params.price !== 0) return "";
  if (Number.isNaN(price)) return "";
  return `${symbol}${price.toFixed(2)}`;
}
var VariantCard_default = VariantCard;
