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 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 _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, { useContext, useMemo } from 'react';
import ShoppingCart from "../../../shoppingCart";
import { CartContext } from "../../../shoppingCart/Provider";
import { Context } from "../model";
import { formatProducts, isEventBooking, updateServices } from "../service2/utils";
import useHolderConfig from "../hooks/useHolderConfig";
import { useMemoizedFn } from 'ahooks';
import { getProductExtend } from "../../info2/service/addService/utils";
import useAddHolder from "../hooks/useAddHolder";
var Lists = function Lists(_ref) {
  var _state$service2;
  var onEdit = _ref.onEdit,
    onChange = _ref.onChange,
    onAction = _ref.onAction,
    isParallelResource = _ref.isParallelResource,
    _ref$isShowDelete = _ref.isShowDelete,
    isShowDelete = _ref$isShowDelete === void 0 ? true : _ref$isShowDelete,
    _ref$isShowAmountFoot = _ref.isShowAmountFooter,
    isShowAmountFooter = _ref$isShowAmountFoot === void 0 ? true : _ref$isShowAmountFoot;
  var _useContext = useContext(Context),
    state = _useContext.state,
    dispatch = _useContext.dispatch;
  var _useHolderConfig = useHolderConfig(state),
    isShowChangeHolder = _useHolderConfig.isShowChangeHolder;
  var _useAddHolder = useAddHolder(state, dispatch),
    handleAddHolder = _useAddHolder.handleAddHolder;

  /**
   * @title: 更新商品数据
   * @description:
   * @param {any} newState
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-11-29 16:35
   */
  var handleChange = useMemoizedFn(function (currentItem, type, other) {
    var _window$closeBookingE, _window2;
    console.time('handleChange');
    console.log(window.pp1 = performance.now(), '打开商品');
    if (state.disabledEdit || state.disableEventBookingEdit) {
      return;
    }
    var products = updateServices(state, currentItem, type, other, {
      handleAddHolder: handleAddHolder
    });

    // 查看
    if (type === 'view' || type === 'edit_product') {
      var _window$openBookingEd, _window;
      var product = currentItem._origin;
      var cacheItem = _objectSpread(_objectSpread({}, product), {}, {
        new: 0
      });
      if (isParallelResource) {
        cacheItem = getProductExtend({
          cacheItem: cacheItem,
          state: state
        });
      }
      (_window$openBookingEd = (_window = window).openBookingEditModal) === null || _window$openBookingEd === void 0 || _window$openBookingEd.call(_window);
      onChange({
        editModal: true,
        cacheItem: cacheItem
      });
      return onEdit === null || onEdit === void 0 ? void 0 : onEdit(cacheItem, type);
    }
    (_window$closeBookingE = (_window2 = window).closeBookingEditModal) === null || _window$closeBookingE === void 0 || _window$closeBookingE.call(_window2);
    var params = {
      editModal: false,
      value: products,
      edit: true,
      cacheItem: null
    };
    onChange(params);
  });

  /**
   * @title: 商品信息
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-12-09 16:07
   */
  var productParams = useMemo(function () {
    var _state$bookingConfig;
    return {
      hideAddBtn: state.isTerminalDayBookingPage || state.isBookingCreatePage,
      isShowNote: state.isBookingTicket2 ? true : isEventBooking(state),
      isShowDelete: isShowDelete,
      isShowAmountFooter: isShowAmountFooter,
      isShowPackageNote: false,
      accounts: [],
      isEdit: !!(state !== null && state !== void 0 && state.bookingId),
      disabledEdit: state === null || state === void 0 ? void 0 : state.disabledEdit,
      maxLength: isEventBooking(state) ? 1 : 999,
      isShowChangeHolder: isShowChangeHolder,
      isShowChangeResource: true,
      isShowAddHolderButton: true,
      isShowEditProduct: !state.isBookingCreatePage,
      productCardStyleConfig: (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.cart_settings_tab
    };
  }, [state === null || state === void 0 ? void 0 : state.bookingId, state === null || state === void 0 ? void 0 : state.disabledEdit, isShowChangeHolder, state.isBookingCreatePage, state.bookingConfig]);
  var products = useMemo(function () {
    var _state$service;
    console.time('products');
    var p = formatProducts((state === null || state === void 0 || (_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.value) || [], state, true, true, isParallelResource);
    console.timeEnd('products');
    return p;
  }, [state === null || state === void 0 || (_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.value, state]);
  return useMemo(function () {
    console.log('render List');
    return /*#__PURE__*/React.createElement(CartContext.Provider, {
      value: {
        state: state
      }
    }, /*#__PURE__*/React.createElement(ShoppingCart, {
      scenario: state.isBookingTicket2 ? 'booking2' : undefined,
      isParallelResource: isParallelResource,
      onAction: onAction,
      onChange: handleChange,
      isOpenGroup: false,
      isHideClearCart: true,
      onAddProduct: function onAddProduct() {
        return onChange({
          addModal: true
        });
      }
      // onActiveKey={handleActiveKey}
      // collapseParams={CollapseParams}
      ,
      productParams: _objectSpread(_objectSpread({}, productParams), {}, {
        products: products
      })
    }));
  }, [products, state, productParams]);
};
export default Lists;