function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { image as imageAli, formatAmount } from '@pisell/utils';
import Options from "../Packages/components/options";
import DeleteButton from "./DeleteButton";
import EditButton from "./EditButton";
import "./index.less";
var prefix = 'pisell-lowcode-';
var Header = function Header(props) {
  var isShowDelete = props.isShowDelete,
    item = props.item,
    isShowImage = props.isShowImage,
    onDelete = props.onDelete,
    disabledEdit = props.disabledEdit,
    onEditProduct = props.onEditProduct,
    isShowEditProduct = props.isShowEditProduct;
  var id = item.id,
    options = item.options,
    bundle = item.bundle,
    product_option_string = item.product_option_string,
    image = item.image,
    name = item.name,
    price = item.price,
    symbol = item.symbol,
    disabled = item.disabled,
    relation_products = item.relation_products,
    _item$num = item.num,
    num = _item$num === void 0 ? 1 : _item$num;

  /**
   * @title: 是否显示价格
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-11-23 16:13
   */
  var showPrice = useMemo(function () {
    // 如果有报价单则不需要显示价格

    return (bundle === null || bundle === void 0 ? void 0 : bundle.length) > 0 || (options === null || options === void 0 ? void 0 : options.length) > 0 || ((relation_products === null || relation_products === void 0 ? void 0 : relation_products.length) || 0) > 0;
  }, [bundle, options, relation_products]);

  /**
   * @title: 样式是否居中
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-11-23 17:37
   */
  var headerCenterStyle = useMemo(function () {
    return (options === null || options === void 0 ? void 0 : options.length) > 0 || product_option_string;
  }, [options, product_option_string]);

  /**
   * @title: 是否显示删除按钮
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-06-11 15:14
   */
  var showDelete = useMemo(function () {
    return isShowDelete && !disabledEdit && !disabled;
  }, [isShowDelete, disabledEdit, disabled]);
  var renderImage = function renderImage() {
    if (!isShowImage) return null;
    if (image) {
      return /*#__PURE__*/React.createElement("img", {
        src: imageAli.ali(image, 64),
        className: "".concat(prefix, "product-header-cover")
      });
    }

    // 如果没有图片，显示文字图片
    var displayText = name ? name.slice(0, 2) : '';
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefix, "product-header-cover-text")
    }, displayText);
  };
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "product-header"), headerCenterStyle && "".concat(prefix, "product-options-header"))
  }, showDelete ? /*#__PURE__*/React.createElement(DeleteButton, {
    onDelete: onDelete
  }) : null, renderImage(), id ? /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "product-right-wrap"), _defineProperty({}, "".concat(prefix, "product-right-wrap-stretch"), isShowEditProduct))
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "product-title")
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      paddingRight: showDelete ? '18px' : '0'
    }
  }, name), showPrice ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "product-title-price")
  }, formatAmount(price, 2, symbol)) : null), product_option_string ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "product-title-variant")
  }, product_option_string) : null, /*#__PURE__*/React.createElement(Options, {
    options: options,
    amountSymbol: symbol
  }), isShowEditProduct && !disabledEdit && !disabled ? /*#__PURE__*/React.createElement(EditButton, {
    onEdit: onEditProduct
  }) : null) : null);
};
export default Header;