import React from 'react';
import { isMobile, locales } from '@pisell/utils';
import ShoppingCart from "../../../../../shoppingCart";
import { useCart, useHolder, useSummary, useStep } from "../../../../../Sales";
import SelectHolderModal from "../../SelectHolderModal";
import ContinueButton from "../ContinueButton";
import Total from "./Total";
import Deposit from "../Deposit";
import "./index.less";
var CartItem = function CartItem() {
  var _cartData$cartItems;
  var _useHolder = useHolder(),
    open = _useHolder.open,
    holderData = _useHolder.holderData,
    selectedHolderIds = _useHolder.selectedHolderIds;
  var _useCart = useCart(),
    deleteCartItem = _useCart.deleteCartItem,
    deleteCartItemByHolder = _useCart.deleteCartItemByHolder,
    cartData = _useCart.cartData,
    addNoteToCartItem = _useCart.addNoteToCartItem;
  var _useSummary = useSummary(),
    deposit = _useSummary.deposit;
  var _useStep = useStep(),
    isLastStep = _useStep.isLastStep;
  var handleClickCard = function handleClickCard(e, type, key) {
    if (type === 'note') {
      return addNoteToCartItem(e);
    }
    console.log(e, type, key, 'wh9988767');
    // 删除
    if (type === 'delete') {
      return deleteCartItem(e);
    }
    if (type === 'delete_holders') {
      return deleteCartItemByHolder(key);
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "cart-item-wrap ".concat(isMobile() ? 'cart-mobile-item-wrap' : '')
  }, /*#__PURE__*/React.createElement("div", {
    className: "content"
  }, /*#__PURE__*/React.createElement(ShoppingCart, {
    productParams: {
      products: (cartData === null || cartData === void 0 ? void 0 : cartData.cartItems) || [],
      hideAddBtn: false,
      holders: (holderData === null || holderData === void 0 ? void 0 : holderData.selectedHolderItems) || [],
      disabledEdit: isLastStep
    },
    collapseParams: {
      activeKey: selectedHolderIds,
      ghost: true
    },
    platform: "h5",
    emptyText: locales.getText('pisell2.event.empty.service'),
    isOpenGroup: !!(selectedHolderIds !== null && selectedHolderIds !== void 0 && selectedHolderIds.length),
    onChange: function onChange(e, type, key) {
      return handleClickCard(e, type, key);
    }
  })), /*#__PURE__*/React.createElement("div", {
    className: "event-footer"
  }, /*#__PURE__*/React.createElement(Total, null), (cartData === null || cartData === void 0 || (_cartData$cartItems = cartData.cartItems) === null || _cartData$cartItems === void 0 ? void 0 : _cartData$cartItems.length) > 0 && deposit !== null && deposit !== void 0 && deposit.hasDeposit ? /*#__PURE__*/React.createElement(Deposit, null) : null, /*#__PURE__*/React.createElement(ContinueButton, null))), /*#__PURE__*/React.createElement(SelectHolderModal, {
    open: open
  }));
};
export default CartItem;