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/productCard/cartSkuCard/components/basicInfo/index.tsx
var basicInfo_exports = {};
__export(basicInfo_exports, {
  default: () => basicInfo_default
});
module.exports = __toCommonJS(basicInfo_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_specs = __toESM(require("../specs"));
var import_holders = __toESM(require("../holders"));
var import_weighing = __toESM(require("../weighing"));
var import__ = require("../../index");
var import_EditButton = __toESM(require("../../../components/Header/EditButton"));
var import_index = require("./index.less");
var BasicInfo = (props) => {
  var _a, _b;
  const {
    isShowImage,
    dataSource = {},
    style,
    isMainProduct,
    type,
    maxSpecsCount = 1,
    isBundle,
    showFooter,
    isShowOriginalPrice = false,
    isShowEditProduct = false,
    onEditProduct,
    disabledEditClick = false
  } = props;
  const {
    image,
    bundle,
    options,
    product_option_string,
    name,
    price,
    symbol,
    total = 0,
    origin_total = 0,
    num = 1,
    holder_id,
    isFormSubject,
    totalDifference = 0
  } = dataSource;
  const renderNumTag = () => {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(`num-tag`, {
          "is-main": isMainProduct
        })
      },
      num < 100 ? num : "99+"
    );
  };
  const hasSpecs = (bundle == null ? void 0 : bundle.length) || (options == null ? void 0 : options.length) || product_option_string;
  const weighingInfo = (_b = (_a = dataSource == null ? void 0 : dataSource._origin) == null ? void 0 : _a._extend) == null ? void 0 : _b.weighing;
  const hasWeighingInfo = Boolean(
    weighingInfo && (Number.isFinite(Number(weighingInfo == null ? void 0 : weighingInfo.weight)) || Number.isFinite(Number(weighingInfo == null ? void 0 : weighingInfo.net_weight)))
  );
  const hasProductMeta = hasSpecs || hasWeighingInfo;
  const basicInfoClassName = (0, import_classnames.default)(`${import__.PREFIX}__basic-info`, {
    [`${import__.PREFIX}__basic-info--weighing`]: hasWeighingInfo
  });
  const renderProductMeta = () => {
    if (!hasProductMeta) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(`${import__.PREFIX}__product-meta`, {
          [`${import__.PREFIX}__product-meta--weighing`]: hasWeighingInfo
        })
      },
      hasWeighingInfo ? /* @__PURE__ */ import_react.default.createElement(import_weighing.default, { dataSource: weighingInfo, symbol }) : null,
      hasSpecs ? /* @__PURE__ */ import_react.default.createElement(
        import_specs.default,
        {
          dataSource,
          maxSpecsCount,
          type
        }
      ) : null
    );
  };
  const renderProductPrice = () => {
    if (weighingInfo) {
      return null;
    }
    return (0, import_utils.formatAmount)(price, 2, symbol);
  };
  const renderImage = () => {
    if (!isShowImage) return null;
    if (image) {
      return /* @__PURE__ */ import_react.default.createElement("img", { src: import_utils.image.ali(image, 64), className: `product-cover` });
    }
    const displayText = name ? name.slice(0, 2) : "";
    return /* @__PURE__ */ import_react.default.createElement("div", { className: `product-cover-text` }, displayText);
  };
  const renderEdit = (0, import_react.useMemo)(() => {
    if (!isShowEditProduct) return null;
    return /* @__PURE__ */ import_react.default.createElement(
      import_EditButton.default,
      {
        onEdit: () => onEditProduct == null ? void 0 : onEditProduct(dataSource),
        disabledEditClick
      }
    );
  }, [disabledEditClick]);
  const _isShowOriginalPrice = (0, import_react.useMemo)(() => {
    if (!isShowOriginalPrice) return false;
    if (hasSpecs || hasWeighingInfo) return false;
    const _originalTotal = parseFloat(String(origin_total || 0));
    const _total = parseFloat(String(total || 0));
    if (isNaN(_originalTotal) || isNaN(total)) return false;
    return _originalTotal !== 0 && _originalTotal != _total;
  }, [isShowOriginalPrice, origin_total, total, hasSpecs, hasWeighingInfo]);
  if (type === "a5") {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: basicInfoClassName, style: style || {} }, renderNumTag(), renderImage(), !isShowImage || !image && !name ? /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 20 } }) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-info product-info-a5` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-basic-info-wrap` }, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `product-name ${renderEdit ? "product-name-edit" : ""}`
      },
      name
    ), renderProductMeta(), (!holder_id || !(holder_id == null ? void 0 : holder_id.length)) && !isFormSubject ? /* @__PURE__ */ import_react.default.createElement("div", { className: `product-price` }, renderProductPrice()) : /* @__PURE__ */ import_react.default.createElement(import_holders.default, { dataSource })), renderEdit));
  }
  if (type === "a9") {
    const showAmount = isBundle && !showFooter;
    const _price = showAmount ? Number(price ?? 0) * num : price;
    return /* @__PURE__ */ import_react.default.createElement("div", { className: basicInfoClassName, style: style || {} }, renderNumTag(), renderImage(), !isShowImage || !image && !name ? /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 20 } }) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-info product-info-a9` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-basic-info-wrap` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-basic-info ${isBundle ? "row" : ""}` }, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `product-name ${renderEdit ? "product-name-edit" : ""}`
      },
      name
    ), /* @__PURE__ */ import_react.default.createElement("div", { className: `product-price` }, /* @__PURE__ */ import_react.default.createElement("span", null, renderProductPrice()), _isShowOriginalPrice ? /* @__PURE__ */ import_react.default.createElement("span", { className: `original-price` }, (0, import_utils.formatAmount)(origin_total, 2, symbol)) : null)), renderProductMeta()), renderEdit));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: basicInfoClassName, style: style || {} }, renderNumTag(), renderImage(), !isShowImage || !image && !name ? /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 20 } }) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-info` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `product-name` }, name), hasProductMeta ? renderProductMeta() : /* @__PURE__ */ import_react.default.createElement("div", { className: `product-price` }, renderProductPrice())), /* @__PURE__ */ import_react.default.createElement("div", { className: `product-amount` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `total-amont` }, (0, import_utils.formatAmount)(total * num - (totalDifference ?? 0), 2, symbol)), origin_total && Number(total) !== Number(origin_total) ? /* @__PURE__ */ import_react.default.createElement("div", { className: `origin-amount` }, (0, import_utils.formatAmount)(origin_total * num, 2, symbol)) : null));
};
var basicInfo_default = BasicInfo;
