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 React, { useContext, useEffect, useMemo, useImperativeHandle, forwardRef, useRef } from 'react';
import Delete_wght300_24px from '@pisell/icon/es/Delete_wght300_24px';
import Drawer from "../../../components/drawer";
import { Context } from "../../../info/model";
import { formatAmount, locales } from '@pisell/utils';
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 { useUpdateEffect, useMemoizedFn } from 'ahooks';
// import SelectTime from "../../../../../../../materials/src/components/select-time";
import { getServiceTimes, deleteCacheParams, getProductTotalPrice, isSessionProduct } from "../../../utils";
import { getErrorList } from "../../utilsByBooking";
import { formatResources, getDurationProps, getFlexibleOption, getTimeObj, setDefaultCapacitys } from "../addService/utils";
import { PisellAdjustPriceInputNumber } from '@pisell/materials';
import { editSessionProduct } from "../../../info/utils";
import { isNormalProductByDurationSchedule } from "../../../info/service2/utils";
import { addService, genServiceKey, getIsShowNumber } from "../../../../ticketBooking/utils";
var submitLock = false;
var Info = function Info(_, ref) {
  var _state$service3, _state$bookingConfig2, _state$service$cacheI4, _state$service$cacheI5, _state$service6, _state$service8, _window$BaseMaterials, _state$service$cacheI6, _state$service9, _state$service$cacheI7, _state$service$cacheI8, _state$service$cacheI9, _state$service$cacheI10, _state$bookingConfig3, _state$service$resour;
  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 _useContext = useContext(Context),
    state = _useContext.state,
    dispatch = _useContext.dispatch;
  var resourcesRef = useRef(null);
  var isChangeTotal = useRef(false);
  var isNormalProduct = useMemo(function () {
    var _state$service, _state$service2;
    return (state === null || state === void 0 || (_state$service = state.service) === null || _state$service === void 0 ? void 0 : _state$service.cacheItem) && isNormalProductByDurationSchedule(state === null || state === void 0 || (_state$service2 = state.service) === null || _state$service2 === void 0 ? void 0 : _state$service2.cacheItem);
  }, [state === null || state === void 0 || (_state$service3 = state.service) === null || _state$service3 === void 0 ? void 0 : _state$service3.cacheItem]);

  // 当前商品信息+ 表单信息
  var getCurrentCacheItem = function getCurrentCacheItem(_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;
  }, [useResource]);

  /**
   * @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();
    return getDurationProps({
      cacheItem: _cacheItem,
      useStartTime: useStartTime,
      currentResource: 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
    });
  }, [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 () {
    return getFlexibleOption({
      durationProps: durationProps
    });
  }, [durationProps, locales.locale]);

  /**
   * @title: 时间切片
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 13:37
   */
  var timeObj = useMemo(function () {
    return getTimeObj({
      durationProps: durationProps,
      useStartTime: useStartTime,
      currentResource: currentResource,
      state: state,
      useDuration: useDuration
    });
  }, [durationProps, useStartTime, currentResource, state, useDuration]);
  // 由于灵活时长的结束时间随时变动, 这里发现如果当前选择的值没有在列表内,则选择最新的灵活时长值
  useEffect(function () {
    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 = function handleDeleteProduct() {
    var _state$service$cacheI;
    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;
    });
    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;
    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();
    dispatch({
      type: 'setService',
      payload: {
        editModal: false,
        addModal: false,
        value: _list,
        edit: true,
        cacheItem: null,
        changeService: false
      }
    });
  };
  var setEditData = useMemoizedFn(function (_cacheItem, open, openProductDetail) {
    form.resetFields();
    isChangeTotal.current = false;
    var cacheItem = _cacheItem || state.service.cacheItem;
    var values = cacheItem._extend;
    form.setFieldsValue(values);
    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$cacheI3;
    var oPrice = Number(((_state$service$cacheI3 = state.service.cacheItem) === null || _state$service$cacheI3 === void 0 ? void 0 : _state$service$cacheI3._extend.origin_total) || 0);
    var cPrice = Number(useTotal || 0);
    // 原价 !== 现价
    return cPrice !== oPrice;
  }, [useTotal, (_state$service$cacheI4 = state.service.cacheItem) === null || _state$service$cacheI4 === void 0 || (_state$service$cacheI4 = _state$service$cacheI4._extend) === null || _state$service$cacheI4 === void 0 ? void 0 : _state$service$cacheI4.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) {
      setEditData(null);
    }
  }, [state.service.editModal, state.isBookingCreatePage]);

  /**
   * @title: 价格发生变化,重新计算折扣
   * @description:
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-01-09 14:08
   */
  useEffect(function () {
    getDiscount();
  }, [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 isDiscount = useMemo(function () {
    var _state$service4, _state$service5;
    if (!((_state$service4 = state.service) !== null && _state$service4 !== void 0 && _state$service4.cacheItem)) {
      return false;
    }
    return useTotal != ((_state$service5 = state.service) === null || _state$service5 === void 0 || (_state$service5 = _state$service5.cacheItem) === null || _state$service5 === void 0 ? void 0 : _state$service5._extend.origin_total);
  }, [useTotal, (_state$service6 = state.service) === null || _state$service6 === void 0 || (_state$service6 = _state$service6.cacheItem) === null || _state$service6 === void 0 ? void 0 : _state$service6._extend.origin_total]);
  var bundles = useMemo(function () {
    var _state$service7;
    return ((_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 || (_state$service7 = _state$service7.other) === null || _state$service7 === void 0 ? void 0 : _state$service7.bundle) || [];
  }, [(_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 || (_state$service8 = _state$service8.other) === null || _state$service8 === void 0 ? void 0 : _state$service8.bundle]);

  /**
   * @title: 编辑商品
   * @description:
   * @param {any} e
   * @return {*}
   * @Author: zhiwei.Wang
   * @Date: 2024-08-28 17:08
   */
  var handleEdit = function handleEdit(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 = function handleChange(e) {
    if (state.channelDisabledEdit) {
      return;
    }
    form.resetFields();
    dispatch({
      type: 'setService',
      payload: {
        addModal: true,
        editModal: false

        //用于控制 添加商品 和 编辑服务弹窗的上下层级
        // changeService: true,
      }
    });
  };
  useImperativeHandle(ref, function () {
    return {
      init: setEditData
    };
  });
  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;
  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: state.service.editModal && !((_state$service$cacheI6 = state.service.cacheItem) !== null && _state$service$cacheI6 !== void 0 && _state$service$cacheI6.autoClose),
    title: locales.getText('pisell2.text.edit-service'),
    onClose: function onClose() {
      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]
  }, /*#__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$service9 = state.service) === null || _state$service9 === void 0 || (_state$service9 = _state$service9.cacheItem) === null || _state$service9 === void 0 || (_state$service9 = _state$service9._extend) === null || _state$service9 === void 0 ? void 0 : _state$service9.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);
    }
  })))), /*#__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(PisellAdjustPriceInputNumber, {
    style: {
      width: '100%'
    },
    min: 0,
    precision: 2,
    prefix: state.amountSymbol,
    onChange: handleTotalChange,
    disabled: state.channelDisabledEdit,
    originValue: ((_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'
  }))), 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, isShowTimeAndResource && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__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$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 || (_state$bookingConfig3 = _state$bookingConfig3.service_time) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.value,
    timePickerProps: {
      style: {
        width: '100%'
      }
    },
    timeProps: {
      style: {
        zoom: 0.8
      }
    }
  }) : null)), /*#__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
  })))), /*#__PURE__*/React.createElement(Form.Item, {
    noStyle: true,
    name: "resource"
  }, /*#__PURE__*/React.createElement(Resources, {
    ref: resourcesRef,
    state: state,
    cacheItem: state.service.cacheItem,
    getCurrentCacheItem: getCurrentCacheItem,
    useDuration: useDuration,
    useStartTime: useStartTime
  })), /*#__PURE__*/React.createElement(Form.Item, {
    noStyle: true,
    name: "capacity"
  }, /*#__PURE__*/React.createElement(Capacity, {
    state: state,
    cacheItem: state.service.cacheItem
  })), /*#__PURE__*/React.createElement(Form.Item, {
    hidden: true,
    name: "quantity"
  }, /*#__PURE__*/React.createElement(InputNumber, null))), isNormalProduct && /*#__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;
    }
  }))))), /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-service-body-edit-footer"
  }, /*#__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"
  })), /*#__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'))))));
};
export default /*#__PURE__*/forwardRef(Info);