var _excluded = ["dataSource", "isShowImage", "isShowOriginalPrice", "isShowHolder", "isShowNote", "isShowDelete", "isShowAmountFooter", "isShowPackageNote", "isShowEditProduct", "disabledClick", "disabledEditClick", "onEditProduct", "onAction", "onDelete", "onNote", "onLike", "onCard", "onChangeResource", "onPromotion", "onGift", "onChangeHolder", "itemType", "type", "rightActions", "escapeDom", "maxSpecsCount", "isShowRelatedProduct"];
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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 localeTexts from "./locales";
import BasicInfo from "./components/basicInfo";
import DiscountReason from "./components/discountReason";
import TimeRange from "./components/timeRange";
import Resources from "./components/resources";
import Packages from "./components/packages";
import Sales from "./components/sales";
import { SwipeAction } from "./components/swipeAction";
import Note from "./components/Note";
import AmountFooter from "./components/AmountFooter";
import Items from "./components/MultiDay";
import Promotion from "./components/Promotion";
import Gift from "./components/Gift";
import BookingItem from "./components/BookingItem";
import "./index.less";
import Iconfont from "../../iconfont";
import useEngineContext from "../../../hooks/useEngineContext";
import Action from "../components/Action";
import { defaultValue } from "../status";
export var PREFIX = 'pisell-cart-sku-card';
var CartSkuCard = function CartSkuCard(props) {
  var _context$appHelper$ut;
  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$isShowOriginal = props.isShowOriginalPrice,
    isShowOriginalPrice = _props$isShowOriginal === void 0 ? defaultValue.isShowOriginalPrice : _props$isShowOriginal,
    _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,
    _props$disabledClick = props.disabledClick,
    disabledClick = _props$disabledClick === void 0 ? defaultValue.disabledClick : _props$disabledClick,
    _props$disabledEditCl = props.disabledEditClick,
    disabledEditClick = _props$disabledEditCl === void 0 ? defaultValue.disabledEditClick : _props$disabledEditCl,
    onEditProduct = props.onEditProduct,
    _onAction = props.onAction,
    onDelete = props.onDelete,
    onNote = props.onNote,
    onLike = props.onLike,
    onCard = props.onCard,
    onChangeResource = props.onChangeResource,
    onPromotion = props.onPromotion,
    onGift = props.onGift,
    onChangeHolder = props.onChangeHolder,
    _props$itemType = props.itemType,
    itemType = _props$itemType === void 0 ? 'product' : _props$itemType,
    type = props.type,
    _props$rightActions = props.rightActions,
    rightActions = _props$rightActions === void 0 ? [] : _props$rightActions,
    escapeDom = props.escapeDom,
    _props$maxSpecsCount = props.maxSpecsCount,
    maxSpecsCount = _props$maxSpecsCount === void 0 ? 1 : _props$maxSpecsCount,
    _props$isShowRelatedP = props.isShowRelatedProduct,
    isShowRelatedProduct = _props$isShowRelatedP === void 0 ? true : _props$isShowRelatedP,
    other = _objectWithoutProperties(props, _excluded);
  var useOpenNoteRef = useRef();
  var context = useEngineContext();
  locales.init(localeTexts, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut = _context$appHelper$ut.storage) === null || _context$appHelper$ut === void 0 ? void 0 : _context$appHelper$ut.get('umi_locale')) || 'en');
  console.log('prodcut props', props);
  var isShowAction = dataSource.isShowAction,
    actionText = dataSource.actionText;
  var _rightActions = useMemo(function () {
    var deleteAction = {
      key: 'delete',
      text: /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          justifyContent: 'center',
          alignItems: 'center',
          color: 'white',
          cursor: 'pointer',
          padding: '10px 0px'
        }
      }, /*#__PURE__*/React.createElement("span", {
        style: {
          fontSize: 20,
          marginRight: 4,
          lineHeight: 1
        }
      }, /*#__PURE__*/React.createElement(Iconfont, {
        type: "pisell2-trash-01"
      })), /*#__PURE__*/React.createElement("span", {
        style: {
          fontSize: 12,
          fontWeight: 500
        }
      }, locales.getText('pisell2.cart.sku-card.actions.delete'))),
      color: 'danger',
      onClick: function onClick(e) {
        e.preventDefault();
        e.stopPropagation();
        onDelete === null || onDelete === void 0 || onDelete(dataSource);
      }
    };
    var actions = _toConsumableArray(rightActions);
    if (isShowDelete) {
      actions.unshift(deleteAction);
    }
    return actions;
  }, [dataSource, onDelete, isShowDelete, rightActions]);
  var hideDivider = useMemo(function () {
    return false;
    // const { bundle, relation_products } = dataSource;
    // return bundle?.length || relation_products?.length;
  }, [dataSource]);

  /**
   * @description: 营销活动
   * @param {*} useMemo
   * @return {*}
   */
  var renderPromotion = useMemo(function () {
    var _dataSource$promotion;
    return dataSource !== null && dataSource !== void 0 && (_dataSource$promotion = dataSource.promotions) !== null && _dataSource$promotion !== void 0 && _dataSource$promotion.length ? /*#__PURE__*/React.createElement(Promotion, {
      promotions: dataSource === null || dataSource === void 0 ? void 0 : dataSource.promotions,
      onClick: function onClick(item) {
        return onPromotion === null || onPromotion === void 0 ? void 0 : onPromotion(item);
      }
    }) : null;
  }, [dataSource === null || dataSource === void 0 ? void 0 : dataSource.promotions, dataSource === null || dataSource === void 0 ? void 0 : dataSource.num]);
  var renderA2 = function renderA2() {
    return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BasicInfo, {
      isShowImage: isShowImage,
      dataSource: dataSource,
      isMainProduct: true,
      maxSpecsCount: maxSpecsCount
    }), /*#__PURE__*/React.createElement(DiscountReason, {
      dataSource: dataSource
    }), renderPromotion, isShowNote ? /*#__PURE__*/React.createElement(Note, _extends({}, other, {
      item: dataSource,
      openNote: function openNote() {
        useOpenNoteRef.current.open({
          item: dataSource
        });
      }
    })) : null);
  };
  var renderA5 = function renderA5() {
    var _dataSource$bundle, _dataSource$items;
    return /*#__PURE__*/React.createElement(React.Fragment, null, isShowDelete ? /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__delete-btn"),
      onClick: function onClick(e) {
        e.preventDefault();
        e.stopPropagation();
        onDelete === null || onDelete === void 0 || onDelete(dataSource);
      }
    }, /*#__PURE__*/React.createElement(Iconfont, {
      type: "pisell2-trash-01"
    })) : null, /*#__PURE__*/React.createElement(BasicInfo, {
      isShowImage: isShowImage,
      dataSource: dataSource,
      isMainProduct: true,
      type: type,
      isShowOriginalPrice: isShowOriginalPrice,
      isShowEditProduct: isShowEditProduct,
      disabledEditClick: disabledEditClick,
      onEditProduct: onEditProduct
    }), itemType !== 'booking' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TimeRange, {
      dataSource: dataSource
    }), /*#__PURE__*/React.createElement(Resources, {
      dataSource: dataSource
    })) : null, /*#__PURE__*/React.createElement(Packages, {
      dataSource: dataSource,
      isShowImage: isShowImage
    }), /*#__PURE__*/React.createElement(Sales, {
      dataSource: dataSource,
      hideDivider: !!(dataSource !== null && dataSource !== void 0 && (_dataSource$bundle = dataSource.bundle) !== null && _dataSource$bundle !== void 0 && _dataSource$bundle.length),
      isShowImage: isShowImage
    }), (_dataSource$items = dataSource.items) !== null && _dataSource$items !== void 0 && _dataSource$items.length ? /*#__PURE__*/React.createElement(Items, {
      dataSource: dataSource,
      hideDivider: hideDivider
    }) : isShowAmountFooter ? /*#__PURE__*/React.createElement(AmountFooter, {
      item: dataSource,
      hideDivider: hideDivider,
      type: "total"
    }) : null, renderPromotion, 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);
  };
  var renderA9 = function renderA9() {
    return /*#__PURE__*/React.createElement(React.Fragment, null, isShowDelete ? /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__delete-btn"),
      onClick: function onClick(e) {
        e.preventDefault();
        e.stopPropagation();
        onDelete === null || onDelete === void 0 || onDelete(dataSource);
      }
    }, /*#__PURE__*/React.createElement(Iconfont, {
      type: "pisell2-trash-01"
    })) : null, /*#__PURE__*/React.createElement(BasicInfo, {
      isShowImage: isShowImage,
      dataSource: dataSource,
      isMainProduct: true,
      type: type,
      isShowOriginalPrice: isShowOriginalPrice,
      isShowEditProduct: isShowEditProduct,
      disabledEditClick: disabledEditClick,
      onEditProduct: onEditProduct
    }), /*#__PURE__*/React.createElement(Packages, {
      dataSource: dataSource,
      isShowImage: isShowImage,
      type: type
    }), isShowAmountFooter ? /*#__PURE__*/React.createElement(AmountFooter, {
      item: dataSource,
      hideDivider: hideDivider,
      type: "total"
    }) : null, /*#__PURE__*/React.createElement(DiscountReason, {
      dataSource: dataSource
    }), renderPromotion, isShowNote ? /*#__PURE__*/React.createElement(Note, _extends({}, other, {
      item: dataSource,
      openNote: function openNote() {
        useOpenNoteRef.current.open({
          item: dataSource
        });
      }
    })) : null);
  };
  var renderContent = function renderContent() {
    if (type === 'a9') {
      return renderA9();
    }
    if (type === 'a5') {
      return renderA5();
    }
    return renderA2();
  };
  if (dataSource !== null && dataSource !== void 0 && dataSource.isGift) return null;
  var content = renderContent();
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "-wrapper-container")
  }, /*#__PURE__*/React.createElement(SwipeAction, {
    closeOnAction: false,
    className: classNames("".concat(PREFIX, "-wrapper")),
    rightActions: _rightActions,
    escapeDom: escapeDom
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames(PREFIX, "".concat(PREFIX, "--").concat(type)),
    onClick: function onClick(e) {
      if (disabledClick) return;
      e.preventDefault();
      e.stopPropagation();
      onCard === null || onCard === void 0 || onCard(dataSource);
    }
  }, itemType === 'booking' ? /*#__PURE__*/React.createElement(BookingItem, {
    dataSource: dataSource,
    isShowRelatedProduct: isShowRelatedProduct,
    isShowDelete: isShowDelete
  }, content) : content)), /*#__PURE__*/React.createElement(Gift, _extends({}, (dataSource === null || dataSource === void 0 ? void 0 : dataSource.giftData) || {}, {
    onClick: function onClick() {
      return onGift === null || onGift === void 0 ? void 0 : onGift(dataSource);
    }
  })));
};
export default CartSkuCard;