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/saleDetail/components/LineItem/components/ProductBasicInfo.tsx
var ProductBasicInfo_exports = {};
__export(ProductBasicInfo_exports, {
  default: () => ProductBasicInfo_default
});
module.exports = __toCommonJS(ProductBasicInfo_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_icons = require("@ant-design/icons");
var import_utils = require("@pisell/utils");
var import_constants = require("../constants");
var import_display = require("../utils/display");
var import_render = require("../utils/render");
var import_ProductSpecs = __toESM(require("./ProductSpecs"));
var getQuantity = (value) => {
  const quantity = Number(value);
  return Number.isFinite(quantity) && quantity > 0 ? quantity : 1;
};
var ProductImage = ({
  image,
  title,
  isShowImage
}) => {
  if (!isShowImage) return null;
  if (image) {
    return /* @__PURE__ */ import_react.default.createElement(
      "img",
      {
        className: `${import_constants.PREFIX}__product-image`,
        src: import_utils.image.ali(image, 72),
        alt: ""
      }
    );
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-image-text` }, title.slice(0, 2));
};
var ProductBasicInfo = ({
  product,
  symbol,
  type = "a2",
  isShowImage,
  isShowOriginalPrice,
  isShowEditProduct,
  disabledEditClick,
  maxSpecsCount,
  onEditProduct
}) => {
  var _a, _b;
  const title = (0, import_display.toDisplayText)(product.title);
  const image = product.cover;
  const quantity = getQuantity(((_a = product._extend) == null ? void 0 : _a.displayQuantity) ?? product.num);
  const unitPrice = product.selling_price;
  const originalPrice = product.original_price;
  const optionText = (0, import_display.toDisplayText)(product.product_option_string);
  const options = product.product_option_item;
  const hasProductBundles = Boolean((_b = product.product_bundle) == null ? void 0 : _b.length);
  const hasMeta = Boolean(optionText || (options == null ? void 0 : options.length) || hasProductBundles);
  const showOriginalPrice = (0, import_react.useMemo)(() => {
    if (!isShowOriginalPrice || hasMeta) return false;
    const original = Number(originalPrice || 0);
    const current = Number(unitPrice || 0);
    return original > 0 && original !== current;
  }, [hasMeta, isShowOriginalPrice, originalPrice, unitPrice]);
  const showAmount = type === "a2";
  const showImageSlot = Boolean(isShowImage);
  const quantityClassName = (0, import_classnames.default)(
    `${import_constants.PREFIX}__quantity`,
    `${import_constants.PREFIX}__quantity--main`,
    {
      [`${import_constants.PREFIX}__quantity--with-image`]: showImageSlot,
      [`${import_constants.PREFIX}__quantity--without-image`]: !showImageSlot
    }
  );
  const editButton = isShowEditProduct ? /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: `${import_constants.PREFIX}__edit-btn`,
      type: "button",
      disabled: disabledEditClick,
      onClick: (event) => {
        (0, import_render.stopPropagation)(event);
        if (!disabledEditClick) onEditProduct == null ? void 0 : onEditProduct(product);
      }
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.EditOutlined, null)
  ) : null;
  if (type === "a5") {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__basic-info ${import_constants.PREFIX}__basic-info--a5` }, /* @__PURE__ */ import_react.default.createElement("span", { className: quantityClassName }, quantity < 100 ? quantity : "99+"), /* @__PURE__ */ import_react.default.createElement(ProductImage, { image, title, isShowImage }), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-info ${import_constants.PREFIX}__product-info--a5` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-title-row` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-title` }, title), editButton), /* @__PURE__ */ import_react.default.createElement(
      import_ProductSpecs.default,
      {
        optionText,
        options,
        maxSpecsCount,
        symbol,
        type
      }
    ), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-price` }, (0, import_render.formatMoney)(unitPrice, symbol))));
  }
  if (type === "a9") {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__basic-info ${import_constants.PREFIX}__basic-info--a9` }, /* @__PURE__ */ import_react.default.createElement("span", { className: quantityClassName }, quantity < 100 ? quantity : "99+"), /* @__PURE__ */ import_react.default.createElement(ProductImage, { image, title, isShowImage }), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-info ${import_constants.PREFIX}__product-info--a9` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-basic-row` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-title-row` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-title` }, title), editButton), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-price` }, /* @__PURE__ */ import_react.default.createElement("span", null, (0, import_render.formatMoney)(unitPrice, symbol)), showOriginalPrice ? /* @__PURE__ */ import_react.default.createElement("span", { className: `${import_constants.PREFIX}__product-original-price` }, (0, import_render.formatMoney)(originalPrice, symbol)) : null)), /* @__PURE__ */ import_react.default.createElement(
      import_ProductSpecs.default,
      {
        optionText,
        options,
        maxSpecsCount,
        symbol,
        type
      }
    )));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__basic-info ${import_constants.PREFIX}__basic-info--a2` }, /* @__PURE__ */ import_react.default.createElement("span", { className: quantityClassName }, quantity < 100 ? quantity : "99+"), /* @__PURE__ */ import_react.default.createElement(ProductImage, { image, title, isShowImage }), /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-info` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-title` }, title), hasMeta ? /* @__PURE__ */ import_react.default.createElement(
    import_ProductSpecs.default,
    {
      optionText,
      options,
      maxSpecsCount,
      symbol,
      type
    }
  ) : /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-price` }, (0, import_render.formatMoney)(unitPrice, symbol))), showAmount ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-amount` }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-total` }, (0, import_render.formatMoney)(Number(product.selling_price || 0) * quantity, symbol)), showOriginalPrice ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_constants.PREFIX}__product-origin-total` }, (0, import_render.formatMoney)(Number(product.original_price || 0) * quantity, symbol)) : null) : null);
};
var ProductBasicInfo_default = ProductBasicInfo;
