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); }
var _excluded = ["dataSource", "isShowImage", "isShowHolder", "isShowNote", "isShowDelete", "isShowAmountFooter", "isShowPackageNote", "isShowEditProduct", "scenario", "onEditProduct", "onAction", "onDelete", "onNote", "onLike", "onCard", "onChangeResource", "onChangeHolder"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo, useRef } from 'react';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import CardPro from "../cardPro";
import Header from "./components/Header";
import DeleteButton from "./components/Header/DeleteButton";
import Time from "./components/Time";
import Packages from "./components/Packages";
import Sales from "./components/Sales";
import AmountFooter from "./components/AmountFooter";
import Items from "./components/MultiDay";
import Note from "./components/Note";
import Action from "./components/Action";
import UseOpenNote from "./hooks/useOpenNote";
import localeTexts from "./locales";
import { defaultValue } from "./status";
import useEngineContext from "../../hooks/useEngineContext";
import Warning from "./components/Warning";
import "./index.less";
import CartSkuCard from "./cartSkuCard";
var ProductCard = function ProductCard(props) {
  var _utils$storage, _dataSource$items;
  var context = useEngineContext();
  var utils = context.appHelper.utils || {};
  var _props$dataSource = props.dataSource,
    dataSource = _props$dataSource === void 0 ? defaultValue.dataSource : _props$dataSource,
    _props$isShowImage = props.isShowImage,
    isShowImage = _props$isShowImage === void 0 ? defaultValue.isShowImage : _props$isShowImage,
    _props$isShowHolder = props.isShowHolder,
    isShowHolder = _props$isShowHolder === void 0 ? defaultValue.isShowHolder : _props$isShowHolder,
    _props$isShowNote = props.isShowNote,
    isShowNote = _props$isShowNote === void 0 ? defaultValue.isShowNote : _props$isShowNote,
    _props$isShowDelete = props.isShowDelete,
    isShowDelete = _props$isShowDelete === void 0 ? defaultValue.isShowDelete : _props$isShowDelete,
    _props$isShowAmountFo = props.isShowAmountFooter,
    isShowAmountFooter = _props$isShowAmountFo === void 0 ? defaultValue.isShowAmountFooter : _props$isShowAmountFo,
    _props$isShowPackageN = props.isShowPackageNote,
    isShowPackageNote = _props$isShowPackageN === void 0 ? defaultValue.isShowPackageNote : _props$isShowPackageN,
    _props$isShowEditProd = props.isShowEditProduct,
    isShowEditProduct = _props$isShowEditProd === void 0 ? defaultValue.isShowEditProduct : _props$isShowEditProd,
    scenario = props.scenario,
    _onEditProduct = props.onEditProduct,
    _onAction = props.onAction,
    _onDelete = props.onDelete,
    onNote = props.onNote,
    _onLike = props.onLike,
    onCard = props.onCard,
    onChangeResource = props.onChangeResource,
    onChangeHolder = props.onChangeHolder,
    other = _objectWithoutProperties(props, _excluded);
  var useOpenNoteRef = useRef();
  var locale = (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get('umi_locale')) || localStorage.getItem('umi_locale');
  locales.init(localeTexts, locale || 'en');
  var image = dataSource.image,
    bundle = dataSource.bundle,
    relation_products = dataSource.relation_products,
    _id = dataSource._id,
    isShowAction = dataSource.isShowAction,
    actionText = dataSource.actionText,
    errorMessage = dataSource.errorMessage,
    isNormalProduct = dataSource.isNormalProduct,
    _dataSource$osWarnTip = dataSource.osWarnTips,
    osWarnTips = _dataSource$osWarnTip === void 0 ? [] : _dataSource$osWarnTip;

  /**
   * @title: 显示图片
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-11-21 19:33
   */
  var showImage = useMemo(function () {
    return isShowImage && image;
  }, [isShowImage, image]);

  /**
   * @title: 是否隐藏footer分割线
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-11-23 13:30
   */
  var hideDivider = useMemo(function () {
    return (bundle === null || bundle === void 0 ? void 0 : bundle.length) || (relation_products === null || relation_products === void 0 ? void 0 : relation_products.length);
  }, [bundle, relation_products]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-lowcode-product-card-wrap', _defineProperty({}, 'pisell-lowcode-product-card-disabled', dataSource === null || dataSource === void 0 ? void 0 : dataSource.disabled)),
    id: dataSource === null || dataSource === void 0 ? void 0 : dataSource.rowKey
  }, (dataSource === null || dataSource === void 0 ? void 0 : dataSource.disabled) && /*#__PURE__*/React.createElement("div", {
    className: "delete-btn-wrapper"
  }, /*#__PURE__*/React.createElement(DeleteButton, {
    onDelete: function onDelete() {
      return _onDelete === null || _onDelete === void 0 ? void 0 : _onDelete(dataSource);
    }
  })), /*#__PURE__*/React.createElement(CardPro, {
    className: classNames('pisell-lowcode-product-card', _defineProperty(_defineProperty(_defineProperty({}, 'pisell-lowcode-product-card-image', !showImage && scenario !== 'booking2'), 'pisell-lowcode-normal-product-card', !showImage && isNormalProduct && scenario !== 'booking2'), 'pisell-lowcode-product-card-image-booking2', scenario === 'booking2')),
    key: _id
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    onClick: function onClick(e) {
      e.preventDefault();
      e.stopPropagation();
      onCard === null || onCard === void 0 || onCard(dataSource);
    }
  }, /*#__PURE__*/React.createElement(Header, _extends({}, other, {
    item: dataSource,
    isShowImage: isShowImage,
    isShowDelete: isShowDelete,
    isShowEditProduct: isShowEditProduct,
    showImage: showImage,
    onEditProduct: function onEditProduct() {
      return _onEditProduct === null || _onEditProduct === void 0 ? void 0 : _onEditProduct(dataSource);
    },
    onDelete: function onDelete() {
      _onDelete === null || _onDelete === void 0 || _onDelete(dataSource);
    }
  })), /*#__PURE__*/React.createElement(Time, {
    item: dataSource,
    isShowHolder: isShowHolder,
    isShowChangeResource: other === null || other === void 0 ? void 0 : other.isShowChangeResource,
    isShowChangeHolder: other === null || other === void 0 ? void 0 : other.isShowChangeHolder,
    holderMode: other === null || other === void 0 ? void 0 : other.holderMode,
    onLike: function onLike(item) {
      return _onLike === null || _onLike === void 0 ? void 0 : _onLike(item);
    },
    changeResource: onChangeResource,
    changeHolder: onChangeHolder,
    onAddHolder: other === null || other === void 0 ? void 0 : other.onAddHolder,
    isShowAddHolderButton: other === null || other === void 0 ? void 0 : other.isShowAddHolderButton,
    onClearResource: other === null || other === void 0 ? void 0 : other.onClearResource,
    onClearHolder: other === null || other === void 0 ? void 0 : other.onClearHolder
  }), /*#__PURE__*/React.createElement(Packages, {
    item: dataSource,
    isShowPackageNote: isShowPackageNote
  }), /*#__PURE__*/React.createElement(Sales, {
    item: dataSource,
    isShowNote: isShowNote
  }), (_dataSource$items = dataSource.items) !== null && _dataSource$items !== void 0 && _dataSource$items.length ? /*#__PURE__*/React.createElement(Items, {
    dataSource: dataSource,
    hideDivider: hideDivider
  }) : /*#__PURE__*/React.createElement(AmountFooter, {
    item: dataSource,
    hideDivider: hideDivider,
    type: "total"
  }), isShowNote ? /*#__PURE__*/React.createElement(Note, _extends({}, other, {
    item: dataSource,
    openNote: function openNote() {
      useOpenNoteRef.current.open({
        item: dataSource
      });
    }
  })) : null, isShowAction && actionText ? /*#__PURE__*/React.createElement(Action, {
    item: dataSource,
    onAction: function onAction() {
      return _onAction === null || _onAction === void 0 ? void 0 : _onAction(dataSource);
    }
  }) : null, /*#__PURE__*/React.createElement(Warning, {
    errorMessage: errorMessage,
    osWarnTips: osWarnTips
  })), /*#__PURE__*/React.createElement(UseOpenNote, {
    ref: useOpenNoteRef,
    onNoteChange: function onNoteChange(e) {
      onNote === null || onNote === void 0 || onNote(_objectSpread(_objectSpread({}, dataSource), {}, {
        note: e || ''
      }));
    }
  }))));
};
ProductCard.V2 = CartSkuCard;
export default ProductCard;