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 _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 _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 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); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import Delete_wght300_24px from '@pisell/icon/es/Delete_wght300_24px';
import { formatAmount, locales } from '@pisell/utils';
import React, { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import Drawer from "../../../components/drawer";
import { Context } from "../../../info/model";
import Duration from "../../../materiels/duration";
import Capacity from "./Capacity";
import Resources from "./Resources";
import { Input, Button, Row, Col, Form, InputNumber } from 'antd';
import "./index.less";
import CollapsibleList from "../../../components/collapsibleList";
import { renderBundles } from "../../../components/collapsibleList/utils";
import "./index.less";
import { useUpdateEffect, useMemoizedFn, useDebounceFn } from 'ahooks';
// import SelectTime from "../../../../../../../materials/src/components/select-time";
import { ConfigProvider, Iconfont } from '@pisell/materials';
import { addService, genServiceKey, getIsShowNumber } from "../../../../ticketBooking/utils";
import { isNormalProductByDurationSchedule } from "../../../info/service2/utils";
import { editSessionProduct } from "../../../info/utils";
import { deleteCacheParams, getProductTotalPrice, getServiceTimes, isSessionProduct } from "../../../utils";
import { getErrorList, getIsNoSpecAndPackage } from "../../utilsByBooking";
import { formatResources, getDurationProps, getFlexibleOption, getTimeObj, setDefaultCapacitys } from "../addService/utils";
import NoteModal from "../../../../../plus/noteModal";
import { DiscountKeyboard } from "../../../../../pro/priceKeyboard";
var submitLock = false;
var Info = function Info(_, ref) {
  var _state$service4, _state$bookingConfig2, _state$bookingConfig3, _state$service$cacheI5, _state$service$cacheI6, _state$service6, _window$BaseMaterials, _state$service8, _state$service$cacheI11, _state$bookingConfig5, _state$service$cacheI12, _state$service$cacheI13, _state$service9, _state$service$resour2, _state$service$cacheI14, _state$service$cacheI15;
  var _Form$useForm = Form.useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    form = _Form$useForm2[0];
  var useTotal = Form.useWatch('total', form);
  var useResource = Form.useWatch('resource', form);
  var useStartTime = Form.useWatch('start_time', form);
  var useDuration = Form.useWatch('duration', form);
  var useNote = Form.useWatch('note', form);
  var _useContext = useContext(Context),
    state = _useContext.state,
    dispatch = _useContext.dispatch;
  var resourcesRef = useRef(null);
  var isChangeTotal = useRef(false);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    noteModalOpen = _useState2[0],
    setNoteModalOpen = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    open = _useState4[0],
    setOpen = _useState4[1];
  useEffect(function () {
    window.openBookingEditModal = function () {
      setOpen(true);
    };
    window.closeBookingEditModal = function () {
      setOpen(false);
    };
  }, []);
  var isNormalProduct = useMemo(function () {
    var _state$service, _state$service2, _state$service3;
    if (!(state !== null && state !== void 0 && (_state$service = state.service) !== null && _state$service !== void 0 && _state$service.cacheItem)) {
      return true;
    }
    return (state === null || state === void 0 || (_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.cacheItem) && isNormalProductByDurationSchedule(state === null || state === void 0 || (_state$service3 = state.service) === null || _state$service3 === void 0 ? void 0 : _state$service3.cacheItem);
  }, [state === null || state === void 0 || (_state$service4 = state.service) === null || _state$service4 === void 0 ? void 0 : _state$service4.cacheItem]);

  // 当前商品信息+ 表单信息
  var getCurrentCacheItem = useMemoizedFn(function (_cacheItem) {
    // 获取当前表单数据
    var values = form.getFieldsValue();
    var _item = _cacheItem || state.service.cacheItem;
    return _objectSpread(_objectSpread({}, _item), {}, {
      _extend: _objectSpread(_objectSpread({}, _item === null || _item === void 0 ? void 0 : _item._extend), values)
    });
  });

  /**
   * @title: 当前的资源
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:06
   */
  var currentResource = useMemo(function () {
    // let item =
    //   resources.find((d: any) => d.form_record_id == useResource) || {};
    return null;
  }, []);

  /**
   * @title: 持续时长组件的props
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-02-23 09:59
   */
  var durationProps = useMemo(function () {
    var _state$bookingConfig;
    var _cacheItem = getCurrentCacheItem();
    var val = getDurationProps({
      cacheItem: _cacheItem,
      useStartTime: useStartTime,
      // currentResource,
      slice: (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.basic) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.service_time
    });
    return val;
  }, [
  // currentResource,
  state.service.cacheItem, useStartTime, useResource, (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.basic) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.service_time]);

  /**
   * @title: 灵活时长选项
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-02-23 10:10
   */
  var flexibleOption = useMemo(function () {
    var op = getFlexibleOption({
      durationProps: durationProps
    });
    return op;
  }, [durationProps, locales.locale]);

  /**
   * @title: 时间切片
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 13:37
   */
  var timeObj = useMemo(function () {
    var val = getTimeObj({
      durationProps: durationProps,
      useStartTime: useStartTime,
      currentResource: currentResource,
      state: state,
      useDuration: useDuration
    });
    return val;
  }, [durationProps, useStartTime, currentResource, (_state$bookingConfig3 = state.bookingConfig) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.config) === null || _state$bookingConfig3 === void 0 || (_state$bookingConfig3 = _state$bookingConfig3.basic) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.service_time, useDuration]);

  // 由于灵活时长的结束时间随时变动, 这里发现如果当前选择的值没有在列表内,则选择最新的灵活时长值
  useEffect(function () {
    console.log('执行次数:于灵活时长的结束时间随');
    try {
      if (useDuration.indexOf('flexible_') == 0) {
        if (flexibleOption) {
          form.setFieldsValue({
            duration: flexibleOption.value
          });
        }
      }
    } catch (err) {}
  }, [useDuration, flexibleOption]);

  /**
   * @title: 删除服务商品
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 13:59
   */
  var handleDeleteProduct = useMemoizedFn(function () {
    var _state$service$cacheI, _window$closeBookingE, _window;
    if (state.channelDisabledEdit) {
      return;
    }
    var _list = _toConsumableArray(state.service.value);
    var _id = (_state$service$cacheI = state.service.cacheItem) === null || _state$service$cacheI === void 0 ? void 0 : _state$service$cacheI._id;
    _list = _list.filter(function (d) {
      return d._id !== _id;
    });
    (_window$closeBookingE = (_window = window).closeBookingEditModal) === null || _window$closeBookingE === void 0 || _window$closeBookingE.call(_window);
    dispatch({
      type: 'setService',
      payload: {
        editModal: false,
        value: _list,
        edit: true,
        cacheItem: null
      }
    });
  });

  /**
   * @title: 计算折扣
   * @description: 仅是文案展示
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:03
   */
  var getDiscount = function getDiscount() {
    var _state$service$cacheI2;
    var oPrice = Number(((_state$service$cacheI2 = state.service.cacheItem) === null || _state$service$cacheI2 === void 0 ? void 0 : _state$service$cacheI2._extend.origin_total) || 0);
    var cPrice = Number(useTotal || 0);
    var discount = '';
    // 原价 = 现价 为无折扣
    if (cPrice === oPrice) {
      discount = locales.getText('pisell2.text.status.no-discount');
    } else {
      // 判断加价还是减价
      discount = "".concat(locales.getText('pisell2.text.status.manual'), " ");
      if (cPrice < oPrice) {
        discount += formatAmount(cPrice - oPrice, 2, state.amountSymbol) + '';
      } else {
        discount += '+' + formatAmount(cPrice - oPrice, 2, state.amountSymbol) + '';
      }
    }
    // 赋值文案
    form.setFieldsValue({
      discount: discount
    });
  };

  /**
   * @title: 提交,
   * @description:
   * @param {any} values
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:04
   */
  var onFinish = function onFinish(values) {
    var _resourcesRef$current, _item$_extend, _state$service$cacheI3, _window$closeBookingE2, _window2;
    var isSuccess = (_resourcesRef$current = resourcesRef.current) === null || _resourcesRef$current === void 0 ? void 0 : _resourcesRef$current.check();
    if (isShowTimeAndResource && !isSuccess) {
      return;
    }
    // 防止多次提交, 增加锁
    if (submitLock) {
      return;
    }
    submitLock = true;

    // 1500毫秒后解除
    setTimeout(function () {
      submitLock = false;
    }, 1500);
    var _list = _toConsumableArray(state.service.value);
    var _item = _objectSpread(_objectSpread({}, state.service.cacheItem), {}, {
      autoClose: false
    });
    var _extend = _objectSpread(_objectSpread({}, _item._extend), {}, {
      other: _objectSpread(_objectSpread({}, ((_item$_extend = _item._extend) === null || _item$_extend === void 0 ? void 0 : _item$_extend.other) || {}), {}, {
        quantity: values.quantity
      })
    }, values);
    var _getServiceTimes = getServiceTimes({
        _extend: _extend
      }),
      startDate = _getServiceTimes.startDate,
      endDate = _getServiceTimes.endDate;
    _extend.startDate = startDate;
    _extend.endDate = endDate;
    if (_extend.bundle_edit !== undefined) {
      _extend.bundle_edit = 1;
    }
    _item._extend = _extend;
    _item._time = new Date().getTime();
    _item._serviceKey = genServiceKey(_item);
    var _id = _item === null || _item === void 0 ? void 0 : _item._id;

    // 判断是新增还是编辑
    if (!_list.some(function (d) {
      return d._id === _id;
    })) {
      var detail = addService(_list, _item, state);
      _list = detail.list;
    } else {
      // 手动改价时移除优惠券使用
      if (isChangeTotal.current) {
        delete _item.discount_list;
      }
      _list = _list.map(function (d) {
        return d._id === _id ? _objectSpread(_objectSpread({}, _item), {}, {
          new: 0
        }) : d;
      });
    }
    deleteCacheParams();
    console.log('_onFinish', _list);
    form.resetFields();
    if (!!((_state$service$cacheI3 = state.service.cacheItem) !== null && _state$service$cacheI3 !== void 0 && _state$service$cacheI3.new)) {
      window.dispatchEvent(new CustomEvent('onAddNewService', {
        detail: {
          cacheItem: _objectSpread({}, state.service.cacheItem)
        }
      }));
    }
    (_window$closeBookingE2 = (_window2 = window).closeBookingEditModal) === null || _window$closeBookingE2 === void 0 || _window$closeBookingE2.call(_window2);
    dispatch({
      type: 'setService',
      payload: {
        editModal: false,
        addModal: false,
        value: _list,
        edit: true,
        cacheItem: null,
        changeService: false
      }
    });
  };
  var _useDebounceFn = useDebounceFn(function () {
      setEditData.apply(void 0, arguments);
    }, {
      wait: 50,
      leading: true,
      trailing: false
    }),
    setEditDataRun = _useDebounceFn.run;
  var setEditData = useMemoizedFn(function (_cacheItem, open, openProductDetail) {
    console.timeEnd('handleChange');
    console.log('setEditDatasetEditData', _cacheItem, open);
    isChangeTotal.current = false;
    var cacheItem = _cacheItem || state.service.cacheItem;
    var values = cacheItem._extend;
    var startTime = performance.now();
    console.log(startTime, 'startTime');
    form.resetFields();
    form.setFieldsValue(values);
    // form.setFieldValue('resource', values.resource)

    // values.resource[1117][0].times = [];
    // values.resource[1117][0]._extend = {
    //   usableTime: {
    //     ...values.resource[1117][0]._extend.usableTime,
    //     event_list: []
    //   }
    // };

    // form.setFieldsValue({
    //   capacity: values.capacity,
    //   duration: values.duration,
    //   endDate: values.endDate,
    //   origin_total: values.origin_total,
    //   price: values.price,
    //   product_name: values.product_name,
    //   quantity: values.quantity,
    //   resource: values.resource,
    //   startDate: values.startDate,
    //   start_time: values.start_time,
    //   total: values.total,
    // });
    var endTime = performance.now();
    console.log(endTime - window.pp1, '打开商品5');
    console.log('执行时间', endTime - startTime, values);
    setTimeout(function () {}, 20);
    if (openProductDetail) {
      setTimeout(function () {
        handleEdit({});
      }, 100);
    }
  });

  /**
   * @title: 是否显示折扣原因
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:06
   */
  var isReason = useMemo(function () {
    var _state$service$cacheI4;
    var oPrice = Number(((_state$service$cacheI4 = state.service.cacheItem) === null || _state$service$cacheI4 === void 0 ? void 0 : _state$service$cacheI4._extend.origin_total) || 0);
    var cPrice = Number(useTotal || 0);
    // 原价 !== 现价
    return cPrice !== oPrice;
  }, [useTotal, (_state$service$cacheI5 = state.service.cacheItem) === null || _state$service$cacheI5 === void 0 || (_state$service$cacheI5 = _state$service$cacheI5._extend) === null || _state$service$cacheI5 === void 0 ? void 0 : _state$service$cacheI5.origin_total]);
  var getResources = function getResources() {
    var res = formatResources({
      cacheItem: getCurrentCacheItem(),
      resourcesOrigin: state.service.cacheItem._data.resourcesOrigin
    });
    dispatch({
      type: 'setService',
      payload: {
        cacheItem: _objectSpread(_objectSpread({}, state.service.cacheItem), {}, {
          _data: _objectSpread(_objectSpread({}, state.service.cacheItem._data), {}, {
            resources: res.list,
            resourceMaps: res.maps
          })
        })
      }
    });
    updateResourceErrors(res.maps);
  };
  var updateResourceErrors = function updateResourceErrors(resourceMaps) {
    var _form$getFieldsValue = form.getFieldsValue(),
      resource = _form$getFieldsValue.resource;
    if (resource) {
      var _resource = _objectSpread({}, resource);
      // 拿当前value 和 resources
      var _loop = function _loop(form_id) {
        _resource[form_id] = _resource[form_id].map(function (d) {
          var _resourceMaps$form_id;
          return _objectSpread(_objectSpread({}, d), {}, {
            errors: getErrorList(resourceMaps === null || resourceMaps === void 0 || (_resourceMaps$form_id = resourceMaps[form_id]) === null || _resourceMaps$form_id === void 0 || (_resourceMaps$form_id = _resourceMaps$form_id.renderListMaps) === null || _resourceMaps$form_id === void 0 ? void 0 : _resourceMaps$form_id[d === null || d === void 0 ? void 0 : d.relation_id], getCurrentCacheItem())
          });
        });
      };
      for (var form_id in _resource) {
        _loop(form_id);
      }
      form.setFieldsValue({
        resource: _resource
      });
      return _resource;
    }
  };

  /**
   * @title: 开始时间 和 服务时间 发生变化时,重新计算资源
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:07
   */
  useUpdateEffect(function () {
    if (!state.service.cacheItem) {
      return;
    }
    if (useStartTime && useDuration && state.renderType !== 'eventBooking') {
      getResources();
    }
  }, [useStartTime, useDuration, state.renderType, state.service.resourcesOrigin]);
  useEffect(function () {
    // 预约创建页面并且打开了编辑弹窗
    if (state.isBookingCreatePage && state.service.editModal) {
      setEditDataRun(null);
    }
  }, [state.service.editModal, state.isBookingCreatePage]);

  /**
   * @title: 价格发生变化,重新计算折扣
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:08
   */
  useEffect(function () {
    getDiscount();
  }, [useTotal, (_state$service$cacheI6 = state.service.cacheItem) === null || _state$service$cacheI6 === void 0 || (_state$service$cacheI6 = _state$service$cacheI6._extend) === null || _state$service$cacheI6 === void 0 ? void 0 : _state$service$cacheI6.origin_total]);
  var bundles = useMemo(function () {
    var _state$service5;
    return ((_state$service5 = state.service) === null || _state$service5 === void 0 || (_state$service5 = _state$service5.cacheItem) === null || _state$service5 === void 0 || (_state$service5 = _state$service5._extend) === null || _state$service5 === void 0 || (_state$service5 = _state$service5.other) === null || _state$service5 === void 0 ? void 0 : _state$service5.bundle) || [];
  }, [(_state$service6 = state.service) === null || _state$service6 === void 0 || (_state$service6 = _state$service6.cacheItem) === null || _state$service6 === void 0 || (_state$service6 = _state$service6._extend) === null || _state$service6 === void 0 || (_state$service6 = _state$service6.other) === null || _state$service6 === void 0 ? void 0 : _state$service6.bundle]);

  /**
   * @title: 编辑商品
   * @description:
   * @param {any} e
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-08-28 17:08
   */
  var handleEdit = useMemoizedFn(function (e) {
    var _state$client;
    // 当前商品
    var item = state.service.cacheItem;

    // 表单数据
    var values = form.getFieldsValue();
    var isSession = isSessionProduct(item);
    var sessionValue = {};
    if (isSession) {
      var _item$_extend2, _item$_extend3, _item$_extend4;
      sessionValue.startEndTime = {
        startDate: item === null || item === void 0 || (_item$_extend2 = item._extend) === null || _item$_extend2 === void 0 ? void 0 : _item$_extend2.start_date,
        endDate: item === null || item === void 0 || (_item$_extend3 = item._extend) === null || _item$_extend3 === void 0 ? void 0 : _item$_extend3.end_date,
        duration: item === null || item === void 0 || (_item$_extend4 = item._extend) === null || _item$_extend4 === void 0 ? void 0 : _item$_extend4.duration
      };
    }

    // 打开商品详情弹窗
    state.action({
      type: 'pisell1.handleOpenProductModal',
      data: {
        id: item.id,
        date: state.date.value.format('YYYY-MM-DD'),
        showConfig: {
          option: true,
          session: isSession,
          variant: true,
          package: true,
          number: getIsShowNumber(item, state)
        },
        isOS: isSession,
        customer_id: (_state$client = state.client) === null || _state$client === void 0 || (_state$client = _state$client.value) === null || _state$client === void 0 ? void 0 : _state$client.id,
        value: _objectSpread(_objectSpread(_objectSpread({}, item._extend.other), sessionValue), {}, {
          quantity: values.quantity || item._extend.quantity
        })
      },
      callback: function callback(e, extension_type, detail) {
        var _cacheItem$_extend;
        var _detail = detail || item;
        var other = JSON.parse(JSON.stringify(e));
        other.session = e.session;

        // 重新生成商品
        var cacheItem = _objectSpread(_objectSpread(_objectSpread({}, item), _detail), {}, {
          product_id: item.id,
          _id: item === null || item === void 0 ? void 0 : item._id,
          _key: e.key,
          _extend: _objectSpread(_objectSpread(_objectSpread({}, item._extend), values), {}, {
            quantity: (e === null || e === void 0 ? void 0 : e.quantity) || (values === null || values === void 0 ? void 0 : values.quantity) || 1,
            // 覆盖选择的规格和套餐
            other: other
          }),
          new: 0
        });

        // 获取商品总价
        var _total = getProductTotalPrice(cacheItem);

        // 用于折扣 可修改
        cacheItem._extend.total = _total;
        try {
          cacheItem._extend.capacity = setDefaultCapacitys({
            capacitys: cacheItem._data.capacitys,
            cacheItem: cacheItem
          });
        } catch (err) {}
        var sessionDetail = editSessionProduct(cacheItem, e.session);
        if (sessionDetail) {
          setTimeout(function () {
            form.setFieldsValue({
              start_time: sessionDetail.start_time,
              duration: sessionDetail.duration
            });
          }, 200);
        }

        // 用于储存原价
        cacheItem._extend.origin_total = _total;

        // 覆盖商品
        dispatch({
          type: 'setService',
          payload: {
            cacheItem: cacheItem
          }
        });

        // 更新表单内的商品价格
        form.setFieldsValue({
          total: _total,
          capacity: (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.capacity,
          quantity: (e === null || e === void 0 ? void 0 : e.quantity) || (values === null || values === void 0 ? void 0 : values.quantity) || 1
        });
      }
    });
  });

  /**
   * @title: 更换商品
   * @description:
   * @param {any} e
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-08-28 17:10
   */
  var handleChange = useMemoizedFn(function (e) {
    var _window$closeBookingE3, _window3;
    if (state.channelDisabledEdit) {
      return;
    }
    form.resetFields();
    (_window$closeBookingE3 = (_window3 = window).closeBookingEditModal) === null || _window$closeBookingE3 === void 0 || _window$closeBookingE3.call(_window3);
    dispatch({
      type: 'setService',
      payload: {
        addModal: true,
        editModal: false

        //用于控制 添加商品 和 编辑服务弹窗的上下层级
        // changeService: true,
      }
    });
  });
  useImperativeHandle(ref, function () {
    return {
      init: setEditDataRun
    };
  });
  var handleTotalChange = function handleTotalChange(number) {
    isChangeTotal.current = true;
  };
  var isShowTimeAndResource = useMemo(function () {
    // 非活动预约 非普通商品时展示
    if (state.renderType !== 'eventBooking' && !isNormalProduct) {
      return true;
    }
    return false;
  }, [state.renderType, isNormalProduct]);
  var SelectTime = (_window$BaseMaterials = window.BaseMaterials) === null || _window$BaseMaterials === void 0 ? void 0 : _window$BaseMaterials.SelectTime;
  var isNoSpecAndPackage = getIsNoSpecAndPackage(state.service.cacheItem);
  var handleNoteConfirm = function handleNoteConfirm(noteValue) {
    form.setFieldsValue({
      note: noteValue
    });
    setNoteModalOpen(false);
  };
  var handleNoteDelete = function handleNoteDelete() {
    form.setFieldsValue({
      note: ''
    });
    setNoteModalOpen(false);
  };
  var handleNoteCancel = function handleNoteCancel() {
    setNoteModalOpen(false);
  };
  console.log(isShowTimeAndResource, 'isShowTimeAndResource');
  var productName = useMemo(function () {
    var _state$service7;
    return /*#__PURE__*/React.createElement(Col, {
      span: 24
    }, /*#__PURE__*/React.createElement(Form.Item, {
      name: "product_name"
    }, /*#__PURE__*/React.createElement("div", {
      className: "current-service-info"
    }, /*#__PURE__*/React.createElement("div", {
      className: "current-service-info-name-wrap"
    }, /*#__PURE__*/React.createElement("div", {
      className: "current-service-info-name"
    }, ((_state$service7 = state.service) === null || _state$service7 === void 0 || (_state$service7 = _state$service7.cacheItem) === null || _state$service7 === void 0 || (_state$service7 = _state$service7._extend) === null || _state$service7 === void 0 ? void 0 : _state$service7.product_name) || '-'), /*#__PURE__*/React.createElement(Button, {
      onClick: handleEdit
    }, locales.getText('pisell2.text.edit')), !state.isBookingCreatePage && /*#__PURE__*/React.createElement(Button, {
      onClick: handleChange
    }, locales.getText('pisell2.text.change'))), /*#__PURE__*/React.createElement(CollapsibleList, {
      style: {
        marginTop: bundles.length ? '8px' : 0
      },
      list: bundles,
      renderItem: function renderItem(item) {
        return renderBundles(item, state.amountSymbol);
      }
    }))));
  }, [(_state$service8 = state.service) === null || _state$service8 === void 0 || (_state$service8 = _state$service8.cacheItem) === null || _state$service8 === void 0 || (_state$service8 = _state$service8._extend) === null || _state$service8 === void 0 ? void 0 : _state$service8.product_name, bundles, state.amountSymbol, state.isBookingCreatePage]);
  var price = useMemo(function () {
    var _state$service$cacheI7, _state$service$cacheI8, _state$service$cacheI9, _state$service$cacheI10;
    return /*#__PURE__*/React.createElement(Col, {
      span: 24
    }, /*#__PURE__*/React.createElement(Form.Item, {
      label: locales.getText('pisell2.text.price'),
      name: "total",
      rules: [{
        required: true
      }],
      extra: useTotal !== ((_state$service$cacheI7 = state.service.cacheItem) === null || _state$service$cacheI7 === void 0 || (_state$service$cacheI7 = _state$service$cacheI7._extend) === null || _state$service$cacheI7 === void 0 ? void 0 : _state$service$cacheI7.origin_total) && locales.getText('page.booking.text.price-extra')(formatAmount((_state$service$cacheI8 = state.service.cacheItem) === null || _state$service$cacheI8 === void 0 || (_state$service$cacheI8 = _state$service$cacheI8._extend) === null || _state$service$cacheI8 === void 0 ? void 0 : _state$service$cacheI8.origin_total, 2, state.amountSymbol), formatAmount(useTotal, 2, state.amountSymbol))
    }, /*#__PURE__*/React.createElement(DiscountKeyboard.InputNumber, {
      style: {
        width: '100%'
      },
      min: 0,
      precision: 2,
      prefix: state.amountSymbol,
      onChange: handleTotalChange,
      disabled: state.channelDisabledEdit,
      originalValue: ((_state$service$cacheI9 = state.service.cacheItem) === null || _state$service$cacheI9 === void 0 || (_state$service$cacheI9 = _state$service$cacheI9._extend) === null || _state$service$cacheI9 === void 0 ? void 0 : _state$service$cacheI9.origin_total) || 0,
      placeholder: ((_state$service$cacheI10 = state.service.cacheItem) === null || _state$service$cacheI10 === void 0 || (_state$service$cacheI10 = _state$service$cacheI10._extend) === null || _state$service$cacheI10 === void 0 ? void 0 : _state$service$cacheI10.origin_total) || '0',
      size: "large",
      keyboardProps: {
        containerProps: {
          renderType: 'modal'
        },
        selectType: 'dark'
      }
    })));
  }, [useTotal, (_state$service$cacheI11 = state.service.cacheItem) === null || _state$service$cacheI11 === void 0 || (_state$service$cacheI11 = _state$service$cacheI11._extend) === null || _state$service$cacheI11 === void 0 ? void 0 : _state$service$cacheI11.origin_total, state.amountSymbol, state.channelDisabledEdit]);
  var reason = useMemo(function () {
    return isReason ? /*#__PURE__*/React.createElement(Col, {
      span: 24
    }, /*#__PURE__*/React.createElement(Form.Item, {
      label: locales.getText('pisell2.text.discount-reason'),
      name: "discount_reason"
    }, /*#__PURE__*/React.createElement(Input.TextArea, {
      size: "large"
    }))) : null;
  }, [isReason]);
  var startTime = useMemo(function () {
    var _state$bookingConfig4;
    return /*#__PURE__*/React.createElement(Col, {
      span: 12
    }, /*#__PURE__*/React.createElement(Form.Item, {
      label: locales.getText('pisell2.text.start_time'),
      name: "start_time",
      rules: [{
        required: true
      }]
    }, SelectTime ? /*#__PURE__*/React.createElement(SelectTime, {
      slice: (_state$bookingConfig4 = state.bookingConfig) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.config) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.basic) === null || _state$bookingConfig4 === void 0 || (_state$bookingConfig4 = _state$bookingConfig4.service_time) === null || _state$bookingConfig4 === void 0 ? void 0 : _state$bookingConfig4.value,
      timePickerProps: {
        style: {
          width: '100%'
        }
      },
      timeProps: {
        style: {
          zoom: 0.8
        }
      }
    }) : null));
  }, [SelectTime, (_state$bookingConfig5 = state.bookingConfig) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.config) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.basic) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.service_time) === null || _state$bookingConfig5 === void 0 ? void 0 : _state$bookingConfig5.value]);
  var duration = useMemo(function () {
    console.log('render form duration');
    return /*#__PURE__*/React.createElement(Col, {
      span: 12
    }, /*#__PURE__*/React.createElement(Form.Item, {
      label: locales.getText('pisell2.text.duration'),
      name: "duration",
      rules: [{
        required: true
      }]
    }, /*#__PURE__*/React.createElement(Duration, _extends({}, durationProps, {
      timeObj: timeObj
    }))));
  }, [durationProps, timeObj]);
  var resource = useMemo(function () {
    console.log('render form resource');
    return /*#__PURE__*/React.createElement(Form.Item, {
      noStyle: true,
      name: "resource"
    }, /*#__PURE__*/React.createElement(Resources, {
      ref: resourcesRef,
      state: state,
      cacheItem: state.service.cacheItem,
      getCurrentCacheItem: getCurrentCacheItem
      // 内部没有使用 useDuration useStartTime
      // useDuration={useDuration}
      // useStartTime={useStartTime}
    }));
    // 只监听内部使用值
  }, [state.renderType, (_state$service$cacheI12 = state.service.cacheItem) === null || _state$service$cacheI12 === void 0 || (_state$service$cacheI12 = _state$service$cacheI12._data) === null || _state$service$cacheI12 === void 0 ? void 0 : _state$service$cacheI12.resources, (_state$service$cacheI13 = state.service.cacheItem) === null || _state$service$cacheI13 === void 0 || (_state$service$cacheI13 = _state$service$cacheI13._data) === null || _state$service$cacheI13 === void 0 ? void 0 : _state$service$cacheI13.resourceMaps]);
  var capacity = useMemo(function () {
    return /*#__PURE__*/React.createElement(Form.Item, {
      noStyle: true,
      name: "capacity"
    }, /*#__PURE__*/React.createElement(Capacity, {
      state: state,
      cacheItem: state.service.cacheItem
    }));
    // 只监听Capacity 内部使用的 state.locale state.isTerminal, state.service?.cacheItem?._data?.capacitys
  }, [state.locale, state.isTerminal, (_state$service9 = state.service) === null || _state$service9 === void 0 || (_state$service9 = _state$service9.cacheItem) === null || _state$service9 === void 0 || (_state$service9 = _state$service9._data) === null || _state$service9 === void 0 ? void 0 : _state$service9.capacitys]);
  var hiddenQuantity = useMemo(function () {
    return /*#__PURE__*/React.createElement(Form.Item, {
      hidden: true,
      name: "quantity"
    }, /*#__PURE__*/React.createElement(InputNumber, null));
  }, []);
  var quantity = useMemo(function () {
    return /*#__PURE__*/React.createElement(Col, {
      span: 24
    }, /*#__PURE__*/React.createElement(Form.Item, {
      label: locales.getText('pisell2.text.quantity'),
      name: "quantity",
      rules: [{
        required: true
      }]
    }, /*#__PURE__*/React.createElement(InputNumber, {
      size: "large",
      style: {
        width: '100%'
      },
      min: 1,
      max: 999999,
      formatter: function formatter(value) {
        if (value !== undefined) {
          // 向下取整
          return Math.floor(value);
        }
        return value;
      }
    })));
  }, []);
  var footer = useMemo(function () {
    var _state$service$resour;
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-lowcode__booking-service-body-edit-footer",
      style: state !== null && state !== void 0 && state.isBookingTicket2 ? {
        justifyContent: 'space-between'
      } : {}
    }, /*#__PURE__*/React.createElement("div", {
      className: "pisell-lowcode__booking-service-body-edit-footer-left"
    }, /*#__PURE__*/React.createElement("div", {
      className: "pisell-lowcode__booking-service-delete-wrap",
      onClick: handleDeleteProduct
    }, /*#__PURE__*/React.createElement(Delete_wght300_24px, {
      className: "pisell-lowcode__booking-service-delete-icon"
    })), (state === null || state === void 0 ? void 0 : state.isBookingTicket2) && /*#__PURE__*/React.createElement(ConfigProvider, {
      theme: {
        token: {
          colorPrimary: '#0d7fa9'
        }
      }
    }, /*#__PURE__*/React.createElement(Button, {
      className: "pisell-lowcode__booking-service-buttons-item note-button",
      type: "primary",
      size: "large",
      onClick: function onClick() {
        return setNoteModalOpen(true);
      },
      style: {
        height: '48px',
        width: '140px'
      }
    }, locales.getText('pisell2.ticket-booking.note'), useNote && /*#__PURE__*/React.createElement("span", {
      className: "note-indicator"
    }, /*#__PURE__*/React.createElement(Iconfont, {
      type: "pisell2-info-circle2"
    }))))), /*#__PURE__*/React.createElement(Button, {
      type: "primary",
      className: "pisell-lowcode__booking-service-body-edit-footer-apple",
      disabled: !isNormalProduct && !((_state$service$resour = state.service.resourcesOrigin) !== null && _state$service$resour !== void 0 && _state$service$resour.length),
      onClick: function onClick() {
        form.submit();
      }
    }, locales.getText('pisell2.text.apply')));
  }, [(_state$service$resour2 = state.service.resourcesOrigin) === null || _state$service$resour2 === void 0 ? void 0 : _state$service$resour2.length, isNormalProduct]);
  console.log('render edit');
  console.log(state.service.editModal && !((_state$service$cacheI14 = state.service.cacheItem) !== null && _state$service$cacheI14 !== void 0 && _state$service$cacheI14.autoClose), performance.now() - window.pp1, '打开商品1');
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    val = _useState6[0],
    setVal = _useState6[1];
  useEffect(function () {
    if (isShowTimeAndResource) {
      setTimeout(function () {
        setVal(true);
      }, 200);
    } else {
      setVal(false);
    }
  }, [isShowTimeAndResource]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Drawer, {
    titleNoWrap: true
    //通过zIndex的方式控制  添加商品 和 编辑服务弹窗的上下层级
    ,
    zIndex: state.service.changeService ? 999 : 1000,
    forceRender: true,
    mask: state.drawerMask,
    open: !isNoSpecAndPackage && state.service.editModal && !((_state$service$cacheI15 = state.service.cacheItem) !== null && _state$service$cacheI15 !== void 0 && _state$service$cacheI15.autoClose),
    title: locales.getText('pisell2.text.edit-service'),
    onClose: function onClose() {
      var _window$closeBookingE4, _window4;
      (_window$closeBookingE4 = (_window4 = window).closeBookingEditModal) === null || _window$closeBookingE4 === void 0 || _window$closeBookingE4.call(_window4);
      dispatch({
        type: 'setService',
        payload: {
          editModal: false,
          cacheItem: null,
          changeService: false
        }
      });
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-service-body-edit"
  }, /*#__PURE__*/React.createElement(Form, {
    layout: "vertical",
    form: form,
    onFinish: onFinish
  }, /*#__PURE__*/React.createElement(Row, {
    style: {
      width: '100%'
    },
    gutter: [16, 0]
  }, productName, price, reason, val && isShowTimeAndResource && /*#__PURE__*/React.createElement(React.Fragment, null, startTime, duration, resource, capacity, hiddenQuantity), isNormalProduct && quantity), /*#__PURE__*/React.createElement(Form.Item, {
    noStyle: true,
    name: "note"
  }, noteModalOpen && /*#__PURE__*/React.createElement(NoteModal, {
    open: noteModalOpen,
    value: form.getFieldValue('note'),
    onConfirm: handleNoteConfirm,
    onDelete: handleNoteDelete,
    onCancel: handleNoteCancel
  }))), footer)));
};
export default /*#__PURE__*/forwardRef(Info);